Last active
June 9, 2022 19:32
-
-
Save AdaRoseCannon/1165e64d83ccf85f2f8638d0629bf4b3 to your computer and use it in GitHub Desktop.
Todolist repl, It works with https://github.com/gammons/todolist/releases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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