summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-03-29 19:29:29 -0400
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-03-29 19:29:29 -0400
commit2d64adb0f339a3344e880bc6add832abd707ce8a (patch)
tree1dc8b18aaa221a56dea8e710b1e3fa440ff3602b
downloadnextbin-2d64adb0f339a3344e880bc6add832abd707ce8a.tar.xz
nextbin-2d64adb0f339a3344e880bc6add832abd707ce8a.zip
Initial commit
-rwxr-xr-xnextbin31
1 files changed, 31 insertions, 0 deletions
diff --git a/nextbin b/nextbin
new file mode 100755
index 0000000..2e1d9dd
--- /dev/null
+++ b/nextbin
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+orig_exe=$(realpath -s "$1")
+exe_name=${orig_exe##*/}
+case "$orig_exe" in
+ */*) ;;
+ *)
+ printf 'error: cannot find next executable: argv[0] is %s, missing /\n' "$orig_exe"
+ exit 1
+esac
+paths=
+passed_paths=
+set -f
+_IFS=$IFS
+IFS=:
+for path in $PATH; do
+ file=$path/$exe_name
+ if [ "$file" = "$orig_exe" ]; then
+ if [ -n "$passed_paths" ] && [ -n "$paths" ]; then
+ printf 'error: ambiguous next executable for %s past %s, due to multiple non-consecutive instances of %s in PATH' "$exe_name" "$orig_exe" "$(dirname "$orig_exe")"
+ exit 1
+ fi
+ passed_paths=${paths+$paths:}
+ paths=
+ else
+ paths="${paths+$paths:}$path"
+ fi
+done
+IFS=$_IFS
+PATH="$passed_paths$paths" exec "$exe_name"
+exit 1