Skip to content

Commit 72575f6

Browse files
committed
Resolves #61 loop with keep open flag
1 parent 85b9b0b commit 72575f6

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

fpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ done
2121
BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
2222

2323
PYTHONCMD="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...
2637
for 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
3558
done
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

src/processInput.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@
107107
which editor to open the selected files with. If that variable
108108
is not set, $EDITOR is used the next fallback, with "vim" as a last resort.
109109
110+
~ Keep-Open ~
111+
112+
Use the --keep-open or -ko flag to avoid closing PathPicker once
113+
a file selection or command is performed. This will loop the program
114+
until Ctrl-C is used to terminate the process.
115+
110116
'''
111117

112118
USAGE_TAIL = '''
@@ -165,6 +171,7 @@ def usage():
165171
sys.exit(0)
166172
else:
167173
# delete the old selection
174+
print('getting input')
168175
selectionPath = stateFiles.getSelectionFilePath()
169176
if os.path.isfile(selectionPath):
170177
os.remove(selectionPath)

0 commit comments

Comments
 (0)