-
-
Save eventualbuddha/182964 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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