# HG changeset patch # User Meredith Howard # Date 1637867626 18000 # Node ID ea852d5451737e6b03d4d06b71b59a1680ac7258 # Parent 61c91bec34c80d94555f2bd9ee841d5ca5b8f98b improve stubexec diff --git a/.lib/sh/stubexec.sh b/.lib/sh/stubexec.sh --- a/.lib/sh/stubexec.sh +++ b/.lib/sh/stubexec.sh @@ -4,10 +4,17 @@ realpath() { (cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file") } +realbin() { + which -a $(basename $1) | + grep -v "$(realpath $1)" | + head -n 1 +} + stubexec() { - local real_me="$(realpath "$0")" - local real_bin="$(which -a $(basename $0) | grep -v "$real_me" | head -n 1)" + local real_bin="$(realbin "$0")" if [ -x "$real_bin" ]; then - exec $real_bin $* + exec "$real_bin" $* fi + install_it + stubexec $* } diff --git a/bin/cpm b/bin/cpm --- a/bin/cpm +++ b/bin/cpm @@ -2,11 +2,11 @@ set -eu . ~/.lib/sh/stubexec.sh -stubexec "$@" +install_it() { + curl -fsSL --compressed https://git.io/cpm | + perl - install -g App::cpm -curl -fsSL --compressed https://git.io/cpm | - perl - install -g App::cpm - -plenv rehash || : + plenv rehash || : +} stubexec "$@" diff --git a/bin/gotags b/bin/gotags --- a/bin/gotags +++ b/bin/gotags @@ -2,9 +2,9 @@ set -eu . ~/.lib/sh/stubexec.sh -stubexec "$@" - -go install github.com/jstemmer/gotags@latest -asdf reshim || : +install_it() { + go install github.com/jstemmer/gotags@latest + asdf reshim || : +} stubexec "$@" diff --git a/bin/pg_format b/bin/pg_format --- a/bin/pg_format +++ b/bin/pg_format @@ -2,9 +2,9 @@ set -eu . ~/.lib/sh/stubexec.sh -stubexec "$@" - -cpanm -n 'https://github.com/darold/pgFormatter.git' -plenv rehash || : +install_it() { + cpanm -n 'https://github.com/darold/pgFormatter.git' + plenv rehash || : +} stubexec "$@"