From b7fb2ac2be7132e18871e73276d2765309732b34 Mon Sep 17 00:00:00 2001 From: Simon M Date: Fri, 13 Oct 2017 23:32:13 +0200 Subject: [PATCH] fix: Make text input more user-friendly (#208) The use of the default read command will not allow the user to use arrow keys and shortcuts to enter the data when doing a replace or entering any input, which can be frustrating. Besides, backslashed are interpreted and can be mangled. - Using the `-e` option will trigger the use of the readline library: you can then, as expected in bash, use the arrow keys and all shortcuts to move around the line before pressing enter. - Using the `-r` option will prevent the interpretation of the "" and insert them as typed, useful when pasting code: --- todo.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/todo.sh b/todo.sh index 10ea614..53b1919 100755 --- a/todo.sh +++ b/todo.sh @@ -429,7 +429,7 @@ replaceOrPrepend() if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then echo -n "$querytext" - read input + read -e -r input else input=$* fi @@ -1021,7 +1021,7 @@ case $action in "add" | "a") if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then echo -n "Add: " - read input + read -e -r input else [ -z "$2" ] && die "usage: $TODO_SH add \"TODO ITEM\"" shift @@ -1033,7 +1033,7 @@ case $action in "addm") if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then echo -n "Add: " - read input + read -e -r input else [ -z "$2" ] && die "usage: $TODO_SH addm \"TODO ITEM\"" shift @@ -1074,7 +1074,7 @@ case $action in if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then echo -n "Append: " - read input + read -e -r input else input=$* fi @@ -1114,7 +1114,7 @@ case $action in if [ -z "$3" ]; then if [ $TODOTXT_FORCE = 0 ]; then echo "Delete '$todo'? (y/n)" - read ANSWER + read -e -r ANSWER else ANSWER="y" fi @@ -1310,7 +1310,7 @@ case $action in [ -z "$todo" ] && die "$item: No such item in $src." if [ $TODOTXT_FORCE = 0 ]; then echo "Move '$todo' from $src to $dest? (y/n)" - read ANSWER + read -e -r ANSWER else ANSWER="y" fi