Getting around your projects with BASH

I just realised this might be useful to people who like me, as soon as they open a shell window (I use Ubuntu) they then have to remember where each project is. I am a pretty organised developer, I have cron and s3cmd backing up to S3 every night, I use GIT and / or subversion, Emacs for *everything* and all in all life is good. Except... I can never remember where the hell anything is especially on a Friday. Yes, I wrote this on a Friday!

In the end I used bash (a very useful thing, might really catch on one day) to create in my home folder a whole bunch of files called goXXX, for example :-

#!/bin/bash
cd /var/www/project-name/$*

That's a small one, sometimes the paths can be much longer as I use meaningful names based on the client so it could be spelled wrong a few times before I get it right. This way of course, BASH takes all the guessing out of it as all I have to remember is . goXYZ or whatever. Note that there is a dot which is bash shorthand notation for the source command. When you execute a bash script it cannot change the directory permanently; once its over you are back where you ran the script from, therefore to change the folder/path for real use the source command... it is as though you had typed the contents of the file from the keyboard, hence it will change directory.

The dodge...

The dodge is putting the $* on the end of the directory name in the script. $* means 'everything from the command line except the program name as you typed it', the concatenation of the remaining arguments. So what!? Well what if you wanted to move into a specific module folder at the same time, here's how ...

$ . goXYZ sites/all/modules/eric
$ pwd
$ /var/www/project-name/sites/all/modules/eric

I love BASH, I used to write Solaris applications with nothing but that fifteen years ago, well, it might have been zsh or sh but you get it!

Content Tags: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <pre> <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Full HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.