diff --git a/.gitignore b/.gitignore index 67c01e0..c6c0d97 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ tmux/resurrect tmux/plugins !tmux/plugins/tpm -bin/water/waterintake +bin/water/archive +bin/water/*.csv bin/weather/.env* *.swp bin/startup/*.json diff --git a/bin/bluebikes/bb b/bin/bluebikes/bb index 0519b20..d97b949 100755 --- a/bin/bluebikes/bb +++ b/bin/bluebikes/bb @@ -3,18 +3,17 @@ #set -e usage() { - # basic usage statement cat < "$ALIAS_FILE" - printf 'Updated alias to %s\n' "$ALIAS" - + # printing change + if [[ -z "$ALIAS" ]] ; then + printf 'Removing alias\n' + else + printf 'Updated alias to %s\n' "$ALIAS" + fi } @@ -181,46 +184,55 @@ print_status() { BIKES=$(colorize $BIKES) DOCKS=$(colorize $DOCKS) fi - printf '%s  %s  %s%s' $BIKES $DOCKS "$DEFAULT" "$STATION_NAME" + printf '%s  %s  %s%s\n' $BIKES $DOCKS "$DEFAULT" "$STATION_NAME" } # always check/clean status check_update -if [[ $# -eq 0 ]] ; then - # no args passed, default to print - print_status -fi +# change long form +for arg in "$@"; do + shift + case "$arg" in + '--help') set -- "$@" "-h" ;; + '--search') set -- "$@" "-s" ;; + '--force') set -- "$@" "-f" ;; + '--rename') set -- "$@" "-r" ;; + '--colorize') set -- "$@" "-c" ;; + *) set -- "$@" "$arg" ;; + esac +done -while [[ $# -gt 0 ]] ; do - # loop over args if present - case $1 in - -h | --help) +# parsing args +while getopts "hsfcr" opt ; do + case "$opt" in + 'h' ) usage exit 0 ;; - -s | --search) + 's' ) update_station ;; - -f | --force) + 'f' ) UPDATE=true - output_status ;; - -r | --rename) - shift - ALIAS="$1" - set_station_alias - ;; - -c | --colorize) + 'c' ) COLORIZE=true - print_status ;; - *) - echo "Error: bb" >&2 + 'r' ) + nextopt=${!OPTIND} + if [[ -n "$nextopt" && "$nextopt" != -* ]] ; then + ALIAS="$nextopt" + fi + set_station_alias + ;; + '?' ) usage exit 1 ;; esac - shift # shift over the args before loop done + +# finish by printing +print_status diff --git a/bin/water/water.sh b/bin/water/water.sh index 82fb99d..3701f46 100755 --- a/bin/water/water.sh +++ b/bin/water/water.sh @@ -1,75 +1,160 @@ #!/usr/bin/env bash + # this script enables water tracking in tmux status bar via a simple command -# tracking resets everyday at midnight local time -# to inc/dec water consumed just call water XX where XX is any integer amount of ounces to change your total by -# it is really only ever exepected to use negatives to fix mistakes -# the file writes like a log where the last entry is total consumed and the difference between two consecutive entries is the water consumed in that entry -# i.e -# 10:00:01 0 starts off at 0 in a new day -# 10:14:21 16 drank 16 ounces of water so it goes up -# 11:10:21 48 drank 32 more ounces of water so new total is 48 - -# setting up vars -declare waterfile -declare -i water_intake -declare output - -curtime=$(timedatectl | grep Local | cut -d '-' -f 2-) # getting date to MM-DD HH:MM:SS TMZ -date=$(echo $curtime | awk '{print $1}') # for filename -time=$(echo $curtime | awk '{print $2}') # for timestamp - -waterfile="$HOME/.dotfiles/bin/water/waterintake/$date" # makes it easy to reset on each new day - -mkdir -p "$HOME/.dotfiles/bin/water/waterintake" - -# update func -update() { - printf '%s: %s\n' "$time" "$water_intake" >> "$waterfile" +usage() { + cat < "$WATERFILE" + printf '%s, 0, 0\n' "$TIME" >> "$WATERFILE" else - water_intake=0 + # waterfile exists + CURRENT_WATER=$(cat $WATERFILE | tail -n 1 | awk '{print $3}') fi } -reset_water_intake() { - water_intake=0 - update +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" } -colorize_water_intake() { +undo_change() { + # removes the last entry up to the first + + if [[ $(wc -l < "$WATERFILE") -gt 2 ]] ; then + # removing last entry + lastentry=$(cat "$WATERFILE" | tail -n 1) + ts=$(echo "$lastentry" | awk -F , '{print $1}') + amt=$(echo "$lastentry" | awk -F , '{print $2}') + prompt=$(printf 'Are you sure you want to remove the %d fl oz added at %s?(y/n)\n' $amt "$ts") + read -p "$prompt" -n 1 -r + + if [[ $REPLY =~ ^[Yy]$ ]] ; then + # remove + sed -i '$d' "$WATERFILE" + fi + echo "" + get_current_amt + else + echo "No changes to undo!" + fi +} + +colorize() { # sends water intake level through conditionals to be colorized - dflt='#[default]' - if [[ $water_intake -lt 32 ]] ; then + + if [[ $1 -lt 32 ]] ; then color='#[fg=color1]' # red - elif [[ $water_intake -lt 64 ]] ; then + elif [[ $1 -lt 64 ]] ; then color='#[fg=color3]' # bad yellow - elif [[ $water_intake -lt 96 ]] ; then + elif [[ $1 -lt 96 ]] ; then color='#[fg=color226]' # pale yellow - elif [[ $water_intake -lt 128 ]] ; then + elif [[ $1 -lt 128 ]] ; then color='#[fg=color10]' # light green else color='#[fg=color21]' # blue fi - output="${color}\uf6aa ${water_intake}${dflt}" + + printf '%s' "$color" } -# checking for/creating missing files -if [[ ! -f $waterfile ]] ; then - # water intake file doesn't exist - reset_water_intake -fi +print_water() { + # prints total + if [ "$COLORIZE" = true ] ; then + dflt="#[default]" + printf '%s' "$(colorize $CURRENT_WATER)" + fi + + if [ "$SYMBOL" = true ] ; then + printf '%s ' $(echo -e '\uf6aa') + fi -# evaluating arguements -get_water_intake -if [[ -z $1 ]] ; then - colorize_water_intake # optional color codes based on total consumption - echo -e $output # no args is basic echo -else - water_intake="$((water_intake + $1))" # provided value to inc/dec water intake by - update + printf '%d%s\n' $CURRENT_WATER "$dflt" +} + +# handle long forms +for arg in "$@"; do + shift + case "$arg" in + '--help') set -- "$@" "-h" ;; + '--colorize') set -- "$@" "-c" ;; + '--reset') set -- "$@" "-r" ;; + '--undo') set -- "$@" "-u" ;; + '--symbol') set -- "$@" "-s" ;; + *) set -- "$@" "$arg" ;; + esac +done + +get_current_amt + +# parsing args +while getopts "hcrsu" opt ; do + case "$opt" in + 'h' ) + usage + exit 0 + ;; + 'c' ) + COLORIZE=true + ;; + 's' ) + SYMBOL=true + ;; + 'u' ) + undo_change + ;; + 'r' ) + reset_water + ;; + '?' ) + usage + exit 1 + ;; + esac +done + +shift $(($OPTIND - 1)) + +WATER_CHANGE=$1 +if [[ ! -z "$WATER_CHANGE" ]] ; then + # prevent empty/0 updates + update_water fi + +print_water diff --git a/tmux.conf b/tmux.conf index da372a5..879eefd 100644 --- a/tmux.conf +++ b/tmux.conf @@ -27,7 +27,7 @@ set -g status-interval 10 set -g status-style "bg=black, fg=brightWhite" set -g status-right "#(~/.dotfiles/bin/docker.sh)| #(~/.dotfiles/bin/agent/checker.sh) | #(~/.tmux/plugins/tmux-mem-cpu-load/tmux-mem-cpu-load -p -i 1 -a 1) | #(~/.dotfiles/bin/up.sh) | %A, %b %d %l:%M %P " set -g status-right-length 100 -set -g status-left "#(~/.dotfiles/bin/weather/weather) | #(~/.dotfiles/bin/bluebikes/bb -c) | #(~/.dotfiles/bin/water/water.sh) |" +set -g status-left "#(~/.dotfiles/bin/weather/weather) | #(~/.dotfiles/bin/bluebikes/bb -c) | #(~/.dotfiles/bin/water/water.sh -sc) |" set -g status-left-length 100 # tmux auto start diff --git a/tmux/plugins/tpm b/tmux/plugins/tpm deleted file mode 160000 index b699a7e..0000000 --- a/tmux/plugins/tpm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b699a7e01c253ffb7818b02d62bce24190ec1019