<?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>blog.lundscape.com &#187; Bash</title>
	<atom:link href="http://blog.lundscape.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.lundscape.com</link>
	<description>The Linux Journey</description>
	<lastBuildDate>Thu, 15 Apr 2010 20:06:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>(Even More) Advanced Bash Completion</title>
		<link>http://blog.lundscape.com/2009/11/even-more-advanced-bash-completion/</link>
		<comments>http://blog.lundscape.com/2009/11/even-more-advanced-bash-completion/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 00:57:40 +0000</pubDate>
		<dc:creator>Zachary Lund</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Bash Completion]]></category>

		<guid isPermaLink="false">http://blog.lundscape.com/?p=242</guid>
		<description><![CDATA[In my previous post, I described how to set up tab completion for many common commands using these Bash completion files. This works well for established commands, but it doesn&#8217;t work so well for commands that I have written myself.
I use a command called &#8220;hc12-console&#8221; to connect to 68HC12 microcontrollers over a serial port. The [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="/2009/02/advanced-bash-completion/">post</a>, I described how to set up tab completion for many common commands using these <a href="http://www.caliban.org/bash/index.shtml">Bash completion files</a>. This works well for established commands, but it doesn&#8217;t work so well for commands that I have written myself.</p>
<p>I use a command called &#8220;hc12-console&#8221; to connect to 68HC12 microcontrollers over a serial port. The command takes two arguments: the name of a microcontroller to connect to and a file to load. I only have two microcontrollers called &#8220;dragon1&#8243; and &#8220;dragon2&#8243;. Therefore, I want to be able to tab complete the first argument to one of those values only. The second argument should be the name of a file that ends in &#8220;.load&#8221;.</p>
<p>I do this with a function that checks the argument number and then completes it based on a specified list or by limiting the types of files that will be listed.</p>
<pre>_hc12console ()
{
	local cur

	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}

	# First argument completes with either dragon1 or dragon2
	if [[ $COMP_CWORD -eq 1 ]] ; then
		COMPREPLY=( $( compgen -W "dragon1 dragon2" -- $cur ) )
		return 0
	fi

	# Second argument completes with only files matching *.load
	if [[ $COMP_CWORD -eq 2 ]] ; then
		COMPREPLY=( $( compgen -f -X '!*.load' -- $cur ) )
		return 0
	fi

	# All other arguments will not auto-complete
	return 0
}
complete -F _hc12console hc12-console</pre>
<p>I added the script above to a file that my bashrc sources. It associates the function with the shell command, and then instead of manually typing out:</p>
<pre>hc12-console dragon1 file.load &lt;enter&gt;</pre>
<p>I can type:</p>
<pre>hc12&lt;tab&gt; &lt;tab&gt;1 &lt;tab&gt; &lt;enter&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.lundscape.com/2009/11/even-more-advanced-bash-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OWA Sync on Ubuntu</title>
		<link>http://blog.lundscape.com/2009/04/owa-sync-on-ubuntu/</link>
		<comments>http://blog.lundscape.com/2009/04/owa-sync-on-ubuntu/#comments</comments>
		<pubDate>Mon, 06 Apr 2009 22:56:38 +0000</pubDate>
		<dc:creator>Zachary Lund</dc:creator>
				<category><![CDATA[Mutt]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Cron]]></category>
		<category><![CDATA[lbdb]]></category>
		<category><![CDATA[OWA Sync]]></category>
		<category><![CDATA[PHP iCalendar]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.lundscape.com/?p=98</guid>
		<description><![CDATA[Update: OWA Sync V0.6 (the current version) is not compatible with Exchange 2007. When I set this up, I was connecting to Exchange 2003.
I use OWA Sync to get all of my calendar information onto my Ubuntu desktop. I recently rediscovered the Little Brother&#8217;s Database and decided to make my OWA contacts available in Mutt [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: OWA Sync V0.6 (the current version) is not compatible with Exchange 2007. When I set this up, I was connecting to Exchange 2003.</strong></p>
<p>I use <a href="http://www.cobb.uk.net/OWA/owasync.html">OWA Sync</a> to get all of my calendar information onto my Ubuntu desktop. I recently rediscovered the <a href="http://www.spinnaker.de/lbdb/">Little Brother&#8217;s Database</a> and decided to make my OWA contacts available in <a href="http://www.mutt.org/">Mutt</a> on my Ubuntu desktop, too. (I used lbdb to make my contacts in Apple Address Book available to Mutt when I was still using Mac OS X as my primary operating system.)</p>
<p>The OWA Sync website has a decent explanation of creating a owaSyncrc file. After I created that, I wrote a script that runs as a cron job.</p>
<pre>#! /bin/bash

export PATH=$PATH:/usr/local/bin/

/usr/local/bin/owaSync.kit -update

cat $HOME/.owa/Calendar/*.ics > $HOME/.calendar.ics
cat $HOME/.owa/Contacts/*.vcf > $HOME/.contacts.vcf</pre>
<p>After a bit of trial and error, I figured out that &#8220;/usr/local/bin/&#8221; needed to be in the path for the owaSync.kit script to run. After the synchronization is complete, I then concatenate all of the calendar events into a single file and all of the contact cards into a single file. I now have a single calendar file that I can use with <a href="http://phpicalendar.net/">PHP iCalendar</a> and a single contacts file that I can use with lbdb. It requires a fairly simple rc file that looks something like this:</p>
<pre>METHODS="$METHODS m_vcf m_muttalias"

VCF_FILES="$HOME/.contacts.vcf"
MUTTALIAS_FILES="$HOME/.mutt/aliases"</pre>
<p>I add &#8220;m_vcf&#8221; and &#8220;m_muttaliases&#8221; to the &#8220;METHODS&#8221; and then I specify the locations of my OWA contacts and my Mutt aliases. Now when I launch Mutt, I can query for addresses that I downloaded from OWA.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lundscape.com/2009/04/owa-sync-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bad Bash Sourcing</title>
		<link>http://blog.lundscape.com/2009/03/bad-bash-sourcing/</link>
		<comments>http://blog.lundscape.com/2009/03/bad-bash-sourcing/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 23:32:18 +0000</pubDate>
		<dc:creator>Zachary Lund</dc:creator>
				<category><![CDATA[Secure Shell]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://blog.lundscape.com/?p=53</guid>
		<description><![CDATA[A while back I switched such that my .bash_profile sources my .bashrc instead of the reverse. Based on a few sources, this seems to be the preferred approach. Today I decided to push those files to a few servers that haven&#8217;t been updated lately. I transferred my .bash_profile and then my .bashrc:
zac@dakara:~$ scp ~/.environment/bash/bash_profile lansky:~/.bash_profile
bash_profile [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I switched such that my .bash_profile sources my .bashrc instead of the reverse. Based on a few sources, this seems to be the preferred approach. Today I decided to push those files to a few servers that haven&#8217;t been updated lately. I transferred my .bash_profile and then my .bashrc:</p>
<pre>zac@dakara:~$ scp ~/.environment/bash/bash_profile lansky:~/.bash_profile
bash_profile                                  100%  120     0.1KB/s   00:00
zac@dakara:~$ scp ~/.environment/bash/bashrc lansky:~/.bashrc
lost connection</pre>
<p>What happened? My .bash_profile sources my .bashrc, but since I hadn&#8217;t yet replaced the .bashrc, it still sources my .bash_profile. That means infinite loop and that I am an idiot. SSH, rsync, and scp are all broken. There is no way to remove or replace either of those files without another account. I guess it&#8217;s time to open a support ticket at DreamHost.</p>
<p>The moral of the story is to always be careful how you source those files. I usually try to keep an SSH session open on the remote machine when I modify those files in case I break login, but this time I didn&#8217;t. A few searches didn&#8217;t reveal any solutions. I&#8217;d love to know if someone has a way of resolving this without access to another account on the remote machine.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lundscape.com/2009/03/bad-bash-sourcing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Advanced Bash Completion</title>
		<link>http://blog.lundscape.com/2009/02/advanced-bash-completion/</link>
		<comments>http://blog.lundscape.com/2009/02/advanced-bash-completion/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 22:42:50 +0000</pubDate>
		<dc:creator>Zachary Lund</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[Bash Completion]]></category>
		<category><![CDATA[bashrc]]></category>
		<category><![CDATA[Fedora]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.lundscape.com/?p=50</guid>
		<description><![CDATA[Ubuntu has a lot of advanced bash completion features that simplify using the shell. For example, when using the ssh command, I can tab complete server names based on my host file and my ssh config file. It turns out that most of this is accomplished with one bash_completion script. This page has a lot [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu has a lot of advanced bash completion features that simplify using the shell. For example, when using the ssh command, I can tab complete server names based on my host file and my ssh config file. It turns out that most of this is accomplished with one bash_completion script. This <a href="http://www.caliban.org/bash/index.shtml">page</a> has a lot of useful information about the Bash shell and also the very useful script. I&#8217;ve found that when I use Fedora in the Xinu lab, I am left typing a lot of this stuff myself. Since I use the same bashrc file on both Dakara and my lab machine (Kastria), I didn&#8217;t want to always resource the file so I added this to my bashrc:</p>
<pre># Source global definitions
[ -f /etc/bashrc ]      &#038;&#038; source /etc/bashrc
[ -f /etc/bash.bashrc ] &#038;&#038; source /etc/bash.bashrc
# enable programmable completion features
if [ -z "$BASH_COMPLETION" \
    -a -r ~/.configuration/bash/bash_completion.caliban ]; then
    BASH_COMPLETION=~/.configuration/bash/bash_completion.caliban
    source $BASH_COMPLETION
fi</pre>
<p>First, I source the global definitions, Ubuntu uses /etc/bashrc, and Fedora uses /etc/bash.bashrc. After that, if the bash_completion script was already sourced, $BASH_COMPLETION will be set. I check to see if it is zero length (-z) and then source my own copy of it if it is. Now I have advanced bash completion on both Ubuntu and Fedora.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lundscape.com/2009/02/advanced-bash-completion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
