From d4daece76b4ecf6df70763ecb736dd5bd253f5df Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Apr 2015 20:05:45 -0400 Subject: 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"). --- install | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'install') diff --git a/install b/install index a8bb0749..3b8dbe6f 100755 --- a/install +++ b/install @@ -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]$ ]] } -- cgit v1.2.3