Last active
August 13, 2025 06:22
-
-
Save riturajborpujari/5a08a52ecb9495166508ae70ab809b33 to your computer and use it in GitHub Desktop.
A simple todo program with just Unix tools
This file contains hidden or 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
#!/usr/bin/env bash | |
command=$1 | |
shift | |
# Make sure the following path is valid on your system | |
data_file="$HOME/.local/var/db/todos/todos.db" | |
temp_data_file="/tmp/todos.db.tmp" | |
case $command in | |
add) | |
echo $@ >> $data_file | |
;; | |
del) | |
prev_row=$(echo "$1 - 1" | bc) | |
next_row=$(echo "$1 + 1" | bc) | |
head -n$prev_row $data_file > $temp_data_file | |
tail -n+$next_row $data_file >> $temp_data_file | |
deleted_todo=$(head -n$1 $data_file | tail -n1) | |
mv $temp_data_file $data_file | |
echo "deleted: $1: $deleted_todo" | |
;; | |
*) | |
echo -e "Todos\n------" | |
cat -n $data_file | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment