Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/sh
- display_help() {
- cat << EOF
- Script Name: Todo Manager
- Author: Aidan Danielski
- Date Created: Sat August 19th 2023
- Description:
- A utility script to manage todo entries stored in specific directories.
- Provides functionalities for listing, reading, retiring, and clearing entries.
- Usage:
- ./script.sh [where] [action] [entry-name/pattern (if required)]
- Arguments:
- where:
- Specify the storage location. Options include:
- - db|drop|box|dropbox: Refers to $HOME/Dropbox/todo
- - ms|mega|sync|megasync: Refers to $HOME/MEGAsync/todo
- action:
- Specify the action to perform. Options include:
- - list: Lists all entries
- - read: Reads a specific entry
- - retire: Moves an entry to a "retired" folder
- - clear: Deletes all entries
- - If no action is provided, creates a new entry
- entry-name/pattern:
- Used with the "read" and "retire" actions to specify which entry to act upon.
- Examples:
- ./script.sh db list: Lists all entries in the Dropbox todo folder.
- ./script.sh ms read project: Reads entries containing the word "project" in the MEGAsync todo folder.
- ./script.sh drop retire old-task: Retires entries containing the word "old-task" in the Dropbox todo folder.
- ./script.sh mega clear: Deletes all entries in the MEGAsync todo folder.
- Note:
- Be cautious when using the clear action. Ensure backups are made as this will delete all files in the chosen location.
- EOF
- }
- where="$1"
- action="$2"
- entry="$3"
- # Display help if the user provides "help" as the first argument
- if [ "$where" = "help" ]; then
- display_help
- exit 0
- fi
- if [ -z "$where" ]; then
- echo "Please provide a storage argument."
- exit 1
- fi
- case $where in
- db|drop|box|dropbox)
- folder="$HOME/Dropbox/todo"
- ;;
- ms|mega|sync|megasync)
- folder="$HOME/MEGAsync/todo"
- ;;
- *)
- echo "Invalid \"$where\" :: ..."
- exit 1
- ;;
- esac
- cd "$folder" || { echo "Error: Unable to change directory to $folder"; exit 1; }
- case $action in
- list)
- ls -al --color=auto
- ;;
- read)
- if [ -z "$entry" ]; then
- echo "Please provide a filename or part of the filename to read."
- exit 1
- fi
- grep -l "$entry" * | xargs cat
- ;;
- retire)
- if [ -z "$entry" ]; then
- echo "Please provide a filename or part of the filename to retire."
- exit 1
- fi
- mkdir -p retired
- mv "$(grep -l "$entry" *)" retired/
- ;;
- clear)
- echo "Clearing all entries..."
- rm *
- ;;
- *)
- new="Todo entry $(date '+%Y-%m-%d %H:%M:%S').txt"
- echo "Opening $new!"
- touch "$new"
- chmod +rw "$new"
- /usr/bin/gedit "$new" &
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement