Brian took my cd bash function hack, made a whole bunch of improvements, and created a Sourceforge project for it:
Category Archives: bash
My latest bash toy: a “cd” replacement
I just made this little cd function that is a drop-in replacement for the builtin bash cd command. The idea was to make it really easy and productive to navigate around to commonly used directories in bash without forcing someone to learn new habits like in the case of pushd, popd, and a bunch of other stuff like cdargs and gotodir.
cd () { if [ "$*" = "" -o "$*" = "-" ]; then builtin cd $*; return; fi; realpath=$(realpath $*); if [ -z "$realpath" -o ! -d "$realpath" ]; then realpath=$(realpath ~/recent_dirs/$* 2> /dev/null); fi; if builtin cd $realpath; then if [ "$*" = "" -o "$*" = "-" ]; then return; fi; ln -s $realpath ~/recent_dirs 2>/dev/null; else :; fi }
UNIX Power Tools
Here’s an online copy of the classic book.
Using braces in bash
Another great bash tip from Deadman.org | Advancing in the Bash shell:
$ cp filename filename-old $ cp filename-old filename
These seem fairly straightforward, what could possibly make them more efficient? Let’s look at an example:
$ cp filename{,-old} $ cp filename{-old,} $ cp filename{-v1,-v2}
Nice little bash function for determining the meaning of error codes
Here’s a cool idea from Deadman.org | Advancing in the Bash shell:
Restarting fetchmail automatically
I use fetchmail (in daemon mode) to pull down mail from a POP server to my local box, where I then serve it up with the Courier IMAP server. Problem I had was when my box rebooted, fetchmail could not automatically restart because it needs a password to proceed (I don’t want to store the password in my .fetchmailrc). My solution was to add the following to my .bashrc:
if [ -x "/usr/local/bin/fetchmail" ]; then if ! killall -0 fetchmail 2> /dev/null; then echo "killall -0 fetchmail failed - starting fetchmail..." fetchmail fi fi
Making Bash Do Your Work for You
There are a few interesting ideas here and the author has perhaps the same idea that I had – of building a standardized bashrc environment that is powerful and easily customizable.