This tutorial demonstrates how to integrate a todo reminder into your terminal prompt using the Starship prompt and a Bash script named iZiDo. The setup allows you to manage and display your tasks directly within your terminal.
TL;DR https://idmtr.github.io/izido/
- Configuring a custom module in
starship.toml
- Creating the
izido.sh
Bash script for todo management - Using the script to update your prompt with task reminders
- Setting up the script for both Bash and Zsh shells
Prerequisites
- Starship Prompt installed and configured.
- Basic knowledge of editing configuration files and running scripts.
- A terminal emulator of your choice.
- Bash or Zsh shell.
Step 1: Update Your starship.toml
Configuration
Begin by modifying the starship.toml
file to include a custom module that displays your todo messages in the prompt.
Locate Your starship.toml
The configuration file is typically located at ~/.config/starship.toml
.
Modify the Configuration
Add the following content to your starship.toml
:
# ~/.config/starship.toml
# Use custom format
format = '''
$custom.izido
$time
[│ ](#555a64)$git_branch
│$directory❯
'''
# Define a custom module named 'izido'
[custom.izido]
command = """
if [ -f ~/.config/show_izido ] && [ -f ~/.config/starship_izido.txt ]; then
sayings=("Chop Wood, Carry Water."
"Keep Calm and Code On."
"Ship It, Take a Break."
"Founder Mode.")
index=$((RANDOM % ${#sayings[@]}))
saying="${sayings[$index]}"
echo "┌─❮ $saying"
awk -F, 'BEGIN {OFS=""} $1=="pending" {
icon = ($2=="high") ? "⌛ " : "📝 "
if ($3 != "none") {
print icon $4 " (Due: " $3 ")"
} else {
print icon $4 ""
}
count += 1
if (count >= 3) exit
}' ~/.config/starship_izido.txt 2>/dev/null
fi
"""
when = '''
test -f ~/.config/show_izido && test -f ~/.config/starship_izido.txt
'''
format = '''
[$output](#fff)
'''
# Time Module
[time]
disabled = false
format = '🕙 [$time]($style) '
time_format = '%T'
utc_time_offset = '+2'
time_range = '10:00:00-14:00:00'
# Character Module (Prompt Symbol)
[character]
success_symbol = "[➜](bold #0A84FF)"
error_symbol = "[➜](bold #FF3B30)"
# Directory Module
[directory]
truncation_length = 3
truncation_symbol = "…/"
style = "bold #34C759"
# Git Branch Module
[git_branch]
symbol = " "
style = "bold #ff70cd"
disabled = false
# Git Status Module
[git_status]
style = "bold #007AFF"
ahead = "⇡"
behind = "⇣"
diverged = "⇕"
renamed = "➦"
deleted = "✖"
staged = "✚"
untracked = "…"
modified = "✱"
conflicted = "!"
Explanation:
-
format
: Defines the overall structure of your prompt, including the custom module$custom.izido
. -
[custom.izido]
: Configures the custom module namedizido
.-
command
: Executes a shell command to display a random saying and the top three pending todos fromstarship_izido.txt
. -
when
: Displays the module only if bothshow_izido
andstarship_izido.txt
exist. -
format
: Specifies how the output appears in the prompt.
-
Resulting Prompt Structure
- First Line: Displays a random saying followed by up to three pending todos with icons.
- Subsequent Lines: Show the current time, Git branch, and current directory.
Step 2: Create the izido.sh
Bash Script to Manage Your Todos
Create a script named izido.sh
to handle todo operations.
Create the Script File
Create a new file called izido.sh
:
touch izido.sh
Add the Following Content to izido.sh
:
#!/bin/bash
IZIDO_FILE="$HOME/.config/starship_izido.txt"
# Ensure the izido task list file exists
touch "$IZIDO_FILE"
function add_izido() {
local priority="$1"
local due_date="$2"
shift 2
local task="${*// /_}"
echo "pending,$priority,$due_date,$task" >> "$IZIDO_FILE"
echo "Added: $task with priority $priority and due date $due_date"
}
function list_todos() {
local filter="$1"
if [ ! -s "$IZIDO_FILE" ]; then
echo "No todos found."
return
fi
printf "%-5s %-10s %-10s %-12s %s\n" "ID" "Status" "Priority" "Due_Date" "Task"
awk -v filter="$filter" -F, '{
if (filter == "" || $1 == filter || $2 == filter) {
id=NR
status=$1
priority=$2
due_date=$3
task=$4
status_color = (status == "pending") ? "\033[33m" : "\033[32m"
priority_color = (priority == "high") ? "\033[31m" : ((priority == "normal") ? "\033[34m" : "\033[36m")
printf "%-5d %s%-10s\033[0m %s%-10s\033[0m %-12s %s\n", id, status_color, status, priority_color, priority, due_date, task
}
}' "$IZIDO_FILE"
}
function mark_done() {
local id="$1"
if [ -z "$id" ]; then
echo "Please provide the ID of the task to mark as done."
return
fi
sed -i "${id}s/^pending/done/" "$IZIDO_FILE"
echo "Marked task $id as done."
}
function remove_todo() {
local id="$1"
if [ -z "$id" ]; then
echo "Please provide the ID of the task to remove."
return
fi
sed -i "${id}d" "$IZIDO_FILE"
echo "Removed task $id."
}
function clear_todos() {
> "$IZIDO_FILE"
echo "Cleared all todos."
}
function izido_view() {
if [ "$1" == "on" ]; then
touch ~/.config/show_izido
echo "iZiDo on."
elif [ "$1" == "off" ]; then
rm -f ~/.config/show_izido
echo "iZiDo off."
else
echo "Usage: $0 view {on|off}"
fi
}
case "$1" in
add)
shift
if [ "$1" == "-p" ]; then
priority="$2"
shift 2
else
priority="normal"
fi
if [ "$1" == "-d" ]; then
due_date="$2"
shift 2
else
due_date="none"
fi
add_izido "$priority" "$due_date" "$@"
;;
list)
list_todos "$2"
;;
done)
mark_done "$2"
;;
remove)
remove_todo "$2"
;;
clear)
clear_todos
;;
view)
shift
izido_view "$1"
;;
*)
echo "Usage: $0 {add [-p priority] [-d due_date] task|list|done ID|remove ID|clear|view {on|off}}"
;;
esac
Explanation:
-
Shebang (
#!/bin/bash
): Specifies that the script runs with Bash. -
IZIDO_FILE
: Path to the todo list file. -
Functions:
-
add_izido
: Adds a new todo with optional priority and due date. -
list_todos
: Lists all todos, optionally filtered by status or priority. -
mark_done
: Marks a todo as done based on its ID. -
remove_todo
: Removes a todo based on its ID. -
clear_todos
: Clears all todos. -
izido_view
: Toggles the visibility of the Izido module in the prompt.
-
-
Argument Handling: Uses a
case
statement to handle commands (add
,list
,done
,remove
,clear
,view
).
Make the Script Executable
chmod +x izido.sh
Step 3: Configure the Script for Your Shell
Ensure that the izido.sh
script is accessible from your shell by adding it to your shell's initialization file.
For Bash Users
- Move the Script to a Directory in Your PATH
It's common to place custom scripts in ~/bin
or ~/.local/bin
. If you choose ~/bin
, ensure it's in your PATH.
mkdir -p ~/bin
mv izido.sh ~/bin/
- Add the Directory to Your PATH (if not already included)
Add the following line to your ~/.bashrc
:
export PATH="$HOME/bin:$PATH"
- Source the Script in Your
~/.bashrc
(Optional)
If you want to use aliases for convenience, add them to your ~/.bashrc
:
alias izido='bash ~/bin/izido.sh'
Reload your ~/.bashrc
:
source ~/.bashrc
For Zsh Users
- Move the Script to a Directory in Your PATH
Place the script in ~/bin
or ~/.local/bin
:
mkdir -p ~/bin
mv izido.sh ~/bin/
- Add the Directory to Your PATH (if not already included)
Add the following line to your ~/.zshrc
:
export PATH="$HOME/bin:$PATH"
- Source the Script in Your
~/.zshrc
(Optional)
Add aliases for convenience:
alias izido='bash ~/bin/izido.sh'
Reload your ~/.zshrc
:
source ~/.zshrc
Step 4: Using the Izido Script
Enable the Izido Module in Your Prompt
To display todo reminders in your prompt, enable the Izido module:
./izido.sh view on
Output:
iZiDo on.
Add a New Todo
Add a new todo with optional priority and due date:
./izido.sh add -p high -d 2024-11-03 "Post to Dev.to"
Output:
Added: Post to Dev.to with priority high and due date 2024-11-03
List All Todos
List all current todos:
./izido.sh list
Output:
ID Status Priority Due_Date Task
1 pending high 2024-11-03 Post to Dev.to
Mark a Todo as Done
Mark a todo as done using its ID:
./izido.sh done 1
Output:
Marked task 1 as done.
Remove a Todo
Remove a todo using its ID:
./izido.sh remove 1
Output:
Removed task 1.
Clear All Todos
Remove all todos:
./izido.sh clear
Output:
Cleared all todos.
Disable the Izido Module in Your Prompt
To hide the todo reminders:
./izido.sh view off
Output:
iZiDo off.
Step 5: Configure Shell Initialization (Optional)
To automatically load iZiDo when you start your terminal, you can add the enable command to your shell's initialization file.
For Bash Users
Add the following line to your ~/.bashrc
:
izido.sh view on
For Zsh Users
Add the following line to your ~/.zshrc
:
izido.sh view on
Reload your shell configuration:
- Bash:
source ~/.bashrc
- Zsh:
source ~/.zshrc
Step 6: See It in Action
Before Setting a Todo
Your prompt may appear as follows:
🕙 14:30:00
││ on main
│…/izido ❯
After Adding a Todo
After adding a todo:
./izido.sh add -p high -d 2024-11-03 "Post to Dev.to"
Your prompt updates to:
┌─❮ Chop Wood, Carry Water.
📝 Post to Dev.to (Due: 2024-11-03)
🕙 14:30:00
││ on main
│…/izido ❯
Final Thoughts
Integrating a custom module into your starship.toml
and utilizing the izido.sh
Bash script allows for managing and displaying todo reminders directly within your terminal prompt. This setup provides a method to keep track of tasks without leaving the terminal environment.
Resources
Share Your Experience
I am new to all this, so quite curious how others have customized their terminal prompts? Please, share your methods and tools in the comments.