Skip to content

Instantly share code, notes, and snippets.

@AdaRoseCannon AdaRoseCannon/todo-repl
Last active Feb 11, 2019

Embed
What would you like to do?
Todolist repl, It works with https://github.com/gammons/todolist/releases
#!/bin/bash
tput smcup
# Turn user input off
stty -echo
display() {
BUFFER=$(
tput clear
todolist l | sed '/./,$!d'
echo -ne "\n\n"
tput cup $[$(tput lines)-1] 0
echo -ne ' \e[7ma\e[27mdd \e[7mc\e[27momplete \e[7mr\e[27memove \e[7mq\e[27muit'
)
echo -ne "$BUFFER"
}
trap display WINCH
trap 'tput sgr0; tput cnorm; tput rmcup || clear; exit 0' SIGINT
# Main loop
while :
do
display
tput civis
tput cup $[$(tput lines)-2] 0
read -sen 1 -t 2 ACTION
tput cnorm
[[ -z "$ACTION" ]] && continue
tput cup $[$(tput lines)-1] 0
echo -en "\033[2K"
tput cup $[$(tput lines)-2] 0
case $ACTION in
q|x) #Quit if q or x
tput rmcup
echo "Bye ;)"
exit
;;
a) # Add an item for a
stty echo
read -e -p "Add Item: " ACTION
stty -echo
[[ -z "$ACTION" ]] && continue
eval "todolist a \"$ACTION\"" > /dev/null
;;
c) # Complete an item for c
stty echo
read -e -p "Complete Item: " ACTION
stty -echo
[[ -z "$ACTION" ]] && continue
eval "todolist c \"$ACTION\"" > /dev/null
;;
r|d) # Remove an item with r or d
stty echo
read -e -p "Remove Item: " ACTION
stty -echo
[[ -z "$ACTION" ]] && continue
eval "todolist d \"$ACTION\"" > /dev/null
;;
:) # Use : to enter arbritrary commands
stty echo
read -e -p ":" ACTION
stty -echo
[[ -z "$ACTION" ]] && continue
eval "todolist $ACTION" > /dev/null
;;
*) # By default add an item, prefill the first character entered
stty echo
read -e -i "$ACTION" -p "Add Item: " ACTION
stty -echo
[[ -z "$ACTION" ]] && continue
eval "todolist a \"$ACTION\"" > /dev/null
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.