These are some helpful little scripts I wrote for my ~/bin directory, for when I'm working at the console. Please note that you use these scripts at your own risk and that they are in the public domain. To use them, copy the text into a file in the 'bin' folder of your home directory, and type chmod u+x filename.
Please don't be fooled by the small size and simplicity of these scripts - they're actually very useful...
"I" for ideas
A short script to archive and group ideas. I find that keeping the command name minimal - "i" - is helpful since it is typed quite often. I also find that my brain tends to place ideas under the same tag consistently, so it's easy to find things again later. If you prefer GUI programs, be sure to check out MindTags which works on a similar principle. This script was a lifesaver during my PhD.
#!/bin/bash # "i" by Graeme Bell - http://graemebell.net # Usage and parameters: # Type 'i' followed by a tag. Tag-groups can precede tags. # e.g. 'i java', 'i shares intc', 'i user dave jobs' FOLDER=$HOME/.ideas mkdir $FOLDER 2>/dev/null # You can delete this line after the first run. if [ -z $1 ] ; then echo "Usage: i tag or i [tag-group]* tag"; exit; fi while [ ! -z $2 ] ; do mkdir $FOLDER/$1-folder 2>/dev/null FOLDER="$FOLDER/$1-folder" shift done nano +5000 $FOLDER/$1
"L" for logging
A simple script to keep a record of your daily activities. It can double as a schedule by giving it a parameter. The script is tiny and straightforward, but the habit of using it can be very helpful...
#!/bin/bash # "l" by Graeme Bell - http://graemebell.net # Usage and parameters: # Type 'l' to log for today, or e.g. 'l 08-08-11' to log for 8th Aug 2011. mkdir ~/.log 2>/dev/null # You can delete this line after the first run. if [ -z $1 ] ; then TODAY="$HOME/.log/"`date "+%d-%m-%y"` ; #UK style. else TODAY="$HOME/.log/$1"; fi if [ ! -e $TODAY ] ; then echo -n "Log file for: " > $TODAY date >> $TODAY echo >> $TODAY fi nano +5000 $TODAY echo "---" >> $TODAY
"B" for Backup
"It's Not Version Control, But I Like It!".
B is a very simple backup script that requires no configuration, and helps keep you in the habit of making organised backups as you work by requiring no configuration or effort whatsoever.
There are many free version control systems available to help you keep track of the development of your software over time: cvs, svn, Hg, git and bazaar. Of these, my favourite is Hg (because it's a DVCS, because MacHG has a beautiful interface, and because I can grok hg more easily than bazaar or git).
But there are days when I really can't be bothered with version control - when I just need a few organised backups as I work. For example, when I'm coding up a quick one-off script to test an idea for a few minutes, or working on a problem where the directory structure matters as much as the file contents (a weakness of Hg), or when I'm working on something other than code (documents, images, etc.).
For times like these, I have "B" always sitting ready to organise a tidy backup - no setup needed!
#!/bin/bash # "b" by Graeme Bell - http://graemebell.net # Usage and parameters: # Type "b", and it makes a recursive backup of your current directory into a folder called bak. # Backups will be automatically named "1", then "2", "3" and so on incrementally. mkdir bak 2>/dev/null backup=$(($(ls -t bak | sort -n | tail -n 1)+1)) if [[ $backup == 20 ]] ; then echo -e "\nALERT: 20 backups? Time to setup a VCS!\n"; fi echo -n "Creating new backup number $backup .... " mkdir -p bak/$backup cp -rf $(ls ./ | grep -v bak) bak/$backup echo "completed!" echo