The new shell prompt I created for myself is working wonderfully. However, the Subversion prompt was only effective when I was in the root directory of a Subversion project. Once I drilled down into sub-directories the prompt, which depended upon the presence of a .svn directory, lost all Subversion information.
After much fiddling around last night I came up with a simple change that allows the Subversion information to be displayed, regardless of where I am in the directory hierarchy under the root directory of a Subversion controlled project.
Here’s the code:
The testsvn variable on line 17 is set to the result of running an svn info and then counting the lines of output via wc -l. By shunting the output of the command into /dev/null it’s quiet, i.e., no output leaks out into the shell. And the 2>&1 bit captures the error message produced when svn info is run in a non-Subversion controlled directory. So, if I’m in a Subversion project the line count (wc -l) will be about 12. If I’m not in a Subversion project, there will be a single line counted – the error produced.
The if statement on line 18 determines if there count is greater than 1 and if so, builds the Subversion portion of the prompt.
Everything else stays the same as I had it before. It works beautifully.