2121BASEDIR=" $( cd -P " $( dirname " $SOURCE " ) " && pwd ) "
2222
2323PYTHONCMD=" python"
24+
25+ function doProgram {
26+ # process input from pipe and store as pickled file
27+ $PYTHONCMD " $BASEDIR /src/processInput.py"
28+ # now close stdin and choose input...
29+ exec 0< & -
30+ $PYTHONCMD " $BASEDIR /src/choose.py" < /dev/tty
31+ # execute the output bash script
32+ sh ~ /.fpp/.fpp.sh < /dev/tty
33+ }
34+
2435# we need to handle the --help option outside the python
2536# flow since otherwise we will move into input selection...
2637for opt in " $@ " ; do
@@ -31,13 +42,19 @@ for opt in "$@"; do
3142 elif [ " $opt " == " --help" -o " $opt " == " -h" ]; then
3243 $PYTHONCMD " $BASEDIR /src/printHelp.py"
3344 exit 0
45+ elif [ " $opt " == " --keep-open" -o " $opt " == " -ko" ]; then
46+ # allow control-c to exit the loop
47+ # http://unix.stackexchange.com/a/48432
48+ trap " exit" INT
49+ while true ; do
50+ doProgram
51+ # connect tty back to stdin since we closed it
52+ # earlier. this also works since we will only read
53+ # from stdin once and then go permanent interactive mode
54+ # http://stackoverflow.com/a/1992967/948126
55+ exec 0< /dev/tty
56+ done
3457 fi
3558done
3659
37- # process input from pipe and store as pickled file
38- $PYTHONCMD " $BASEDIR /src/processInput.py"
39- # now choose input and...
40- exec 0< & -
41- $PYTHONCMD " $BASEDIR /src/choose.py" < /dev/tty
42- # execute the output bash script
43- sh ~ /.fpp/.fpp.sh < /dev/tty
60+ doProgram
0 commit comments