Advertisement
HasteBin0

Todo Manager

Aug 19th, 2023 (edited)
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.62 KB | None | 0 0
  1. #!/usr/bin/sh
  2.  
  3. display_help() {
  4.     cat << EOF
  5.  
  6. Script Name: Todo Manager
  7. Author: Aidan Danielski
  8. Date Created: Sat August 19th 2023
  9. Description:
  10.   A utility script to manage todo entries stored in specific directories.
  11.   Provides functionalities for listing, reading, retiring, and clearing entries.
  12.  
  13. Usage:
  14.   ./script.sh [where] [action] [entry-name/pattern (if required)]
  15.  
  16. Arguments:
  17.   where:
  18.     Specify the storage location. Options include:
  19.       - db|drop|box|dropbox: Refers to $HOME/Dropbox/todo
  20.       - ms|mega|sync|megasync: Refers to $HOME/MEGAsync/todo
  21.  
  22.   action:
  23.     Specify the action to perform. Options include:
  24.       - list: Lists all entries
  25.       - read: Reads a specific entry
  26.       - retire: Moves an entry to a "retired" folder
  27.       - clear: Deletes all entries
  28.       - If no action is provided, creates a new entry
  29.  
  30.   entry-name/pattern:
  31.     Used with the "read" and "retire" actions to specify which entry to act upon.
  32.  
  33. Examples:
  34.   ./script.sh db list: Lists all entries in the Dropbox todo folder.
  35.   ./script.sh ms read project: Reads entries containing the word "project" in the MEGAsync todo folder.
  36.   ./script.sh drop retire old-task: Retires entries containing the word "old-task" in the Dropbox todo folder.
  37.   ./script.sh mega clear: Deletes all entries in the MEGAsync todo folder.
  38.  
  39. Note:
  40.   Be cautious when using the clear action. Ensure backups are made as this will delete all files in the chosen location.
  41.  
  42. EOF
  43. }
  44.  
  45. where="$1"
  46. action="$2"
  47. entry="$3"
  48.  
  49. # Display help if the user provides "help" as the first argument
  50. if [ "$where" = "help" ]; then
  51.     display_help
  52.     exit 0
  53. fi
  54.  
  55. if [ -z "$where" ]; then
  56.     echo "Please provide a storage argument."
  57.     exit 1
  58. fi
  59.  
  60. case $where in
  61.     db|drop|box|dropbox)
  62.         folder="$HOME/Dropbox/todo"
  63.         ;;
  64.     ms|mega|sync|megasync)
  65.         folder="$HOME/MEGAsync/todo"
  66.         ;;
  67.     *)
  68.         echo "Invalid \"$where\" :: ..."
  69.         exit 1
  70.         ;;
  71. esac
  72.  
  73. cd "$folder" || { echo "Error: Unable to change directory to $folder"; exit 1; }
  74.  
  75. case $action in
  76.     list)
  77.         ls -al --color=auto
  78.         ;;
  79.  
  80.     read)
  81.         if [ -z "$entry" ]; then
  82.             echo "Please provide a filename or part of the filename to read."
  83.             exit 1
  84.         fi
  85.         grep -l "$entry" * | xargs cat
  86.         ;;
  87.  
  88.     retire)
  89.         if [ -z "$entry" ]; then
  90.             echo "Please provide a filename or part of the filename to retire."
  91.             exit 1
  92.         fi
  93.         mkdir -p retired
  94.         mv "$(grep -l "$entry" *)" retired/
  95.         ;;
  96.  
  97.     clear)
  98.         echo "Clearing all entries..."
  99.         rm *
  100.         ;;
  101.  
  102.     *)
  103.         new="Todo entry $(date '+%Y-%m-%d %H:%M:%S').txt"
  104.         echo "Opening $new!"
  105.         touch "$new"
  106.         chmod +rw "$new"
  107.         /usr/bin/gedit "$new" &
  108.         ;;
  109. esac
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement