annotate .local/bin/hst @ 185:acae526510e2

too many overdue updates to break down
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 06 Dec 2023 13:38:58 +0000
parents a8bb3b4c208f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
66
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 #!/bin/sh
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 pipe=0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 for i in "$@"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 do
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 case $i in
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 -p|--pipe-output)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 pipe=1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 ;;
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 esac
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 done
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14 f="/tmp/$$-command.hst"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 # we install via pip so the python we use is, resolve $SOURCE until the file is no longer a symlink
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 # so one can symlink to /usr/local/bin etc...
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 # stolen from https://github.com/facebook/PathPicker/blob/master/fpp
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 SOURCE=$0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 # resolve $SOURCE until the file is no longer a symlink
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 while [ -h "$SOURCE" ]; do
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21 BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 SOURCE="$(readlink "$SOURCE")"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 # if $SOURCE was a relative symlink, we need to resolve it relative to
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 # the path where the symlink file was located
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 [[ $SOURCE != /* ]] && SOURCE="$BASEDIR/$SOURCE"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 done
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28 PYTHON=`which python`
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 # hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 # if [ $? -ne 0 ]; then
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 # # pass
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 # PYTHON="$BASEDIR/python"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 # hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 # if [ $? -ne 0 ]; then
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35 # PYTHON="/usr/bin/python"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 # hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 # fi
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38 # fi
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 $PYTHON -m hst.hst --out=$f "$@" 3>&1 1>&2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 if [[ $? != 0 ]]; then exit $?; fi
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
44 if [ -f "$f" ]
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
45 then
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46 if [[ $pipe == "1" ]]; then
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 cat $f
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 else
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49 $SHELL -i $f < /dev/tty
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 fi
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 fi