Skip to content

Instantly share code, notes, and snippets.

@eventualbuddha
Forked from bgreenlee/@
Created September 8, 2009 14:32
Show Gist options
  • Save eventualbuddha/182964 to your computer and use it in GitHub Desktop.
Save eventualbuddha/182964 to your computer and use it in GitHub Desktop.
#!/bin/bash
# "@Pad"
# An easy commandline time-stamped log/notepad
# Derived from 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)
# make sure the file exists
touch $DATA_FILE
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