summaryrefslogtreecommitdiffstats
path: root/load-env
diff options
context:
space:
mode:
Diffstat (limited to 'load-env')
-rwxr-xr-xload-env31
1 files changed, 31 insertions, 0 deletions
diff --git a/load-env b/load-env
new file mode 100755
index 0000000..ed192d0
--- /dev/null
+++ b/load-env
@@ -0,0 +1,31 @@
+#! /bin/sh
+set -euf
+main() {
+ case "$PWD" in
+ "$HOME/src/"[0-9A-Za-z-]*)
+ name=$(basename "$PWD")
+ exe=$(findexe "$name" | highest_version)
+ if test -z "$exe"; then
+ echo2 "load-env-$name: no such executable"
+ else
+ echo2 "run $exe"
+ exec "$exe" "$@"
+ fi
+ ;;
+ "$HOME/src/"*) echo2 "bad basename: $(basename "$PWD")";;
+ *) echo2 "load-env only knows about stuff below ~/src";;
+ esac
+ exit 23
+}
+echo2() { echo "$*" >&2; }
+findexe() {
+ ( IFS=:
+ find $PATH \
+ -regextype posix-extended \
+ -regex ".*/load-env-$1(-[0-9.]+)?$" \
+ 2>/dev/null )
+}
+highest_version() {
+ sort -V | tail -n 1
+}
+main "$@"