Skip to content

Instantly share code, notes, and snippets.

@kyleterry
Created March 26, 2020 19:37
Show Gist options
  • Save kyleterry/2968b875dfb7244ef8360ad799b5cb1e to your computer and use it in GitHub Desktop.
Save kyleterry/2968b875dfb7244ef8360ad799b5cb1e to your computer and use it in GitHub Desktop.
#!/bin/bash
WORKOUT_LOG_DIR="${HOME}/.local/share/workout-log"
WORKOUT_LOG_DB="${WORKOUT_LOG_DIR}/workout.db"
# workout-log-setup ensures the data dir and db file exist
_workout-log-setup() {
test -d "${WORKOUT_LOG_DIR}" || mkdir -p "${WORKOUT_LOG_DIR}"
test -f "${WORKOUT_LOG_DB}" || echo "name,count,timestamp" > "${WORKOUT_LOG_DB}"
}
workout-log-write-record() {
_workout-log-setup
local name=${1}
local count=${2}
local timestamp=$(date --rfc-3339=seconds | sed 's/ /T/')
echo "${name},${count},${timestamp}" >> "${WORKOUT_LOG_DB}"
}
workout-log-read-records() {
column -t -s, "${WORKOUT_LOG_DB}" | less +G
}
log-workout() {
workout-log-write-record $@
}
get-workouts() {
workout-log-read-records $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment