Fork Of

Revisions

gist: 182964 Download_button fork
public
Public Clone URL: git://gist.github.com/182964.git
Embed All Files: show embed
@ #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/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