Skip to content

Instantly share code, notes, and snippets.

@bgreenlee
Last active July 21, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bgreenlee/178317 to your computer and use it in GitHub Desktop.
Save bgreenlee/178317 to your computer and use it in GitHub Desktop.
#!/bin/bash
# "@Pad"
# An easy commandline time-stamped log/notepad
# Derived from https://web.archive.org/web/20120118122636/http://blog.rubybestpractices.com/posts/jamesbritt/James_will_be_right_back_after_these_interruptions.html
#
# Usage:
# @ something or other - log the timestamped message "something or other"
# @ . - open the @ scratchpad with a new timestamp and
# no message with your default editor
# @ - - log a timestamped message read from stdin
# @ - open the @ scratchpad in your default editor
#
DATA_FILE="$HOME/.at"
EDIT_METHOD=prepend # or append
TS=$(date)
prepend() {
echo -e "--- $TS:\n$MSG\n\n" >> "/tmp/at-$$"
cat $DATA_FILE >> "/tmp/at-$$"
mv "/tmp/at-$$" $DATA_FILE
}
append() {
echo -e "--- $TS:\n$MSG\n\n" >> $DATA_FILE
}
if [ ! -n "$1" ]
then
$EDITOR $DATA_FILE
elif [ "." = "$1" ]
then
$EDIT_METHOD
$EDITOR $DATA_FILE
elif [ "-" = "$1" ]
then
MSG=$(cat)
$EDIT_METHOD
else
MSG="$*"
$EDIT_METHOD
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment