fixed agent and timetracker
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
|
@ -0,0 +1,2 @@
|
|||||||
|
Date, Time In, Time Out, Total Time
|
||||||
|
Nov-28, 12:15, 14:30, 2:15
|
|
@ -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
|
|
@ -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
|
|
@ -0,0 +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
|
|
@ -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
|
Loading…
Reference in New Issue