fixed agent and timetracker

nvim
KeeganForelight 2 years ago
parent 08dabc3852
commit 8bdf4e726f

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

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

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

@ -0,0 +1,2 @@
Date, Time In, Time Out, Total Time
Nov-28, 12:15, 14:30, 2:15
1 Date Time In Time Out Total Time
2 Nov-28 12:15 14:30 2:15

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

@ -0,0 +1,2 @@
DATE=1673300954
TIME_IN=1673300954

@ -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
1 Date Time In Time Out Total Time (HH:MM)
2 Fri Jan-06 2:40pm 04:30pm 01:50
3 Mon Jan-09 12:30pm 04:33pm 04:03
4 Mon Jan-09 04:34pm 04:49pm 00:15

@ -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
1 Date Time In Time Out Total Time (HH:MM)
2 Dec-08 10:18 11:14 0:56
3 Dec-08 12:47 20:01 7:14
4 Dec-09 11:54 12:38 0:44
5 Dec-09 14:56 19:05 4:09
6 Dec-13 13:07 15:07 2:00
7 Dec-21 12:31 15:38 3:07
8 Dec-21 15:38 17:49 2:11

@ -0,0 +1 @@
Date, Time In, Time Out, Total Time (HH:MM)
1 Date Time In Time Out Total Time (HH:MM)

@ -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
1 Date Time In Time Out Total Time
2 Nov-28 12:15 14:30 2:15
3 Nov-28 14:36 15:55 1:19
4 Nov-29 13:44 16:30 2:46
5 Nov-29 16:33 16:56 0:24
6 Nov-30 15:19 19:23 4:05
7 Dec-01 12:51 18:36 5:44
8 Dec-02 11:30 11:32 0:02
9 Dec-02 11:33 12:44 1:11
10 Dec-02 15:14 17:45 2:31
11 Dec-05 15:03 18:26 3:23
12 Dec-06 16:30 20:51 4:21
13 Dec-06 20:51 20:51 0:01
14 Dec-07 14:35 15:44 1:09
15 Dec-07 15:44 15:47 0:03
16 Dec-07 15:47 20:17 4:30
17 Dec-07 20:17 20:40 0:23

@ -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 <<EOF
Usage: timetracker [-i|o|t|v|h]
Tracks timesheets automatically
Options:
-i, --in clock in
-o, --out clock out
-t, --total totals the hours worked
-v, --visualize prints the timesheet
-h, --help display this message
EOF
}
# dir for timesheets
TIMESHEET_DIR="$HOME/.dotfiles/bin/timetracker/timesheets"
# existing
TIMESHEET=$(ls "$HOME/.dotfiles/bin/timetracker/timesheets" | grep ".csv")
# generated by clock in
CURRENT_SESSION="${TIMESHEET_DIR}/.session"
createTimesheet() {
payperiods=$((($(date +%s) - $(date -d "Dec-30-22" +%s)) / (14*24*3600)))
period_end=$(date -d "Dec-30-22 + $((($payperiods + 1) * 14)) days" +%b-%d-%y)
TIMESHEET=$(printf "%s.csv" "$period_end")
# create timesheet
echo "Date, Time In, Time Out, Total Time (HH:MM)" > "${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

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

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

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

15
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"

Loading…
Cancel
Save