From 1fbec25996bc11a4f29c1e62fd20c53013be9fe6 Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Fri, 13 Jan 2023 13:43:24 -0500 Subject: [PATCH] moved from dotfiles --- .gitignore | 0 .reminder | 1 + Jan_13_23.csv | 3 + archive/Jan_11_23.csv | 2 + archive/Jan_12_23.csv | 4 + archive/Jan_13_23.csv | 2 + archive/test_archive/01-06 | 1 + archive/test_archive/01-09 | 1 + archive/test_archive/01-10 | 1 + archive/test_archive/01-11 | 1 + archive/test_archive/10-12 | 1 + archive/test_archive/10-16 | 1 + archive/test_archive/10-17 | 1 + archive/test_archive/10-19 | 1 + archive/test_archive/10-26 | 1 + archive/test_archive/10-27 | 1 + archive/test_archive/11-02 | 1 + archive/test_archive/11-03 | 1 + archive/test_archive/11-17 | 1 + archive/test_archive/11-18 | 1 + archive/test_archive/11-20 | 1 + archive/test_archive/11-21 | 1 + archive/test_archive/11-28 | 1 + archive/test_archive/11-29 | 1 + archive/test_archive/11-30 | 1 + archive/test_archive/12-01 | 1 + archive/test_archive/12-02 | 1 + archive/test_archive/12-05 | 1 + archive/test_archive/12-06 | 1 + archive/test_archive/12-07 | 1 + archive/test_archive/12-08 | 1 + archive/test_archive/12-09 | 1 + water.sh | 324 +++++++++++++++++++++++++++++++++++++ 33 files changed, 362 insertions(+) create mode 100644 .gitignore create mode 100644 .reminder create mode 100644 Jan_13_23.csv create mode 100644 archive/Jan_11_23.csv create mode 100644 archive/Jan_12_23.csv create mode 100644 archive/Jan_13_23.csv create mode 100644 archive/test_archive/01-06 create mode 100644 archive/test_archive/01-09 create mode 100644 archive/test_archive/01-10 create mode 100644 archive/test_archive/01-11 create mode 100644 archive/test_archive/10-12 create mode 100644 archive/test_archive/10-16 create mode 100644 archive/test_archive/10-17 create mode 100644 archive/test_archive/10-19 create mode 100644 archive/test_archive/10-26 create mode 100644 archive/test_archive/10-27 create mode 100644 archive/test_archive/11-02 create mode 100644 archive/test_archive/11-03 create mode 100644 archive/test_archive/11-17 create mode 100644 archive/test_archive/11-18 create mode 100644 archive/test_archive/11-20 create mode 100644 archive/test_archive/11-21 create mode 100644 archive/test_archive/11-28 create mode 100644 archive/test_archive/11-29 create mode 100644 archive/test_archive/11-30 create mode 100644 archive/test_archive/12-01 create mode 100644 archive/test_archive/12-02 create mode 100644 archive/test_archive/12-05 create mode 100644 archive/test_archive/12-06 create mode 100644 archive/test_archive/12-07 create mode 100644 archive/test_archive/12-08 create mode 100644 archive/test_archive/12-09 create mode 100755 water.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.reminder b/.reminder new file mode 100644 index 0000000..df0f116 --- /dev/null +++ b/.reminder @@ -0,0 +1 @@ +REMINDER_SNOOZE=1673636074 diff --git a/Jan_13_23.csv b/Jan_13_23.csv new file mode 100644 index 0000000..5aac96c --- /dev/null +++ b/Jan_13_23.csv @@ -0,0 +1,3 @@ +Time, Change, Running Total +13:02:53, 0, 0 +13:03:30, 32, 32 diff --git a/archive/Jan_11_23.csv b/archive/Jan_11_23.csv new file mode 100644 index 0000000..13af584 --- /dev/null +++ b/archive/Jan_11_23.csv @@ -0,0 +1,2 @@ +Time, Change, Running Total +16:04:25, 0, 0 diff --git a/archive/Jan_12_23.csv b/archive/Jan_12_23.csv new file mode 100644 index 0000000..d8f35db --- /dev/null +++ b/archive/Jan_12_23.csv @@ -0,0 +1,4 @@ +Time, Change, Running Total +10:36:16, 0, 0 +13:31:58, 32, 32 +16:17:41, 32, 64 diff --git a/archive/Jan_13_23.csv b/archive/Jan_13_23.csv new file mode 100644 index 0000000..ddc803a --- /dev/null +++ b/archive/Jan_13_23.csv @@ -0,0 +1,2 @@ +Time, Change, Running Total +11:41:16, 0, 0 diff --git a/archive/test_archive/01-06 b/archive/test_archive/01-06 new file mode 100644 index 0000000..ed9b1b0 --- /dev/null +++ b/archive/test_archive/01-06 @@ -0,0 +1 @@ +14:48:42: 0 diff --git a/archive/test_archive/01-09 b/archive/test_archive/01-09 new file mode 100644 index 0000000..248a60d --- /dev/null +++ b/archive/test_archive/01-09 @@ -0,0 +1 @@ +12:43:47: 0 diff --git a/archive/test_archive/01-10 b/archive/test_archive/01-10 new file mode 100644 index 0000000..3b33d88 --- /dev/null +++ b/archive/test_archive/01-10 @@ -0,0 +1 @@ +10:46:21: 0 diff --git a/archive/test_archive/01-11 b/archive/test_archive/01-11 new file mode 100644 index 0000000..6073a50 --- /dev/null +++ b/archive/test_archive/01-11 @@ -0,0 +1 @@ +11:34:07: 0 diff --git a/archive/test_archive/10-12 b/archive/test_archive/10-12 new file mode 100644 index 0000000..a122e3a --- /dev/null +++ b/archive/test_archive/10-12 @@ -0,0 +1 @@ +09:48:45: 0 diff --git a/archive/test_archive/10-16 b/archive/test_archive/10-16 new file mode 100644 index 0000000..7ce8643 --- /dev/null +++ b/archive/test_archive/10-16 @@ -0,0 +1 @@ +15:12:03: 0 diff --git a/archive/test_archive/10-17 b/archive/test_archive/10-17 new file mode 100644 index 0000000..8f8f3f1 --- /dev/null +++ b/archive/test_archive/10-17 @@ -0,0 +1 @@ +11:09:29: 0 diff --git a/archive/test_archive/10-19 b/archive/test_archive/10-19 new file mode 100644 index 0000000..f0e5180 --- /dev/null +++ b/archive/test_archive/10-19 @@ -0,0 +1 @@ +13:34:58: 0 diff --git a/archive/test_archive/10-26 b/archive/test_archive/10-26 new file mode 100644 index 0000000..bdbf0a3 --- /dev/null +++ b/archive/test_archive/10-26 @@ -0,0 +1 @@ +14:45:14: 0 diff --git a/archive/test_archive/10-27 b/archive/test_archive/10-27 new file mode 100644 index 0000000..e6b64c8 --- /dev/null +++ b/archive/test_archive/10-27 @@ -0,0 +1 @@ +19:43:32: 0 diff --git a/archive/test_archive/11-02 b/archive/test_archive/11-02 new file mode 100644 index 0000000..560661c --- /dev/null +++ b/archive/test_archive/11-02 @@ -0,0 +1 @@ +13:25:32: 0 diff --git a/archive/test_archive/11-03 b/archive/test_archive/11-03 new file mode 100644 index 0000000..2fc1cf2 --- /dev/null +++ b/archive/test_archive/11-03 @@ -0,0 +1 @@ +14:25:37: 0 diff --git a/archive/test_archive/11-17 b/archive/test_archive/11-17 new file mode 100644 index 0000000..465dd84 --- /dev/null +++ b/archive/test_archive/11-17 @@ -0,0 +1 @@ +15:14:26: 0 diff --git a/archive/test_archive/11-18 b/archive/test_archive/11-18 new file mode 100644 index 0000000..9792031 --- /dev/null +++ b/archive/test_archive/11-18 @@ -0,0 +1 @@ +17:04:05: 0 diff --git a/archive/test_archive/11-20 b/archive/test_archive/11-20 new file mode 100644 index 0000000..1496533 --- /dev/null +++ b/archive/test_archive/11-20 @@ -0,0 +1 @@ +15:58:36: 0 diff --git a/archive/test_archive/11-21 b/archive/test_archive/11-21 new file mode 100644 index 0000000..fc373c8 --- /dev/null +++ b/archive/test_archive/11-21 @@ -0,0 +1 @@ +15:11:15: 0 diff --git a/archive/test_archive/11-28 b/archive/test_archive/11-28 new file mode 100644 index 0000000..92de355 --- /dev/null +++ b/archive/test_archive/11-28 @@ -0,0 +1 @@ +13:18:08: 0 diff --git a/archive/test_archive/11-29 b/archive/test_archive/11-29 new file mode 100644 index 0000000..57f67af --- /dev/null +++ b/archive/test_archive/11-29 @@ -0,0 +1 @@ +13:46:08: 0 diff --git a/archive/test_archive/11-30 b/archive/test_archive/11-30 new file mode 100644 index 0000000..c839b3f --- /dev/null +++ b/archive/test_archive/11-30 @@ -0,0 +1 @@ +15:21:34: 0 diff --git a/archive/test_archive/12-01 b/archive/test_archive/12-01 new file mode 100644 index 0000000..39f6db0 --- /dev/null +++ b/archive/test_archive/12-01 @@ -0,0 +1 @@ +13:38:08: 0 diff --git a/archive/test_archive/12-02 b/archive/test_archive/12-02 new file mode 100644 index 0000000..92b140c --- /dev/null +++ b/archive/test_archive/12-02 @@ -0,0 +1 @@ +17:23:39: 0 diff --git a/archive/test_archive/12-05 b/archive/test_archive/12-05 new file mode 100644 index 0000000..9d18aa9 --- /dev/null +++ b/archive/test_archive/12-05 @@ -0,0 +1 @@ +15:03:18: 0 diff --git a/archive/test_archive/12-06 b/archive/test_archive/12-06 new file mode 100644 index 0000000..4eeda85 --- /dev/null +++ b/archive/test_archive/12-06 @@ -0,0 +1 @@ +16:31:28: 0 diff --git a/archive/test_archive/12-07 b/archive/test_archive/12-07 new file mode 100644 index 0000000..6a84244 --- /dev/null +++ b/archive/test_archive/12-07 @@ -0,0 +1 @@ +15:48:24: 0 diff --git a/archive/test_archive/12-08 b/archive/test_archive/12-08 new file mode 100644 index 0000000..7f74434 --- /dev/null +++ b/archive/test_archive/12-08 @@ -0,0 +1 @@ +11:13:31: 0 diff --git a/archive/test_archive/12-09 b/archive/test_archive/12-09 new file mode 100644 index 0000000..9a01a51 --- /dev/null +++ b/archive/test_archive/12-09 @@ -0,0 +1 @@ +11:57:37: 0 diff --git a/water.sh b/water.sh new file mode 100755 index 0000000..c2e7d59 --- /dev/null +++ b/water.sh @@ -0,0 +1,324 @@ +#!/usr/bin/env bash + +# this script enables water tracking in tmux status bar via a simple command + +usage() { + cat < full +DYNAMIC_SYMBOL=( '\uf58d' '\uf579' '\uf57a' '\uf57b' '\uf57c' '\uf57d' '\uf57e' '\uf57f' '\uf580' '\uf581' '\uf578' ) + +get_current_amt() { + # gets the current water intake + + if [[ ! -f "$WATERFILE" ]] ; then + # no waterfile + + # archiving old file + mv ${WATER_DIR}/*.csv ${WATER_DIR}/archive + + # creating new file for the day + printf 'Time, Change, Running Total\n' > "$WATERFILE" + printf '%s, 0, 0\n' "$TIME" >> "$WATERFILE" + else + # waterfile exists + CURRENT_WATER=$(cat $WATERFILE | tail -n 1 | awk '{print $3}') + fi + + +} + + +reminder() { + # checks and creates a reminder + + if [[ -z "$TMUX" ]] ; then + echo "TMUX required for reminder!" + exit 1 + fi + + # this will round up + goal_incr=$((($GOAL_AMT + ${#GOALS[@]}-1) / ${#GOALS[@]})) + + # index of the time to check in $GOALS + cur_indx=$(($CURRENT_WATER / $goal_incr)) + + if [[ $CURRENT_WATER -lt $GOAL_AMT ]] ; then + # goals not finished, check pace + + time_unix=$(date -d "$TIME" +%s) + # expired is goaltime - current time + expired=$(( $(date -d "${GOALS[$cur_indx]}" +%s) - $time_unix)) + + if [[ $expired -lt 0 ]] ; then + # goal missed, check snooze + source "$WATER_DIR/.reminder" 2>/dev/null + + # check elapsed + if [[ $time_unix -gt $REMINDER_SNOOZE ]] ; then + # trigger reminder + + goal=$(( ($GOAL_AMT * ($cur_indx + 1)) / ${#GOALS[@]})) + + fmt_time=$(date -d "${GOALS[$cur_indx]}" "+%l:%M %P") + rem_info=$(printf 'You have only drank %d fl. oz. while your goal is to drink %d fl. oz. by %s!\n\nThis reminder will reappear in %d minutes unless you consume fluids!\n\nOptionally, mute this reminder until tomorrow' $CURRENT_WATER $goal "$fmt_time" $SNOOZE) + tmux display-popup -E\ + dialog\ + --title 'DEHYDRATION ALERT'\ + --yes-label 'Dismiss'\ + --no-label 'Mute'\ + --yesno \ + "$rem_info" 0 0 + + # check for mute + if [[ $? == 1 ]] ; then + # muted until tomorrow + TTS=$(date -d "tomorrow 00:00:00" +%s) + else + TTS=$(date -d "+ $SNOOZE minutes" +%s) + fi + + # update last_reminder + printf 'REMINDER_SNOOZE=%d\n' $TTS > "$WATER_DIR/.reminder" + fi + fi + fi +} + + +update_water() { + # updates water based on $WATER_CHANGE + + CURRENT_WATER=$(($CURRENT_WATER + $WATER_CHANGE)) + + # putting in file + printf '%s, %d, %d\n' "$TIME" $WATER_CHANGE $CURRENT_WATER >> "$WATERFILE" +} + +undo_changes() { + # removes specifed entries + + # gets the lines of entries + WATER_LINES=$(($(wc -l < "$WATERFILE") - 2)) + + if [[ $WATER_LINES -gt 0 ]] ; then + # removing entries + if [[ "$1" == "all" || "$1" == "ALL" ]] ; then + # force a reset + REMOVAL=$WATER_LINES + elif [[ $1 =~ ^[0-9]+$ ]] ; then + # remove $1 changes + if [[ $1 -gt $WATER_LINES ]] ; then + printf 'Only %d entries\n' $WATER_LINES + REMOVAL=$WATER_LINES + else + REMOVAL=$1 + fi + else + printf 'Arguement %s not recognized\n' "$1" + usage + exit 1 + fi + + choice=$(bash -c "read -p 'Are you sure you want to remove $REMOVAL entries? (y/n)' -n 1 -r c; echo \$c") + echo "" + + if [[ $choice =~ ^[Yy]$ ]] ; then + # remove + if [[ $WATER_LINES -gt $REMOVAL ]] ; then + # removing specified lines + last_line=$(($WATER_LINES - $REMOVAL + 3)) # account for offset + sed -i "$last_line ,$ d" "$WATERFILE" + else + # essentially a reset + printf 'Time, Change, Running Total\n' > "$WATERFILE" + printf '%s, 0, 0\n' "$TIME" >> "$WATERFILE" + fi + + # updating amount + get_current_amt + fi + echo "Removed $REMOVAL entries!" + else + echo "Nothing to remove!" + fi +} + +colorize() { + # sends water intake level through conditionals to be colorized + + if [[ $1 -lt 32 ]] ; then + color="$RED" + elif [[ $1 -lt 64 ]] ; then + color="$YELLOW" + elif [[ $1 -lt 96 ]] ; then + color="$LIGHT_YELLOW" + elif [[ $1 -lt 128 ]] ; then + color="$LIGHT_GREEN" + else + color="$GREEN" + fi + + # avoids newlines + printf '%s' "$color" +} + +print_water() { + # formats and prints $CURRENT_WATER + + if [ "$SYMBOL" == "dynamic" ] ; then + # getting dynamic symbol + + # rounding down + symb_indx=$(echo "scale=1; indx=($CURRENT_WATER / $GOAL_AMT) * ${#DYNAMIC_SYMBOL[@]}; scale=0; indx/1" | bc) + + if [[ $symb_indx -ge ${#DYNAMIC_SYMBOL[@]} ]] ; then + # trimming + symb_indx=$((${#DYNAMIC_SYMBOL[@]}-1)) + fi + + # if colors are enabled, colorize the symbol + if [ "$COLORIZE" = true ] ; then + clr="$BLUE" + fi + printf '%s%s ' "$clr" $(echo -e "${DYNAMIC_SYMBOL[$symb_indx]}") + + elif [[ "$SYMBOL" == "static" ]] ; then + # space for double wide + + printf '%s ' "$STATIC_SYMBOL" + fi + + if [ "$COLORIZE" = true ] ; then + dflt="#[default]" + printf '%s' "$(colorize $CURRENT_WATER)" + fi + + printf '%d%s\n' $CURRENT_WATER "$dflt" + + # checks for a reminder + if [[ "$REMINDER" = true ]] ; then + # reminders enabled + reminder + fi +} + +# make dir on fresh installs +if [[ ! -d "${WATER_DIR}/archive" ]] ; then + mkdir -p "${WATER_DIR}/archive" +fi + +# get the current amount +get_current_amt + +# transform long form args +for arg in "$@"; do + shift + case "$arg" in + '--help') set -- "$@" "-h" ;; + '--colorize') set -- "$@" "-c" ;; + '--reminder') set -- "$@" "-r" ;; + '--undo') set -- "$@" "-u" ;; + '--symbol') set -- "$@" "-s" ;; + *) set -- "$@" "$arg" ;; + esac +done + +# parsing args +while getopts "hcrsSuU:" opt ; do + case "$opt" in + 'c' ) + COLORIZE=true + ;; + 's' ) + [ -n "$SYMBOL" ] && usage 1 || SYMBOL="static" + ;; + 'S' ) + [ -n "$SYMBOL" ] && usage 1 || SYMBOL="dynamic" + ;; + 'u' ) + [ -n "$UNDO" ] && usage 1 || UNDO=1 + ;; + 'U' ) + [ -n "$UNDO" ] && usage 1 || UNDO="$OPTARG" + ;; + 'r' ) + REMINDER=true + ;; + 'h' ) + usage + ;; + '?' ) + usage 1 >&2 + ;; + esac +done + +# check for undo first +if [[ ! -z "$UNDO" ]] ; then + undo_changes "$UNDO" +fi + +# get the change (if any) +shift $(($OPTIND - 1)) +WATER_CHANGE=$1 + +# update totals +if [[ ! -z "$WATER_CHANGE" ]] ; then + # prevent empty/0 updates + update_water +fi + +# return the new total +# Could make this an opt, but it seems to be a good default behavior +print_water