Skip to content

Instantly share code, notes, and snippets.

@jcamenisch
Forked from kohlhofer/logwork
Created August 6, 2014 12:56
Show Gist options
  • Save jcamenisch/5347770d460fb7a675fa to your computer and use it in GitHub Desktop.
Save jcamenisch/5347770d460fb7a675fa to your computer and use it in GitHub Desktop.
# !/bin/bash
# mapped to lw (as in log work) this script simply appends any parameters as a new line in worklog.txt in ~/
# no parameters will print the last 10 messages
# -o opens the worklog in VIM and immediately jumps to the last line.
# -l gets the tux to tell you the last message.
# -u deletes the last message (u as in undo).
# -uv also posts the message to idone this.
worklog='worklog.txt'
if [ $# -eq 0 ]; then
# if no arguments are supplied just print the last 10 lines of the log
tail $HOME/$worklog
exit
else
# Iterate over arguments and set flags for subsequent actions to be carried out in a specific order
for i; do
if [[ $i == '-o' ]]; then
open_work_log=true
elif [[ $i == '-l' ]]; then
show_last_line=true
elif [[ $i == '-u' ]]; then
delete_last_line=true
elif [[ $i == '-uv' ]]; then
idonethis_uv=true
else
# everything else is considered the message
message+=$i' '
fi
done
if [[ $delete_last_line = true ]]; then
printf "DELETED: "
tail -1 $HOME/$worklog
sed '$d' < $HOME/$worklog > $HOME/tempworklog.txt; mv $HOME/tempworklog.txt $HOME/$worklog
fi
if [[ $show_last_line = true ]]; then
if hash cowsay 2>/dev/null; then
tail -1 $HOME/$worklog | cowsay -f tux
else
tail -1 $HOME/$worklog
fi
fi
if [[ ! -z $message ]]; then
if [[ $idonethis_uv = true ]]; then
curl -s -X POST -H "Authorization: Token [token goes here]" -H "Content-Type: application/json" -d '{"team":"https://idonethis.com/api/v0.0/teams/uservoice-VntF/","raw_text":"'"$message"'"}' https://idonethis.com/api/v0.0/dones/ >/dev/null 2>&1
message+='#uservoice'
fi
now=$(date +"%m-%d-%Y %A %H:%M ")
echo $now "|" $message >> $HOME/$worklog
if hash cowsay 2>/dev/null; then
cowsay $message logged to $HOME/$worklog
else
echo $message logged to $HOME/$worklog
fi
fi
if [[ $open_work_log = true ]]; then
vim + $HOME/$worklog
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment