used proper directories

main
KeeganForelight 2 years ago
parent 060d6c8293
commit cb98d87e4a

@ -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

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

Loading…
Cancel
Save