view .local/bin/hst @ 172:72b0420167dc

generalised sbatch front-end to cdx2tsv.py
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 28 Jul 2022 17:24:29 +0100
parents a8bb3b4c208f
children
line wrap: on
line source

#!/bin/sh
pipe=0

for i in "$@"
do
case $i in
    -p|--pipe-output)
    pipe=1
    ;;
esac
done


f="/tmp/$$-command.hst"
# we install via pip so the python we use is, resolve $SOURCE until the file is no longer a symlink
# so one can symlink to /usr/local/bin etc...
# stolen from https://github.com/facebook/PathPicker/blob/master/fpp
SOURCE=$0
# resolve $SOURCE until the file is no longer a symlink
while [ -h "$SOURCE" ]; do
  BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  # if $SOURCE was a relative symlink, we need to resolve it relative to
  # the path where the symlink file was located
  [[ $SOURCE != /* ]] && SOURCE="$BASEDIR/$SOURCE"
done
BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
PYTHON=`which python`
# hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
# if [ $? -ne 0 ]; then
#   # pass
#   PYTHON="$BASEDIR/python"
#   hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
#   if [ $? -ne 0 ]; then
#     PYTHON="/usr/bin/python"
#     hstpy="$($PYTHON -c 'from hst import hst; print hst.__file__.replace(".pyc", ".py")' 2>/dev/null)"
#   fi
# fi


$PYTHON -m hst.hst --out=$f "$@" 3>&1 1>&2

if [[ $? != 0 ]]; then exit $?; fi
if [ -f "$f" ]
then
    if [[ $pipe == "1" ]]; then
      cat $f
    else
      $SHELL -i $f < /dev/tty
    fi
fi