From 2eb7640463e5d052dccfa02ef7a55afc0f056580 Mon Sep 17 00:00:00 2001 From: Nick Gavalas Date: Tue, 19 Jan 2016 12:15:23 -0800 Subject: [PATCH 1/2] add a command-line flag to force non-interactive mode for the subshell that runs the follow-up commands --- fpp | 5 ++++- src/screenFlags.py | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/fpp b/fpp index 8919b196..eb46ab20 100755 --- a/fpp +++ b/fpp @@ -21,6 +21,7 @@ done BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" PYTHONCMD="python" +NONINTERACTIVE=false function doProgram { # process input from pipe and store as pickled file @@ -34,7 +35,7 @@ function doProgram { $PYTHONCMD "$BASEDIR/src/choose.py" "$@" < /dev/tty # Determine if running from within vim shell IFLAG="" - if [ -z "$VIMRUNTIME" ]; then + if [ -z "$VIMRUNTIME" -a "$NONINTERACTIVE" = false ]; then IFLAG="-i" fi # execute the output bash script. For zsh or bash @@ -67,6 +68,8 @@ for opt in "$@"; do exit 0 elif [ "$opt" == "--record" -o "$opt" == "-r" ]; then echo "Recording input and output..." + elif [ "$opt" == "--non-interactive" -o "$opt" == "-n" ]; then + NONINTERACTIVE=true elif [ "$opt" == "--keep-open" -o "$opt" == "-ko" ]; then # allow control-c to exit the loop # http://unix.stackexchange.com/a/48432 diff --git a/src/screenFlags.py b/src/screenFlags.py index 00d2e8cf..d881f8f5 100644 --- a/src/screenFlags.py +++ b/src/screenFlags.py @@ -45,6 +45,9 @@ def getDisableFileChecks(self): def getAllInput(self): return self.args.all_input + def getIsNonInteractive(self): + return self.args.non_interactive + @staticmethod def getArgParser(): parser = argparse.ArgumentParser(prog='fpp') @@ -102,6 +105,16 @@ def getArgParser(): help='''You may force PathPicker to recognize all lines as acceptible input. Typically, PathPicker will scan the input for references to file paths. Passing this option will disable those scans and the program will assume that every input line is a match. In practice, this option allows for input selection for a variety of sources that would otherwise be unsupported -- git branches, mercurial bookmarks, etc.''') + parser.add_argument('-n', + '--non-interactive', + default=False, + action="store_true", + help='''Normally, the command that runs after you've +chosen files to operate on is spawned in an interactive subshell. This allows you +to use aliases and have access to environment variables defined in your startup +files, but can have strange side-effects when starting and stopping jobs +and redirecting inputs. Using this flag runs your commands in a non-interactive subshell, +like a normal shell script.''') return parser @staticmethod From c61192d00add3c533eff51ce434176a890008502 Mon Sep 17 00:00:00 2001 From: Nick Gavalas Date: Tue, 19 Jan 2016 12:45:39 -0800 Subject: [PATCH 2/2] change flag to -ni, fix indentation --- fpp | 2 +- src/screenFlags.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fpp b/fpp index eb46ab20..43fdebaa 100755 --- a/fpp +++ b/fpp @@ -68,7 +68,7 @@ for opt in "$@"; do exit 0 elif [ "$opt" == "--record" -o "$opt" == "-r" ]; then echo "Recording input and output..." - elif [ "$opt" == "--non-interactive" -o "$opt" == "-n" ]; then + elif [ "$opt" == "--non-interactive" -o "$opt" == "-ni" ]; then NONINTERACTIVE=true elif [ "$opt" == "--keep-open" -o "$opt" == "-ko" ]; then # allow control-c to exit the loop diff --git a/src/screenFlags.py b/src/screenFlags.py index d881f8f5..6ce25528 100644 --- a/src/screenFlags.py +++ b/src/screenFlags.py @@ -46,7 +46,7 @@ def getAllInput(self): return self.args.all_input def getIsNonInteractive(self): - return self.args.non_interactive + return self.args.non_interactive @staticmethod def getArgParser(): @@ -105,11 +105,11 @@ def getArgParser(): help='''You may force PathPicker to recognize all lines as acceptible input. Typically, PathPicker will scan the input for references to file paths. Passing this option will disable those scans and the program will assume that every input line is a match. In practice, this option allows for input selection for a variety of sources that would otherwise be unsupported -- git branches, mercurial bookmarks, etc.''') - parser.add_argument('-n', - '--non-interactive', - default=False, - action="store_true", - help='''Normally, the command that runs after you've + parser.add_argument('-ni', + '--non-interactive', + default=False, + action="store_true", + help='''Normally, the command that runs after you've chosen files to operate on is spawned in an interactive subshell. This allows you to use aliases and have access to environment variables defined in your startup files, but can have strange side-effects when starting and stopping jobs