Managing tasks directly from the terminal can be a breeze with the power of shell scripting! In this post, I'll walk you through creating a simple yet functional TODO list using a few shell functions. We'll store tasks in a text file, add unique identifiers to each item, and provide commands for adding, removing, and clearing tasks.
Let’s dive in! 🚀
Prerequisites ⚙️
You'll need a terminal using bash
or zsh
. The following functions can be added to your ~/.zshrc
or ~/.bashrc
file to make them available as commands in your terminal.
Step 1: Set Up Your Storage 🎲
First, let’s create an environment variable that defines where your tasks will be stored. Add this line to your configuration file:
export TODO="${HOME}/todo.txt"
This will store your task list in a file called todo.txt
located in your home directory.
Step 2: Define Your Functions ✨
Now let's add some shell functions to manage our TODO list:
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 ;}
Here’s what each function does:
-
tla
(Todo List Add): Adds tasks to the list. It generates a 4-character md5 hash to serve as a unique identifier for each task. If no argument is passed, it displays the current task list. -
tlr
(Todo List Remove): Removes tasks from the list by matching their md5 identifier. -
tl
(Todo List): Simply displays the current list. -
tlc
(Todo List Clear): Clears the entire task list, removing all entries at once.
At the end of each operation, the current state of your TODO list will be displayed.
Step 3: See It in Action ☕️
Here’s a quick demonstration of how these commands work:
➜ ~ 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
-
tla test 0
: Adds "test 0" to the list with an md5 identifier. -
tlr 2490
: Removes the task with the identifier2490
(in this case, "test 1"). -
tlc
: Clears the list.
Conclusion ✍️
With just a few lines of shell script, you now have a functional TODO list right in your terminal. You can easily add, remove, or clear tasks with simple commands. This setup is lightweight and can be modified to fit your workflow.
Feel free to extend these functions or add your own twists. Happy hacking! 🚀