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:
This commit is contained in:
Simon M
2017-10-13 23:32:13 +02:00
committed by Ali Karbassi
parent 1d64ba59ca
commit b7fb2ac2be

12
todo.sh
View File

@@ -429,7 +429,7 @@ replaceOrPrepend()
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "$querytext" echo -n "$querytext"
read input read -e -r input
else else
input=$* input=$*
fi fi
@@ -1021,7 +1021,7 @@ case $action in
"add" | "a") "add" | "a")
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Add: " echo -n "Add: "
read input read -e -r input
else else
[ -z "$2" ] && die "usage: $TODO_SH add \"TODO ITEM\"" [ -z "$2" ] && die "usage: $TODO_SH add \"TODO ITEM\""
shift shift
@@ -1033,7 +1033,7 @@ case $action in
"addm") "addm")
if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$2" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Add: " echo -n "Add: "
read input read -e -r input
else else
[ -z "$2" ] && die "usage: $TODO_SH addm \"TODO ITEM\"" [ -z "$2" ] && die "usage: $TODO_SH addm \"TODO ITEM\""
shift shift
@@ -1074,7 +1074,7 @@ case $action in
if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then if [[ -z "$1" && $TODOTXT_FORCE = 0 ]]; then
echo -n "Append: " echo -n "Append: "
read input read -e -r input
else else
input=$* input=$*
fi fi
@@ -1114,7 +1114,7 @@ case $action in
if [ -z "$3" ]; then if [ -z "$3" ]; then
if [ $TODOTXT_FORCE = 0 ]; then if [ $TODOTXT_FORCE = 0 ]; then
echo "Delete '$todo'? (y/n)" echo "Delete '$todo'? (y/n)"
read ANSWER read -e -r ANSWER
else else
ANSWER="y" ANSWER="y"
fi fi
@@ -1310,7 +1310,7 @@ case $action in
[ -z "$todo" ] && die "$item: No such item in $src." [ -z "$todo" ] && die "$item: No such item in $src."
if [ $TODOTXT_FORCE = 0 ]; then if [ $TODOTXT_FORCE = 0 ]; then
echo "Move '$todo' from $src to $dest? (y/n)" echo "Move '$todo' from $src to $dest? (y/n)"
read ANSWER read -e -r ANSWER
else else
ANSWER="y" ANSWER="y"
fi fi