Skip to content

Commit

Permalink
Add 'notes' command to show all notes, update documentation, fix a co…
Browse files Browse the repository at this point in the history
…uple minor bugs with 'finished' command, etc.
  • Loading branch information
greg-1-anderson committed Nov 9, 2012
1 parent a81e9f8 commit faab9a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For a quick start, scroll down for installation and usage.
INTRODUCTION
------------

> "Those who forget the past are doomed to retype it."
> "Those who forget the past are doomed to retype it."
> - [George Santayana][1] (paraphrased)
The history recall project helps organize your bash history.
Expand Down Expand Up @@ -73,19 +73,25 @@ This command will switch to the window containing the terminal
where 'apt-get install chromium-browser' was executed in the
last example.

### 'note' and 'recall': Write a note into history ###
### 'note', 'notes' and 'recall': Write a note into history ###

> $ note <command> // <comment>
> $ note <command> // <comment>
> $ notes
> $ recall <comment>
The 'note' command will execute the given command and will
write it, allong with the provided command and all of its
command output into the command history. The 'recall' command
will print out the saved information later.
command output into the command history. The 'notes' command
will list all of the notes taken, but only from those in
the current terminal. The 'recall' command will print out the
information saved information later. Note that 'recall' will
find notes that were entered in any terminal.

$ note ls // initial contents
historyrc
README.md
$ notes
[Thu Nov 8 15:29:52 PST 2012]$ ls // initial contents
$ recall "initial contents"
# Thu Nov 8 15:29:52 PST 2012
$ ls // initial contents
Expand All @@ -94,7 +100,7 @@ will print out the saved information later.

### 'task' and 'finished': Create a named task for history ###

> $ task <label>
> $ task <label>
> $ finished
The 'task' and 'finished' commands
Expand Down
21 changes: 18 additions & 3 deletions historyrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ function hgrep {
)
}

# Show all notes entered in the active terminal window
function notes {
OLDIFS="$IFS"
IFS=$'\n'
for l in $(grep -H "^#[0-9]\+ >>.*$*" $HISTFILE) ; do
t=$(echo $l | sed -e 's/^[^#]*#\([0-9]\+\).*/\1/')
c=$(echo $l | sed -e 's/^[^>]*>> *//')
d=$(date --date="@$t")
n=${c#*:}
sn=${n%% //*}
echo "[$d]\$ $c"
done
IFS="$OLDIFS"
}

# Focus on the terminal specified by the user.
function terminal() {
HOSTNAME=$(hostname -s)
Expand All @@ -154,7 +169,7 @@ function terminal() {
# Show the output of a command passed to 'note', or switch back to a
# task (and corresponding history file) from the past.
function recall {
l=$(cd $HOME/.history && grep "^#[0-9]\+ >>.*$*" $HISTFILE $(ls -t) | tail -n 1)
l=$(cd $HOME/.history && grep "^#[0-9]\+ >>.*$*" $(ls -t) $HISTFILE | tail -n 1)
if [ -z "$l" ]
then
echo "recall: cannot find $*: No such note or task"
Expand Down Expand Up @@ -203,7 +218,7 @@ function recall {
function histpush {
if [ -n "$1" ]
then
if [ -n "$HISTFILES" ]
if [ -z "$HISTFILES" ]
then
export HISTFILES="$HISTFILE"
else
Expand All @@ -226,8 +241,8 @@ function histpop {
else
export HISTFILES="${HISTFILES#*:}"
fi
echo "HISTFILE restored to $HISTFILE"
else
echo "histpop: HISTFILES is empty"
fi
echo "HISTFILE restored to $HISTFILE"
}

0 comments on commit faab9a7

Please sign in to comment.