summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2014-10-31 13:10:00 +0100
committertv <tv@shackspace.de>2014-10-31 13:10:00 +0100
commit24961600116593d7fdf447f19f9ee0ed2fd6c575 (patch)
tree6fb55750feaa98c73ccaed41118756404c5cd0bf
initial commit
-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 "$@"