If you spend a lot of time at the command line, then comment is a useful utility in your CLI toolbox. It appends text in a hidden file in your current directory, and also in your home directory. The text entries can be anything you like, though I tend to use it for remembering things like:
- server details
- syntax for one-off mounts, tunnels
- syntax of utilities used in clever ways (ssh, netcat, sed awk one-liners, etc)
- phone numbers
- etc.
Usage:
Create a comment:
comment put string
Get comments containing searchstring in current directory
comment get [-t] [searchstring]
Get comments containing searchstring globally
comment getall [-t] [searchstring]
I use a couple of aliases to abbreviate the syntax further. These live in your ~/.bash_profile.
alias cget='comment get' alias cgeta='comment getall' alias cput='comment put' alias cputa='comment putall'
Examples:
Describe current directory:
cput This directory contains photos of our holiday on the beach
Put comments into a project directory:
cput Started project Newproj on 14 Feb 2007 cput Project manager John Smith extension 1234 cput Development box orpheus user/password cput 'CVSROOT=:pserver:guest:guest@192.168.0.9:2401/cvs/newproject'
Get all comments for the current directory
cget
Get comments that contain "John" in the current directory
cget John
Get comments from any directory that contain "John"
cgeta John
Use the -t option to also display when the comments where added:
cgeta -t orpheus
Notes:
comment is a simple shell script under 1K. When a comment is put, it appends the text to a file called .comment in the current directory and also in the users home directory. The entry is prefixed with a timestamp that can optionally be displayed with the -t option.
Use single quotes around your comments to avoid shell expansion on characters such as $, :, | and "
Here's the script. Save it in your PATH i.e. /usr/local/bin/comment.
#!/bin/bash
COMMENTFILE=".comment"
if [ "$1" == "get" ]; then
if [ "$2" == "-t" ]; then
grep -i "$3" $COMMENTFILE 2>/dev/null
else
grep -i "$2" $COMMENTFILE 2>/dev/null | cut -b 20-
fi
exit 0
fi
if [ "$1" == "getall" ]; then
if [ "$2" == "-t" ]; then
grep -i "$3" "$HOME/$COMMENTFILE" 2>/dev/null
else
grep -i "$2" "$HOME/$COMMENTFILE" 2>/dev/null | cut -b 20-
fi
exit 0
fi
if [ "$1" == "put" ] || [ "$1" == "putall" ]; then
DATE=`date +'[%d-%m-%Y %H:%M]'`
CWD=`pwd`
PARAMS=$*
ENTRY="$DATE ${PARAMS#* }"
if [ "$1" == "put" ]; then
echo $ENTRY >> $COMMENTFILE
fi
if [ "$CWD" != "$HOME" ] || [ "$1" == "putall" ]; then
echo $ENTRY >> $HOME/$COMMENTFILE
fi
exit 0
fi
echo
echo "comment utility Aidan Hannigan July 2004"
echo "Usage: comment put string"
echo " get | getall [-t] searchstring"
echo
exit 1
Remember to add the aliases to your ~/.bash_profile.