used proper directories

This commit is contained in:
KeeganForelight 2023-01-13 14:14:26 -05:00
parent 060d6c8293
commit cb98d87e4a
2 changed files with 17 additions and 19 deletions

View File

@ -1,3 +0,0 @@
Time, Change, Running Total
13:02:53, 0, 0
13:03:30, 32, 32
1 Time Change Running Total
2 13:02:53 0 0
3 13:03:30 32 32

View File

@ -32,8 +32,9 @@ exit $1
DATE=$(date +%b_%d_%y) DATE=$(date +%b_%d_%y)
TIME=$(date +%H:%M:%S) TIME=$(date +%H:%M:%S)
WATER_DIR="$HOME/.dotfiles/bin/water" WORKING_DIR="$HOME/.local/share/watertracker"
WATERFILE="${WATER_DIR}/${DATE}.csv" # makes it easy to reset on each new day ARCHIVE_DIR="$WORKING_DIR/archive"
WATER_FILE="$WORKING_DIR/$DATE.csv" # makes it easy to reset on each new day
# customize goal amt and timings. # customize goal amt and timings.
@ -61,18 +62,18 @@ DYNAMIC_SYMBOL=( '\uf58d' '\uf579' '\uf57a' '\uf57b' '\uf57c' '\uf57d' '\uf57e'
get_current_amt() { get_current_amt() {
# gets the current water intake # gets the current water intake
if [[ ! -f "$WATERFILE" ]] ; then if [[ ! -f "$WATER_FILE" ]] ; then
# no waterfile # no waterfile
# archiving old file # archiving old file
mv ${WATER_DIR}/*.csv ${WATER_DIR}/archive mv "$WORKING_DIR/*.csv" "$ARCHIVE_DIR"
# creating new file for the day # creating new file for the day
printf 'Time, Change, Running Total\n' > "$WATERFILE" printf 'Time, Change, Running Total\n' > "$WATER_FILE"
printf '%s, 0, 0\n' "$TIME" >> "$WATERFILE" printf '%s, 0, 0\n' "$TIME" >> "$WATER_FILE"
else else
# waterfile exists # waterfile exists
CURRENT_WATER=$(cat $WATERFILE | tail -n 1 | awk '{print $3}') CURRENT_WATER=$(cat $WATER_FILE | tail -n 1 | awk '{print $3}')
fi fi
@ -102,7 +103,7 @@ reminder() {
if [[ $expired -lt 0 ]] ; then if [[ $expired -lt 0 ]] ; then
# goal missed, check snooze # goal missed, check snooze
source "$WATER_DIR/.reminder" 2>/dev/null source "$WORKING_DIR/.reminder" 2>/dev/null
# check elapsed # check elapsed
if [[ $time_unix -gt $REMINDER_SNOOZE ]] ; then if [[ $time_unix -gt $REMINDER_SNOOZE ]] ; then
@ -129,7 +130,7 @@ reminder() {
fi fi
# update last_reminder # update last_reminder
printf 'REMINDER_SNOOZE=%d\n' $TTS > "$WATER_DIR/.reminder" printf 'REMINDER_SNOOZE=%d\n' $TTS > "$WORKING_DIR/.reminder"
fi fi
fi fi
fi fi
@ -142,14 +143,14 @@ update_water() {
CURRENT_WATER=$(($CURRENT_WATER + $WATER_CHANGE)) CURRENT_WATER=$(($CURRENT_WATER + $WATER_CHANGE))
# putting in file # putting in file
printf '%s, %d, %d\n' "$TIME" $WATER_CHANGE $CURRENT_WATER >> "$WATERFILE" printf '%s, %d, %d\n' "$TIME" $WATER_CHANGE $CURRENT_WATER >> "$WATER_FILE"
} }
undo_changes() { undo_changes() {
# removes specifed entries # removes specifed entries
# gets the lines of entries # gets the lines of entries
WATER_LINES=$(($(wc -l < "$WATERFILE") - 2)) WATER_LINES=$(($(wc -l < "$WATER_FILE") - 2))
if [[ $WATER_LINES -gt 0 ]] ; then if [[ $WATER_LINES -gt 0 ]] ; then
# removing entries # removing entries
@ -178,11 +179,11 @@ undo_changes() {
if [[ $WATER_LINES -gt $REMOVAL ]] ; then if [[ $WATER_LINES -gt $REMOVAL ]] ; then
# removing specified lines # removing specified lines
last_line=$(($WATER_LINES - $REMOVAL + 3)) # account for offset last_line=$(($WATER_LINES - $REMOVAL + 3)) # account for offset
sed -i "$last_line ,$ d" "$WATERFILE" sed -i "$last_line ,$ d" "$WATER_FILE"
else else
# essentially a reset # essentially a reset
printf 'Time, Change, Running Total\n' > "$WATERFILE" printf 'Time, Change, Running Total\n' > "$WATER_FILE"
printf '%s, 0, 0\n' "$TIME" >> "$WATERFILE" printf '%s, 0, 0\n' "$TIME" >> "$WATER_FILE"
fi fi
# updating amount # updating amount
@ -254,8 +255,8 @@ print_water() {
} }
# make dir on fresh installs # make dir on fresh installs
if [[ ! -d "${WATER_DIR}/archive" ]] ; then if [[ ! -d "$ARCHIVE_DIR" ]] ; then
mkdir -p "${WATER_DIR}/archive" mkdir -p "$ARCHIVE_DIR"
fi fi
# get the current amount # get the current amount