-
-
Save voidcoefficient/6cf1b7f0564cf4e27e2ceebe9cee4a15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # @meta version beta | |
| # @meta require-tools gum,argc,jrnl,jq,cut | |
| # @describe medicine tracker written in bash | |
| # | |
| # AUTHOR: Marla Albuquerque <marla@albuque.com> | |
| # | |
| MEDS_DIR="$HOME/.local/share/meds" | |
| MEDS_FILE="$MEDS_DIR/list" | |
| mkdir -p "$MEDS_DIR" | |
| touch "$MEDS_FILE" | |
| tag="%took" | |
| _default_dosage() { | |
| jrnl -1 -contains "$tag" -and -contains "$1" --format json 2>/dev/null | jq ".entries[0].title" | cut -d "(" -f2 | cut -d ")" -f1 | |
| } | |
| # @cmd lists medicines | |
| # @alias l,ls | |
| list() { | |
| cat "$MEDS_FILE" | |
| } | |
| # @cmd medicine intake history | |
| # @alias h | |
| history() { | |
| jrnl --short -contains "$tag" 2>/dev/null | |
| } | |
| # @cmd add a new medicine | |
| # @alias a | |
| # @arg name! medicine name | |
| add() { | |
| echo "$argc_name" >>"$MEDS_FILE" | |
| logger info "added medicine '$argc_name'" | |
| } | |
| # @cmd take medicine | |
| # @alias t | |
| # @arg name![`list`] medicine name | |
| # @option -d --dosage medicine dosage | |
| take() { | |
| if [ -n "$argc_dosage" ]; then | |
| logger debug "taking medicine '$argc_name' ($argc_dosage)..." | |
| jrnl "$tag $argc_name ($argc_dosage)" | |
| else | |
| dosage=$( | |
| gum input \ | |
| --value "$(_default_dosage "$argc_name")" \ | |
| --header "medicine dosage" \ | |
| --header.foreground 255 \ | |
| --placeholder "" \ | |
| --placeholder.foreground 250 | |
| ) | |
| if [ -n "$dosage" ]; then | |
| logger debug "taking medicine '$argc_name' ($dosage)..." | |
| jrnl "$tag $argc_name ($dosage)" | |
| else | |
| logger error "could not parse dosage" | |
| exit 1 | |
| fi | |
| fi | |
| } | |
| # @cmd undo your last medicine | |
| # @alias u | |
| # @arg name[`list`] medicine name | |
| undo() { | |
| if [ -n "$argc_name" ]; then | |
| jrnl -contains "$tag" -and -contains "$argc_name" -1 --delete | |
| else | |
| jrnl -contains "$tag" -1 --delete | |
| fi | |
| } | |
| eval "$(argc --argc-eval "$0" "$@")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment