A simple shell script to track the time you spend on tasks, based upon a script shared in the comments on Gina Trapani's Lifehacker article Geek to Live: Quick-Log Your Work Day.
- Create a companion script to parse and report total time spent on projects
To add more shortcut options, there are a couple things you need to do to make sure everything works as expected:
- Update the associative array ("declare -A shortcut…") to include your new option.
- Update the code that provides the different options (two different places in the "while getopts…" loop).
- Add your new shortcut definition.
- (Optional) Update the help (contents of "OPTIONS_HELP=" section) to document your new shortcut.
Example: To add a new shortcut using the "-i" parameter that will enter the task "Buy ice cream", do the following:
- Update the line that starts with "declare -A shortcut" to add the new "i" option at the end:
declare -A shortcut=([e]=false [s]=false [p]=false [h]=false [i]=false)
-
Updating the code that provides the different options:
- Update the "while getopts…" loop line to add the "i" option after the "h" option:
while getopts ":esp:hi" OPTION; do
- Update the line AFTER the one that reads "case $option in" to include the "|i" right before the ")":
e|s|p|h|i) shortcut[$OPTION]=true ;;
-
Add the new shortcut definition at the end of the "=== SHORTCUT DEFINITIONS ===" block:
${shortcut[i]} && echo "$TODAY @ $TIME – Buy ice cream" >> $LOG_FILE && exit 0
- Switched to a zsh script (macOS default bash version doesn't support associative arrays)
- Added shortcut options, including help
- Added ability to define task as a script argument for quicker entry
- Retained original Q&A behavior as a fallback if options or an argument aren't provided
- Added configuration section for log file format & location
- Added ability to auto-create desired log file path (if it doesn't already exist)
- Initial release of basic Q&A functionality