Compare commits

...

4 Commits

Author SHA1 Message Date
James Tomasino a8aa135f43 updates Readme 2024-04-15 15:44:41 +00:00
James Tomasino d2212ef6f4 updates track to support additive logs 2024-04-15 15:40:32 +00:00
James Tomasino d740d8144e cleaning up typo in docs 2020-10-11 13:57:39 +00:00
James Tomasino fbc94f0b11 generate readme from manpage 2020-10-11 13:55:11 +00:00
4 changed files with 98 additions and 64 deletions

View File

@ -1,52 +0,0 @@
track ![calver](https://img.shields.io/badge/calver-2018.05.29-22bfda.svg?style=flat-square) ![status](https://img.shields.io/badge/status-working-green.svg?style=flat-square) ![license](https://img.shields.io/badge/license-GPL3-blue.svg?style=flat-square)
------
**track** is a minimalistic data manager for the shell.
Using the command line, track allows you to enter one and only one data point
on any metric per day. It's great for tracking your weight or how many cups of
coffee you drank. Track logs your data for each given metric to a CSV file. If
you track the same metric twice in the same day, the data is updated. There's
a few handy options for printing out the list data in useful formats as well.
### Install
`sudo make install`
_Note: On systems without admin access the binary can be run directly from the
git repo, but will lack `man` support and command completion._
### Uninstall
`sudo make uninstall`
## Usage
```bash
track [options] [metric] [value]
DIRECTORY:
If the environment variable $TRACK_DIR is set, track will store all data in
that location. Otherwise the default is the current working directory.
USAGE:
track weight 150 Log 150lbs for today's weight
track -n 10 calories Show last 10 days calorie values
track mood Show last value logged for mood
OPTIONS:
-a Show all values of metric
-n N Show N values of metric
-x Remove metric file
-h Show this help
-v Show current version info
-d Debug mode
```
## Contributing
Pull requests are welcome. For major changes, please open an issue first to
discuss what you would like to change.
## License
[GPL3](LICENSE)

59
README.txt Normal file
View File

@ -0,0 +1,59 @@
TRACK(1) General Commands Manual TRACK(1)
NAME
track - a minimalistic data tracker
SYNOPSIS
track [options] <metric> [<value>]
DESRIPTION
Using the command line, track allows you to enter one and only one data point on any metric per day. Its great for tracking your weight or how many
cups of coffee you drank. track logs your data for each given metric to a CSV file. If you track the same metric twice in the same day, the data is
updated. Data need not be numeric.
OPTIONS
Setting the $TRACK_DIR environment variable will change the default location where the data is stored. If it is not set the current directory is
used.
a Show all values of a metric
n <N> Show N values of a metric
x <metric>
Remove metric file
c Output in CSV format
l List all metrics being tracked
h Show the help.
v Display current version information.
d Debug mode.
EXAMPLES
track weight 150
Log 150lbs for todays weight
track n 10 calories
Show last 10 days calorie values
track mood tired and hungry
Log a multiword phrase as the value for your current mood
track mood
Show last value logged for mood
LICENSE
GNU General Public License v3.0 or later at
https://www.gnu.org/licenses/gpl3.0standalone.html
BUGS
Report issues at the git repository at https://github.com/jamestomasino/track
AUTHOR
James Tomasino <james (at) tomasino (dot) org>
v2024.04.15 15 Apr 2024 TRACK(1)

45
track
View File

@ -2,7 +2,7 @@
# This file defines track - a minimalist data tracker
# Copyright (C) 2020 James Tomasino
# Copyright (C) 2024 James Tomasino
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -19,7 +19,7 @@
#-----------------------------------------------------------------------
version="2020.10.11"
version="2024.04.15"
show_help () {
cat > /dev/stdout << END
@ -32,6 +32,7 @@ DIRECTORY:
USAGE:
track weight 150 Log 150lbs for today's weight
track steps +500 Increase the numeric log of today's steps by 500
track -n 10 calories Show last 10 days calorie values
track mood Show last value logged for mood
@ -50,7 +51,7 @@ END
# Determine tracking directory and ensure it is a directory
TRACK_DIR=${TRACK_DIR:-.}
if [ -f "$TRACK_DIR" ]; then
TRACK_DIR="$(dirname ${TRACK_DIR})"
TRACK_DIR="$(dirname "${TRACK_DIR}")"
fi
arg_metric=""
@ -170,15 +171,41 @@ main () {
printf "year,month,day,%s\\n" "${arg_metric}" > "$f"
fi
if [ "${arg_value}" != "" ]; then
# Get arg parts
first_letter=$(printf %.1s "${arg_value}")
if [ "${arg_value}" != "" ]; then # add/update
d=$(date '+%Y,%0m,%0d')
l=$(sed -n "/$d/{=;}" "$f")
if [ -z "$l" ]; then
printf "%s,%s\\n" "$d" "${arg_value}" >> "$f"
else
sed -i"" "$l c $d,${arg_value}" "$f"
if [ "${first_letter}" = "+" ]; then # Add to existing value
rest="${arg_value#+}"
if [ -z "$l" ]; then
printf "%s,%s\\n" "$d" "${rest}" >> "$f"
else
val="$(sed "${l}q;d" "$f" | awk -F "," '{print $4}')" # get current value
# check if existing value is numeric before attempting to sum
if printf "%s" "$val" | grep -vEq '^[0-9]+([.][0-9]+)?$'; then
printf "Current value is not numeric. Abort.\\n"-
exit 1
fi
# check if new value is numeric before attempting to sum
if printf "%s" "$rest" | grep -vEq '^[0-9]+([.][0-9]+)?$'; then
printf "New value is not numeric. Abort.\\n"-
exit 1
fi
# sum new and previous values
newval=$((val+rest)) || exit 1
sed -i"" "$l c $d,${newval}" "$f"
fi
else # Replace existing value
if [ -z "$l" ]; then
printf "%s,%s\\n" "$d" "${arg_value}" >> "$f"
else
sed -i"" "$l c $d,${arg_value}" "$f"
fi
fi
else
else # display value
if [ ${flag_listall} -gt 0 ]; then
if [ ${flag_csv} -gt 0 ]; then
awk -F "," '{printf "%02d-%02d-%02d,%s\n", $1, $2, $3, $4;}' "$f"

View File

@ -1,4 +1,4 @@
.TH TRACK 1 "11 Oct 2020" "v2020.10.11"
.TH TRACK 1 "15 Apr 2024" "v2024.04.15"
.SH NAME
track \- a minimalistic data tracker
@ -54,8 +54,8 @@ Log 150lbs for today's weight
.B track -n 10 calories
Show last 10 days calorie values
.TP
.B track mood `tired and hungry'
Show last value logged for mood
.B track mood "tired and hungry"
Log a multi-word phrase as the value for your current mood
.TP
.B track mood
Show last value logged for mood