comparison .local/bin/hst @ 66:a8bb3b4c208f

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