improve stubexec

Thu, 25 Nov 2021 14:13:46 -0500

author
Meredith Howard <mhoward@roomag.org>
date
Thu, 25 Nov 2021 14:13:46 -0500
changeset 957
ea852d545173
parent 956
61c91bec34c8
child 958
b883fb5c4792

improve stubexec

.lib/sh/stubexec.sh file | annotate | diff | comparison | revisions
bin/cpm file | annotate | diff | comparison | revisions
bin/gotags file | annotate | diff | comparison | revisions
bin/pg_format file | annotate | diff | comparison | revisions
--- 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 $*
 }
--- 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 "$@"
--- 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 "$@"
--- 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 "$@"

mercurial