Skip to content

Instantly share code, notes, and snippets.

@ErnaneJ
Last active May 3, 2024 04:39
Show Gist options
  • Select an option

  • Save ErnaneJ/56ea3aec9f10e5a942594b28eb5015ca to your computer and use it in GitHub Desktop.

Select an option

Save ErnaneJ/56ea3aec9f10e5a942594b28eb5015ca to your computer and use it in GitHub Desktop.
πŸ“‹ TODO List - Shell Script 🐚

πŸ“‹ TODO List - Shell Script 🐚

In your ~/.zshrc or ~/.bashrc configuration file, add the following instructions:

Storage 🎲

  • An environment variable to store a file where the task list will be stored;
export TODO="${HOME}/todo.txt"

Functions ✨

tla() { [ $# -eq 0 ] && cat $TODO || (echo "$(echo $* | md5sum | cut -c 1-4) πŸ‘‰πŸΌ $*" >> $TODO && cat $TODO) ;}
tlr() { sed -i '' "/^$*/d" $TODO && cat $TODO ;}
 tl() { cat $TODO ;}
tlc() { cat /dev/null > $TODO ;}
  • tla (or Todo List Add) is the function responsible for adding items to the list. It captures the string given as input, if provided, generates an md5 and adds its first 4 digits to the beginning of the line to be used as an identifier. If nothing is passed, it just shows the current listing;
  • tlr (or todo list remove) is the function responsible for removing items from the list. For this, the md5 identifier (4 digits) is used to identify the line and remove it from the file;
  • tl (or todo list) serves only as a show. It shows how the list is. It's similar to executing tla without parameters;
  • tlc (or todo list clear) serves to clear the entire list at once, basically deletes the entire file at once.

The main commands are tla and tlr, the others are just auxiliary and are not as important for the app to function.

At the end of each addition or removal command, the current state of the list is shown.

Example of usage: β˜•οΈ

➜  ~ tl       
➜  ~ tla test 0
# 0e57 πŸ‘‰πŸΌ test 0
➜  ~ tla test 1
# 0e57 πŸ‘‰πŸΌ test 0
# 2490 πŸ‘‰πŸΌ test 1
➜  ~ tla test 2
# 0e57 πŸ‘‰πŸΌ test 0
# 2490 πŸ‘‰πŸΌ test 1
# b0b3 πŸ‘‰πŸΌ test 2
➜  ~ tlr 2490
# 0e57 πŸ‘‰πŸΌ test 0
# b0b3 πŸ‘‰πŸΌ test 2
➜  ~ tl
# 0e57 πŸ‘‰πŸΌ test 0
# b0b3 πŸ‘‰πŸΌ test 2
➜  ~ tlc
➜  ~ tl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment