From 8bdf4e726f1eaec0a1ba5a3ebc0098d12fb7555f Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Mon, 9 Jan 2023 16:50:52 -0500 Subject: [PATCH] fixed agent and timetracker --- bin/agent.sh | 20 --- bin/agent/checker.sh | 16 +++ bin/timetracker/planning | 12 ++ bin/timetracker/test.csv | 2 + bin/timetracker/timesheet.log | 34 +++++ bin/timetracker/timesheets/.session | 2 + bin/timetracker/timesheets/Jan-13-23.csv | 4 + .../timesheets/archive/Dec-08_Dec-21.csv | 8 ++ .../timesheets/archive/Dec-22_Jan-04.csv | 1 + .../timesheets/archive/Nov-24_Dec-07.csv | 17 +++ bin/timetracker/timetracker | 134 ++++++++++++++++++ bin/weather/new_weather.sh | 20 +++ bin/weather/wttr | 8 +- tmux.conf | 2 +- zshrc | 15 +- 15 files changed, 269 insertions(+), 26 deletions(-) delete mode 100755 bin/agent.sh create mode 100755 bin/agent/checker.sh create mode 100644 bin/timetracker/test.csv create mode 100644 bin/timetracker/timesheets/.session create mode 100644 bin/timetracker/timesheets/Jan-13-23.csv create mode 100644 bin/timetracker/timesheets/archive/Dec-08_Dec-21.csv create mode 100644 bin/timetracker/timesheets/archive/Dec-22_Jan-04.csv create mode 100644 bin/timetracker/timesheets/archive/Nov-24_Dec-07.csv create mode 100755 bin/timetracker/timetracker create mode 100755 bin/weather/new_weather.sh diff --git a/bin/agent.sh b/bin/agent.sh deleted file mode 100755 index ae3d698..0000000 --- a/bin/agent.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash -# makes sure agent is active and adds keys -if [ -z $SSH_AUTH_SOCK ] ; then - # agent unset - eval $(ssh-agent -s) - if [ "$(ssh-add -l)" = "The agent has no identities." ] ; then - if [ -e ~/.ssh/id_ed25519 ] ; then - ssh-add ~/.ssh/id_ed25519 - else - echo -e "No ed25519 keys found! Killing $SSH_AGENT_PID!" - eval $(ssh-agent -k) - fi - else - echo "Killing $SSH_AGENT_PID!" - eval $(ssh-agent -k) - fi -else - echo "$SSH_AUTH_SOCK" - echo "Agent already running at $SSH_AGENT_PID!" -fi diff --git a/bin/agent/checker.sh b/bin/agent/checker.sh new file mode 100755 index 0000000..d3992aa --- /dev/null +++ b/bin/agent/checker.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# checks for agent status and echos to status bar + +SOCK=$(readlink -f ~/.ssh/ssh_auth_sock) + +if [ -e $SOCK ] ; then + # agent active + clr='#[fg=color34]' # green + symb=$(echo -e '\uf00c') +else + # agent not active + clr='#[fg=color1]' # red + symb=$(echo -e '\uf00d') +fi + +printf 'Agent %s%s #[default]' $clr $symb diff --git a/bin/timetracker/planning b/bin/timetracker/planning index d872556..aac7274 100644 --- a/bin/timetracker/planning +++ b/bin/timetracker/planning @@ -19,4 +19,16 @@ clock -o to clock out Parser will have to be a bit more robust +hell with a parser, I have a better system. +Steps +1) On login echo date, start time >> to a csv +2) On logout echo end time, total uptime \n to same csv + Ending format: + Date, Time in, Time out, Total + 11/11, 11:00, 12:00, 1 +3) On every wednesday mv to a non-temp file for tracking and destroy csv +notes) + - Should be robust as hell as it will log entries into a seperate entry for the same date which can be compressed manually + - Column -s -t ',' < csv should make for easy viewing in terminal + - should be deadsimple to implement a way to track pay periods or modifyed command for entries diff --git a/bin/timetracker/test.csv b/bin/timetracker/test.csv new file mode 100644 index 0000000..e8f6305 --- /dev/null +++ b/bin/timetracker/test.csv @@ -0,0 +1,2 @@ +Date, Time In, Time Out, Total Time +Nov-28, 12:15, 14:30, 2:15 diff --git a/bin/timetracker/timesheet.log b/bin/timetracker/timesheet.log index 15311fb..7ee7dfd 100644 --- a/bin/timetracker/timesheet.log +++ b/bin/timetracker/timesheet.log @@ -69,3 +69,37 @@ O 10-27T20:23 I 11-01T13:40 O 11-01T18:13 I 11-02T13:24 +O 11-02T18:57 +I 11-03T12:59 +O 11-03T15:53 +I 11-03T17:07 +O 11-03T18:31 +I 11-04T19:07 +O 11-04T19:34 +I 11-07T15:15 +O 11-07T17:11 +I 11-08T13:58 +O 11-08T17:27 +I 11-09T17:02 +O 11-09T19:05 +I 11-10T13:19 +O 11-10T21:12 +I 11-11T16:03 +O 11-11T20:24 +I 11-14T13:39 +O 11-14T14:20 +I 11-14T14:23 +O 11-14T14:23 +I 11-15T17:06 +O 11-15T21:11 +I 11-16T15:11 +O 11-16T17:09 +I 11-17T14:34 +O 11-17T22:01 +I 11-18T15:25 +O 11-18T19:39 +I 11-20T15:34 +O 11-20T19:22 +I 11-21T15:10 +O 11-21T19:09 +I 11-28T12:20 diff --git a/bin/timetracker/timesheets/.session b/bin/timetracker/timesheets/.session new file mode 100644 index 0000000..a7762fd --- /dev/null +++ b/bin/timetracker/timesheets/.session @@ -0,0 +1,2 @@ +DATE=1673300954 +TIME_IN=1673300954 diff --git a/bin/timetracker/timesheets/Jan-13-23.csv b/bin/timetracker/timesheets/Jan-13-23.csv new file mode 100644 index 0000000..e287bbb --- /dev/null +++ b/bin/timetracker/timesheets/Jan-13-23.csv @@ -0,0 +1,4 @@ +Date, Time In, Time Out, Total Time (HH:MM) +Fri Jan-06, 2:40pm, 04:30pm, 01:50 +Mon Jan-09, 12:30pm, 04:33pm, 04:03 +Mon Jan-09, 04:34pm, 04:49pm, 00:15 diff --git a/bin/timetracker/timesheets/archive/Dec-08_Dec-21.csv b/bin/timetracker/timesheets/archive/Dec-08_Dec-21.csv new file mode 100644 index 0000000..2b2f8c3 --- /dev/null +++ b/bin/timetracker/timesheets/archive/Dec-08_Dec-21.csv @@ -0,0 +1,8 @@ +Date, Time In, Time Out, Total Time (HH:MM) +Dec-08, 10:18, 11:14, 0:56 +Dec-08, 12:47, 20:01, 7:14 +Dec-09, 11:54, 12:38, 0:44 +Dec-09, 14:56, 19:05, 4:09 +Dec-13, 13:07, 15:07, 2:00 +Dec-21, 12:31, 15:38, 3:07 +Dec-21, 15:38, 17:49, 2:11 diff --git a/bin/timetracker/timesheets/archive/Dec-22_Jan-04.csv b/bin/timetracker/timesheets/archive/Dec-22_Jan-04.csv new file mode 100644 index 0000000..0e77ed7 --- /dev/null +++ b/bin/timetracker/timesheets/archive/Dec-22_Jan-04.csv @@ -0,0 +1 @@ +Date, Time In, Time Out, Total Time (HH:MM) diff --git a/bin/timetracker/timesheets/archive/Nov-24_Dec-07.csv b/bin/timetracker/timesheets/archive/Nov-24_Dec-07.csv new file mode 100644 index 0000000..47451f7 --- /dev/null +++ b/bin/timetracker/timesheets/archive/Nov-24_Dec-07.csv @@ -0,0 +1,17 @@ +Date, Time In, Time Out, Total Time +Nov-28, 12:15, 14:30, 2:15 +Nov-28, 14:36, 15:55, 1:19 +Nov-29, 13:44, 16:30, 2:46 +Nov-29, 16:33, 16:56, 0:24 +Nov-30, 15:19, 19:23, 4:05 +Dec-01, 12:51, 18:36, 5:44 +Dec-02, 11:30, 11:32, 0:02 +Dec-02, 11:33, 12:44, 1:11 +Dec-02, 15:14, 17:45, 2:31 +Dec-05, 15:03, 18:26, 3:23 +Dec-06, 16:30, 20:51, 4:21 +Dec-06, 20:51, 20:51, 0:01 +Dec-07, 14:35, 15:44, 1:09 +Dec-07, 15:44, 15:47, 0:03 +Dec-07, 15:47, 20:17, 4:30 +Dec-07, 20:17, 20:40, 0:23 diff --git a/bin/timetracker/timetracker b/bin/timetracker/timetracker new file mode 100755 index 0000000..fd67d95 --- /dev/null +++ b/bin/timetracker/timetracker @@ -0,0 +1,134 @@ +#!/bin/bash + +# Time sheet creator +# Stores clock in and outs to timesheet named for the ending date of the ts +usage() { + cat < "${TIMESHEET_DIR}/${TIMESHEET}" +} + +getTimesheet() { + # get Timesheet to use + if [[ -z "$TIMESHEET" ]] ; then + # no timesheet, create one + createTimesheet + else + # timesheet found, check we are still in period + period_end=$(date -d "$(echo "$TIMESHEET" | awk -F . '{print $1}') + 1 days" +%s) + if [[ $(date +%s) -ge $period_end ]] ; then + # past timesheet, moving to archive and creating new + mv ${TIMESHEET_DIR}/${TIMESHEET} ${TIMESHEET_DIR}/archive + createTimesheet + fi + fi +} + +clockIn() { + # clock in by creating env file + curdate=$(date +%s) + env_details=$(printf 'DATE=%s\nTIME_IN=%s\n' "$curdate" "$curdate") + if [[ ! -f "$CURRENT_SESSION" ]] ; then + # creating session + echo "$env_details" > "$CURRENT_SESSION" + else + echo "Already Clocked In!" >&2 + exit 1 + fi +} + +clockOut() { + # clock out + if [[ -f "$CURRENT_SESSION" ]] ; then + # session exists, get info + source "$CURRENT_SESSION" + # printing to timesheet + TIME_OUT=$(date +%s) + TOTAL_TIME=$(($TIME_OUT - $TIME_IN + 3600 * 5)) + echo "$TOTAL_TIME" + # printing to timesheet + printf '%s, %s, %s, %s\n' "$(date -d @$DATE "+%a %b-%d")" "$(date -d @$TIME_IN +%I:%M%P)" "$(date -d @$TIME_OUT +%I:%M%P)" "$(date -d @$TOTAL_TIME +%H:%M)" >> ${TIMESHEET_DIR}/${TIMESHEET} + # cleaning up session + rm ${CURRENT_SESSION} + else + # no session + echo "Not clocked in!" >&2 + exit 1 + fi +} + +visualize() { + # visualize the current timesheet + column -s "," -t < ${TIMESHEET_DIR}/${TIMESHEET} +} + +totalHours() { + # tally up hours for the current timesheet + while read -r entry; do + date=$(echo "$entry" | awk -F , '{print $1}' | tr -d ",\n") + time=$(echo "$entry" | awk -F , '{print $4}' | tr -d " ,\n") + if [[ "$date" != "Date" ]] ; then + printf 'On %s worked %s\n' "$date" "$time" + hours=$(($hours + 10#$(echo "$time" | awk -F : '{print $1}'))) + mins=$(($mins + 10#$(echo "$time" | awk -F : '{print $2}'))) + fi + done < ${TIMESHEET_DIR}/${TIMESHEET} + hours=$(($hours + $mins/60)) # overflow + mins=$(($mins%60)) + printf 'Worked %d hours, %d minutes\n' "$hours" "$mins" +} + +# get the timesheet +getTimesheet + +# parse args +while [[ $# -gt 0 ]] ; do + case $1 in + -h | --help) + usage + exit 0 + ;; + -i | --in) + clockIn + ;; + -o | --out) + clockOut + ;; + -v | --visualize) + visualize + ;; + -t | --total) + totalHours + ;; + *) + echo "Error: Unrecognized" >&2 + usage + exit 1 + ;; + esac + shift +done diff --git a/bin/weather/new_weather.sh b/bin/weather/new_weather.sh new file mode 100755 index 0000000..f5b8d32 --- /dev/null +++ b/bin/weather/new_weather.sh @@ -0,0 +1,20 @@ +#!/bin/bash +#source "$HOME/.dotfiles/.priv/key" +#source "$HOME/.dotfiles/bin/weather/.env.location" +#source "$HOME/.dotfiles/bin/weather/.env.weather" +# API_KEY=$(cat "$HOME/.dotfiles/bin/weather/.priv/key") +# getting weather +CUR_TIMESTAMP=$(date +%s) +# only update weather every 30 seconds + +if [[ $CUR_TIMESTAMP -gt $EXPIRATION || -z $EXPIRATION ]] ; then + WEATHER=$(curl --silent "http://wttr.in/${LOCATION}?format=j2" | gojq -r '.current_condition[0]') + + echo $WEATHER + TEMP=$(echo $WEATHER | gojq -r '.temp_F') + HUMIDITY=$(echo $WEATHER | gojq -r '.humidity') + ICON=$(echo $WEATHER | gojq -r '.weatherCode') + EXPIRATION=$(($CUR_TIMESTAMP+30)) + echo "TEMP: $TEMP HUMIDITY: $HUMIDITY ICON: $ICON" + #printf 'TEMP=%s\nHUMIDITY=%s\nICON=%s\nEXPIRATION=%s\n' "$TEMP" "$HUMIDITY" "$ICON" "$EXPIRATION" >"$HOME/.dotfiles/bin/weather/.env.weather" +fi diff --git a/bin/weather/wttr b/bin/weather/wttr index 85faec8..792b232 100755 --- a/bin/weather/wttr +++ b/bin/weather/wttr @@ -32,7 +32,7 @@ get_tod() { get_wttr() { # gets weather for $LOCATION and stores it into file with timestamp - url="https://wttr.in/$LOCATION?0&format=j2" #json stuff need to fix temp + url="https://wttr.in/$LOCATION?format=j2" #json stuff need to fix temp query="{\ temp: .current_condition[0].temp_F,\ humidity: .current_condition[0].humidity,\ @@ -53,6 +53,11 @@ set_location() { display_location() { # updates location to display to $disp_loc + if [[ "$1" == "" ]] ; then + # no arg given, print current loc + echo + fi + shift echo "TODO" } @@ -89,7 +94,6 @@ while [[ "$1" != "" ]]; do ;; -d | --disploc) shift - disp_loc="$1" display_location ;; -u | --unit) diff --git a/tmux.conf b/tmux.conf index 6f171e9..502d452 100644 --- a/tmux.conf +++ b/tmux.conf @@ -25,7 +25,7 @@ set -g clock-mode-colour white # status config set -g status-interval 10 set -g status-style "bg=black, fg=brightWhite" -set -g status-right "#(~/.dotfiles/bin/docker.sh) | #(~/.tmux/plugins/tmux-mem-cpu-load/tmux-mem-cpu-load -p -i 1 -a 1) | #(~/.dotfiles/bin/up.sh) | %a %l:%M " +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) | #(~/.dotfiles/bin/water/water.sh) |" set -g status-left-length 100 diff --git a/zshrc b/zshrc index e8e4b58..6b1d084 100644 --- a/zshrc +++ b/zshrc @@ -1,3 +1,13 @@ +# makes sure agent is active and adds keys +if [ ! -S ~/.ssh/ssh_auth_sock ] ; then + # setting agent + eval `ssh-agent` + ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock +fi + +export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock +ssh-add -l > /dev/null || ssh-add ~/.ssh/id_ed25519 + # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. # Initialization code that may require console input (password prompts, [y/n] # confirmations, etc.) must go above this block; everything else may go below. @@ -135,9 +145,6 @@ alias bbrm='ssh-keygen -f "/home/kdeppe/.ssh/known_hosts" -R "192.168.7.2"' [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh export PATH=$PATH:$HOME/.local/bin -# adding agent startup alias -alias agent="source $HOME/.dotfiles/bin/agent.sh" - # home and clear alias c="cd && clear" @@ -153,3 +160,5 @@ alias water="$HOME/.dotfiles/bin/water/water.sh" [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh export FZF_DEFAULT_OPTS='--layout=reverse --border --height=40%' alias bat="batcat" +alias tt="$HOME/.dotfiles/bin/timetracker/timetracker" +