<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non-random ramble &#187; bash</title>
	<atom:link href="http://jimbarritt.com/non-random/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Current git branch and git autocompletion in bash</title>
		<link>http://jimbarritt.com/non-random/2011/01/26/current-git-branch-and-git-autocompletion-in-bash/</link>
		<comments>http://jimbarritt.com/non-random/2011/01/26/current-git-branch-and-git-autocompletion-in-bash/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 11:46:09 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=766</guid>
		<description><![CDATA[First put the following script somewhere, like ~/git_completion.sh and chmod +x it. Then add this line to your ~/.bash_profile: Finally, if you want to pretty up your prompt as above, then add this: You can also install git from http://code.google.com/p/git-osx-installer/ (Thanks Jon) Or on ubuntu install a package called &#8220;git-completion&#8221; (Thanks Juan)]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2011/01/git_branch_prompt.png" rel="lightbox[766]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2011/01/git_branch_prompt.png" alt="" title="git_branch_prompt" width="301" height="59" class="aligncenter size-full wp-image-767" /></a></p>
<p>First put the following <a href="http://git.kernel.org/?p=git/git.git;a=blob_plain;f=contrib/completion/git-completion.bash;hb=HEAD">script</a> somewhere, like <code>~/git_completion.sh</code> and <code>chmod +x</code> it.</p>
<p>Then add this line to your <code>~/.bash_profile</code>:</p>
<pre name='code' class='java:nogutter:nocontrols'>
. ~/git_completion.sh
</pre>
<p>Finally, if you want to pretty up your prompt as above, then add this:</p>
<pre name='code' class='java:nogutter:nocontrols'>
export PS1=&#8217;\h:\W \[\e[1;32m\]$(__git_ps1 &#8220;[%s]&#8220;)\[\e[0m\] > &#8216;
</pre>
<p>You can also install git from <a href="http://code.google.com/p/git-osx-installer/">http://code.google.com/p/git-osx-installer/</a> (Thanks Jon)</p>
<p>Or on ubuntu install a package called &#8220;git-completion&#8221; (Thanks Juan)</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2011%2F01%2F26%2Fcurrent-git-branch-and-git-autocompletion-in-bash%2F&amp;title=Current%20git%20branch%20and%20git%20autocompletion%20in%20bash"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2011/01/26/current-git-branch-and-git-autocompletion-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A proper shell in windows</title>
		<link>http://jimbarritt.com/non-random/2010/10/27/a-proper-shell-in-windows/</link>
		<comments>http://jimbarritt.com/non-random/2010/10/27/a-proper-shell-in-windows/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 11:05:12 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=687</guid>
		<description><![CDATA[Thanks to a posting on our mailing list I am trying out mintty, a tty shell emulator for windows which runs on top of cygwin. So far so good, feels like the real deal. You can install it by running &#8220;setup.exe&#8221; in the cygwin folder and install it from the package list under &#8220;shells&#8221;. I [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/10/bash-win.bmp" rel="lightbox[687]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/10/bash-win.bmp" alt="" title="bash-win" width="600"/></a></p>
<p>Thanks to a posting on our mailing list I am trying out <a href="">mintty</a>, a tty shell emulator for windows which runs on top of cygwin.</p>
<p>So far so good, feels like the real deal.</p>
<p>You can install it by running &#8220;setup.exe&#8221; in the cygwin folder and install it from the package list under &#8220;shells&#8221;.</p>
<p>I added a couple of lines to my <code>~/.bash_profile</code></p>
<pre>
export PS1="\W> "
alias clear='echo -e "\033c"'
</pre>
<p>As there didn&#8217;t seem to be a default &#8220;clear&#8221; command to clear the terminal. Got the trick from <a href="http://www.cygwin.com/ml/cygwin/2009-03/msg00495.html">here</a>. Also good is <a href="http://code.google.com/p/mintty/wiki/Tips">The tips and tricks page</a></p>
<p>To get a nice &#8220;Bash prompt here&#8221; you can install the <code>chere</code> package from the cygwin setup (same as above) and then run:</p>
<pre name='code' class='java:nogutter:nocontrols'>
chere -i -c -t mintty -s bash
</pre>
<p>One oddity I&#8217;ve found is that if you execute a batch file which uses CMD.exe, <code>CTRL+C</code> doesn&#8217;t seem to work. It breaks out of the program but then output still appears! So you need to run .sh files in there.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F10%2F27%2Fa-proper-shell-in-windows%2F&amp;title=A%20proper%20shell%20in%20windows"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/10/27/a-proper-shell-in-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Colorised Build Success Message</title>
		<link>http://jimbarritt.com/non-random/2010/04/25/colorised-build-success-message/</link>
		<comments>http://jimbarritt.com/non-random/2010/04/25/colorised-build-success-message/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 18:05:16 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[linux commands]]></category>
		<category><![CDATA[os x]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=450</guid>
		<description><![CDATA[My current project has a neat trick we picked up where the build has a red or green banner at the end when you run it locally to give good feedback about the build status. I&#8217;m not sure who originated it, but thanks! I just had to tweak it a bit to get it working [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2010/04/Build-Result.gif" rel="lightbox[450]"><img src="http://jimbarritt.com/non-random/wp-content/uploads/2010/04/Build-Result.gif" alt="" title="Build Result" width="681" height="248" class="aligncenter size-full wp-image-451" /></a></p>
<p>My current project has a neat trick we picked up where the build has a red or green banner at the end when you run it locally to give good feedback about the build status. I&#8217;m not sure who originated it, but thanks!</p>
<p>I just had to tweak it a bit to get it working on OS X so I thought I would document the trick here.</p>
<p><code>run.sh - OS X</code></p>
<pre name='code' class='java:nogutter:nocontrols'>
CMD=&#8221;./tools/ant/bin/ant -lib ./asl/lib/jdepend $@&#8221;
echo &#8220;Running command [${CMD}] &#8230;&#8221;
$CMD
if [ "$?" -ne 0 ]; then
    echo -e &#8220;`tput setab 1`  `cat ./ci/failed.txt` `tput setab 0`&#8221;
    exit 1
else
    echo -e &#8220;`tput setab 2`  `cat ./ci/passed.txt`  `tput setab 0`&#8221;
    exit 0
fi
</pre>
<p>This assumes you have two supporting files <code>./ci/passed.txt</code> and <code>./ci/failed.txt</code> which contain the message. You can generate messages to your taste <a href="http://www.network-science.de/ascii/">here</a>. </p>
<p>I have provided the files in this example here :</p>
<p><a href='http://jimbarritt.com/non-random/wp-content/uploads/2010/04/passed.txt'>passed.txt</a></p>
<p><a href='http://jimbarritt.com/non-random/wp-content/uploads/2010/04/failed.txt'>failed.txt</a></p>
<p>It has also been run under Ubuntu where the following works (it didnt work on OS X which is why I adapted it), but the <code>tput</code> should also work on Ubuntu. I&#8217;ve not explicitly tested this one!</p>
<pre name='code' class='java:nogutter:nocontrols'>
if [ "$?" -ne 0 ]; then
    echo -e &#8220;\E[30;41m"
    cat ./ci/failed.txt
    echo -e "\E[0m"
    exit 1
else
    echo -e "\E[30;42m"
    cat ./ci/passed.txt
    echo -e "\E[0m"
    exit 0
fi
</pre>
<p>Under windows you can actually make the entire screen of the terminal change color:</p>
<p><code>run.bat - WINDOWS</code></p>
<pre name='code' class='java:nogutter:nocontrols'>
CALL tools\ant\bin\ant %*
IF ERRORLEVEL 1 GOTO RedBuild
IF ERRORLEVEL 0 GOTO GreenBuild
:RedBuild
color 4F
GOTO TheEnd
:GreenBuild
color 2F
:TheEnd
PAUSE
color 07
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F04%2F25%2Fcolorised-build-success-message%2F&amp;title=Colorised%20Build%20Success%20Message"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/04/25/colorised-build-success-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check if an command was successful in bash</title>
		<link>http://jimbarritt.com/non-random/2009/09/03/check-if-an-command-was-successful-in-bash/</link>
		<comments>http://jimbarritt.com/non-random/2009/09/03/check-if-an-command-was-successful-in-bash/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 17:21:03 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux commands]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2009/09/03/check-if-an-command-was-successful-in-bash/</guid>
		<description><![CDATA[When scripting gigantic build scripts with bash, its important that if anything fails you halt the script. Heres how: function checkResult() { RESULT=$1 if [ $RESULT -ne 0 ] ; then echo echo "!!!!!!!!!!! Build Failed !!!!!!!!!!!!!!!!!" echo exit $RESULT fi } You call it like this: ./someCommandOrScript.sh checkResult $?]]></description>
			<content:encoded><![CDATA[<p>When scripting gigantic build scripts with bash, its important that if anything fails you halt the script.</p>
<p>Heres how:</p>
<pre>
function checkResult() {
	RESULT=$1
	if [ $RESULT -ne 0 ] ; then
		echo
		echo "!!!!!!!!!!!  Build Failed !!!!!!!!!!!!!!!!!"
		echo
		exit $RESULT
	fi
}
</pre>
<p>You call it like this:</p>
<pre>
./someCommandOrScript.sh
checkResult $?
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F09%2F03%2Fcheck-if-an-command-was-successful-in-bash%2F&amp;title=Check%20if%20an%20command%20was%20successful%20in%20bash"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/09/03/check-if-an-command-was-successful-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Edit GMail messages using Vim</title>
		<link>http://jimbarritt.com/non-random/2008/11/20/edit-gmail-messages-using-vim/</link>
		<comments>http://jimbarritt.com/non-random/2008/11/20/edit-gmail-messages-using-vim/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 13:45:29 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/11/20/edit-gmail-messages-using-vim/</guid>
		<description><![CDATA[Ok, why would you want to do this ? Because you can. 1) Install this add-on which allows you to edit text areas in firefox using an external editor: https://addons.mozilla.org/en-US/firefox/addon/4125 2) Install VIM ftp://ftp.vim.org/pub/vim/pc/gvim72.exe 3) Setup the plugin to use vim (addOns->its all text addon->options) 4) make sure gmail is using &#8220;plain text&#8221; as editing [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, why would you want to do this ?</p>
<p>Because you can.</p>
<p>1) Install this add-on which allows you to edit text areas in firefox using an external editor:</p>
<p><a href='https://addons.mozilla.org/en-US/firefox/addon/4125'>https://addons.mozilla.org/en-US/firefox/addon/4125</a></p>
<p>2) Install VIM</p>
<p><a href='ftp://ftp.vim.org/pub/vim/pc/gvim72.exe'>ftp://ftp.vim.org/pub/vim/pc/gvim72.exe</a></p>
<p>3) Setup the plugin to use vim (addOns->its all text addon->options)</p>
<p>4) make sure gmail is using &#8220;plain text&#8221; as editing &#8211; otherwise its not a text area, but some mad iframe.</p>
<p>6) Happy Days!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2008%2F11%2F20%2Fedit-gmail-messages-using-vim%2F&amp;title=Edit%20GMail%20messages%20using%20Vim"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/11/20/edit-gmail-messages-using-vim/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Read in a list of files and loop over them in bash</title>
		<link>http://jimbarritt.com/non-random/2008/11/08/read-in-a-list-of-files-and-loop-over-them-in-bash/</link>
		<comments>http://jimbarritt.com/non-random/2008/11/08/read-in-a-list-of-files-and-loop-over-them-in-bash/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 12:10:09 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2008/11/08/read-in-a-list-of-files-and-loop-over-them-in-bash/</guid>
		<description><![CDATA[Needed to do this and after a bit of looking around (Bash scripting) came up with this: #!/bin/bash FILE_LIST_SOURCE=listoffiles.txt DEFAULT_FILE="some.default.file" [ -f $FILE_LIST_SOURCE ] &#038;&#038; LIST_OF_FILES=$(cat $FILE_LIST_SOURCE) LIST_OF_FILES=${LIST_OF_FILES:-$DEFAULT_FILE} #echo -e "\\nLIST_OF_FILES:\\n$LIST_OF_FILES" echo "List of files:" for i in $LIST_OF_FILES; do echo $i done]]></description>
			<content:encoded><![CDATA[<p>Needed to do this and after a bit of looking around (<a href='http://www.google.co.uk/url?sa=t&#038;source=web&#038;ct=res&#038;cd=1&#038;url=http%3A%2F%2Fwww.cv.nrao.edu%2F~jmalone%2Ftalks%2Fbash.pdf&#038;ei=XoMVScOHCZjy1gbz1dDsCg&#038;usg=AFQjCNFEf2kRUTBYObiCtfj8HtJWd4YyyQ&#038;sig2=ZQthS3itRMWZ7UENOwwC1w'>Bash scripting</a>) came up with this:</p>
<blockquote>
<pre>
<code>
#!/bin/bash

FILE_LIST_SOURCE=listoffiles.txt
DEFAULT_FILE="some.default.file"

[ -f $FILE_LIST_SOURCE ] &#038;&#038; LIST_OF_FILES=$(cat $FILE_LIST_SOURCE)

LIST_OF_FILES=${LIST_OF_FILES:-$DEFAULT_FILE}

#echo -e "\\nLIST_OF_FILES:\\n$LIST_OF_FILES"

echo "List of files:"
for i in $LIST_OF_FILES; do
    echo $i
done

</code>
</pre>
<p></blockqoute></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2008%2F11%2F08%2Fread-in-a-list-of-files-and-loop-over-them-in-bash%2F&amp;title=Read%20in%20a%20list%20of%20files%20and%20loop%20over%20them%20in%20bash"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2008/11/08/read-in-a-list-of-files-and-loop-over-them-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python!</title>
		<link>http://jimbarritt.com/non-random/2007/12/04/python/</link>
		<comments>http://jimbarritt.com/non-random/2007/12/04/python/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 13:36:21 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2007/12/04/python/</guid>
		<description><![CDATA[Wanted to find all files which contained a specific string and then extract a part of the line we were interested in. First the GREP: grep -R --include=*.vm * > results.txt then run this python script: import re for line in open('editablecomponents.txt'): match = re.search(r'#editableComponent\("(.*?)"', line) if match: print match.group(1) + "Display.vm"]]></description>
			<content:encoded><![CDATA[<p>Wanted to find all files which contained a specific string and then extract a part of the line we were interested in.</p>
<p>First the GREP:</p>
<pre>
grep -R --include=*.vm <searchstring> * > results.txt
</pre>
<p>then run this python script:</p>
<pre>
import re
for line in open('editablecomponents.txt'):
	match = re.search(r'#editableComponent\("(.*?)"', line)
	if match:
		print match.group(1) + "Display.vm"
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2007%2F12%2F04%2Fpython%2F&amp;title=Python%21"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2007/12/04/python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sweet Search And Highlight Command</title>
		<link>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</link>
		<comments>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 17:40:49 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[linux commands]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</guid>
		<description><![CDATA[Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files: grep -r Hoffman */*.tex &#124; less +/Hoffman Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression. The &#8220;less&#8221; command has a very [...]]]></description>
			<content:encoded><![CDATA[<p>Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:</p>
<p><code>grep -r Hoffman */*.tex | less +/Hoffman</code></p>
<p>Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression.</p>
<p>The &#8220;less&#8221; command has a very convenient argument &#8220;+&#8221; which allows you to pass a search term in and will automatically highlight it for you.</p>
<p>The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.</p>
<p>sweet.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2007%2F07%2F15%2Fsweet-search-and-highlight-command%2F&amp;title=Sweet%20Search%20And%20Highlight%20Command"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

