diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2015-04-13 20:05:45 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2015-04-13 20:40:46 -0400 |
commit | d4daece76b4ecf6df70763ecb736dd5bd253f5df (patch) | |
tree | 3f7d53b16077b9e00b06068de976a026875af44f /install | |
parent | 3ec83babacac24341f3db92c2a9b8bae4782fa07 (diff) |
install: wait for LF in non-interactive shell
"read -n 1 ..." ignores all but the first character of a line-delimited
stream (e.g. "yes n | ./install").
Diffstat (limited to 'install')
-rwxr-xr-x | install | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -5,8 +5,15 @@ version=0.9.7 cd $(dirname $BASH_SOURCE) fzf_base=$(pwd) +# If stdin is a tty, we are "interactive". +[ -t 0 ] && interactive=yes + ask() { - read -p "$1 ([y]/n) " -n 1 -r + # non-interactive shell: wait for a linefeed + # interactive shell: continue after a single keypress + [ -n "$interactive" ] && read_n='-n 1' || read_n= + + read -p "$1 ([y]/n) " $read_n -r echo [[ ! $REPLY =~ ^[Nn]$ ]] } |