-
-
Save rogeruiz/64c1704699797f3dc262 to your computer and use it in GitHub Desktop.
A tmux wrapper with clocker integration to better track my time spent working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
export PATH=$PATH:/usr/local/bin | |
# check if we're already in a tmux session | |
[ "$TMUX" == "" ] || exit 0 | |
PS3="Please choose your session: " | |
sessions=($(tmux list-sessions -F "#S") "New Session" "zsh") | |
# A wrapper function around clocker, lovingly named punch_clock. | |
# @param $1 clocker sub-command | |
# @param $2 -t Type parameter for clocker | |
function punch_clock { | |
if [[ -n $1 && ($(which clocker) != "clocker not found") ]]; | |
then | |
clocker "$1" -t "$2" | |
fi | |
} | |
echo "+ ------------------ +" | |
echo " Available Sessions " | |
echo "+ ------------------ +" | |
# Let's start by punching in. | |
# | |
select session in "${sessions[@]}" | |
do | |
case $session in | |
"New Session") | |
read -p "Enter new session name: " new_session | |
selected_session="$new_session" | |
punch_clock "start" "$new_session" | |
tmux new-session -s "$new_session" | |
break | |
;; | |
"zsh") | |
zsh --login | |
break | |
;; | |
*) | |
selected_session="$session" | |
punch_clock "start" $session | |
tmux attach-session -t $session | |
break | |
;; | |
esac | |
done | |
# Don't forget to punch out | |
# | |
if [[ "$?" == 0 && -n $selected_session ]]; then | |
punch_clock "stop" $selected_session | |
echo | |
punch_clock "list" $selected_session | |
fi | |
echo "+ ------------------- +" | |
echo " You look nice today " | |
echo "+ ------------------- +" | |
# Wait for it | |
# | |
sleep 3 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment