<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://townx.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>townx - Rake command completion in the Bash shell - Comments</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell</link>
 <description>Comments for &quot;Rake command completion in the Bash shell&quot;</description>
 <language>en</language>
<item>
 <title>Thanks, I know about Pastie.</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comment-38213</link>
 <description>&lt;p&gt;Thanks, I know about Pastie. Can it be used as a repository and then accessed via an &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;?&lt;/p&gt;</description>
 <pubDate>Mon, 16 Jun 2008 15:30:45 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 38213 at http://townx.org</guid>
</item>
<item>
 <title>Try Pastie for sharing code</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comment-38142</link>
 <description>&lt;p&gt;&lt;a href=&quot;http://pastie.caboo.se/&quot;&gt;Pastie&lt;/a&gt; is great for sharing code. It formats, and highlights.&lt;/p&gt;</description>
 <pubDate>Tue, 20 May 2008 10:08:43 -0500</pubDate>
 <dc:creator>Michael Hale</dc:creator>
 <guid isPermaLink="false">comment 38142 at http://townx.org</guid>
</item>
<item>
 <title>Thanks for the tips. Useful.</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comment-34388</link>
 <description>&lt;p&gt;Thanks for the tips. Useful.&lt;/p&gt;</description>
 <pubDate>Thu, 17 Apr 2008 18:20:19 -0500</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">comment 34388 at http://townx.org</guid>
</item>
<item>
 <title>Some of the text has been</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comment-26537</link>
 <description>&lt;p&gt;Some of the text has been eaten above... Essentially the if condition to check if there is a rake file before installing completions on entering a folder is the important part. Also removing the completions on exit is handled by the &quot;else&quot; and the -r.&lt;/p&gt;

&lt;p&gt;I&#039;ve also included a completion for capistrano that I use.&lt;/p&gt;

&lt;p&gt;I&#039;ll paste again below in the hopes that it makes it this time.&lt;/p&gt;

&lt;p&gt;  cd () { &lt;br /&gt;
		command cd &quot;$@&quot;; &lt;br /&gt;
		# Add enhanced completion for a folder containing a rails app and remove it when we leave the folder&lt;br /&gt;
		if [ -f ./Rakefile ]; then		&lt;br /&gt;
			complete -W &quot;SAME AS &lt;span class=&quot;caps&quot;&gt;YOURS &lt;/span&gt;above&quot; rake&lt;br /&gt;
		else&lt;br /&gt;
			complete -r rake&lt;br /&gt;
		fi&lt;br /&gt;
		if [ -f ./Capfile ]; then		&lt;br /&gt;
			complete -W &quot;$(cap -T | grep &#039;#&#039; | awk &#039;NR != 1 {print $2}&#039;)&quot; cap&lt;br /&gt;
		else&lt;br /&gt;
			complete -r cap&lt;br /&gt;
		fi		&lt;br /&gt;
		stripe ; &lt;br /&gt;
  }&lt;/p&gt;</description>
 <pubDate>Sat, 22 Mar 2008 11:34:29 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 26537 at http://townx.org</guid>
</item>
<item>
 <title>Enhance to the above</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comment-26535</link>
 <description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;Adding the following syntax to your bashrc will dynamically add and remove the completions as appropriate.&lt;/p&gt;

&lt;p&gt;  cd () { &lt;br /&gt;
		command cd &quot;$@&quot;; &lt;br /&gt;
		# Add enhanced completion for a folder containing a rails app and remove it when we leave the folder&lt;br /&gt;
		if [ -f ./Rakefile ]; then		&lt;br /&gt;
			complete -W &quot;$(rake -T | awk &#039;NR &lt;img src=&quot;=&quot; alt=&quot;&quot; /&gt;= 1 {print $2}&#039;)&quot; cap&lt;br /&gt;
		else&lt;br /&gt;
			complete -r cap&lt;br /&gt;
		fi		&lt;br /&gt;
  }&lt;/p&gt;

&lt;p&gt;Hope this helps you out.&lt;/p&gt;</description>
 <pubDate>Sat, 22 Mar 2008 11:30:21 -0500</pubDate>
 <dc:creator>Guest</dc:creator>
 <guid isPermaLink="false">comment 26535 at http://townx.org</guid>
</item>
<item>
 <title>Rake command completion in the Bash shell</title>
 <link>http://townx.org/blog/elliot/rake-command-completion-bash-shell</link>
 <description>&lt;p&gt;I find the command completion tools in a shell indispensable (i.e. when you press Tab to complete a path or show you the options for a command - this works for svn, for example). Plus I get quite annoyed when they don&#039;t work for a command I&#039;m using. I found out today it is pretty easy to add your own completions using the &lt;code&gt;complete&lt;/code&gt; command (at least, when using Bash under Linux).&lt;/p&gt;

&lt;p&gt;So here, for example, is how to get Rake to auto-complete with the names of the tasks in your Rake file:&lt;/p&gt;



&lt;pre&gt;
complete -W &amp;quot;$(rake -T | awk &#039;NR != 1 {print $2}&#039;)&amp;quot; rake
&lt;/pre&gt;



&lt;p&gt;It&#039;s not flawless, but it&#039;s a damn sight better than having to do &lt;code&gt;rake -T&lt;/code&gt; and scrolling through a wordy list. NB this only works if you run the &lt;code&gt;complete&lt;/code&gt; command in a directory where you have a Rake file to start with. There&#039;s probably some switch to &lt;code&gt;complete&lt;/code&gt; which dynamically generates the completions when you try to use them: I need to investigate.&lt;/p&gt;

&lt;p&gt;You could also try something like this to put up a list of names of hosts in your /etc/hosts file when you&#039;re using &lt;span class=&quot;caps&quot;&gt;SSH&lt;/span&gt;:&lt;/p&gt;



&lt;pre&gt;
complete -W &amp;quot;$(cat /etc/hosts | awk &#039;$1 != &amp;quot;#&amp;quot; {print $2}&#039;)&amp;quot; ssh
&lt;/pre&gt;



&lt;p&gt;You can just add these to your Bash profile to get them activated when starting a new shell, I imagine.&lt;/p&gt;</description>
 <comments>http://townx.org/blog/elliot/rake-command-completion-bash-shell#comments</comments>
 <category domain="http://townx.org/tech">tech</category>
 <category domain="http://townx.org/howtos">howtos</category>
 <pubDate>Tue, 20 Nov 2007 08:36:17 -0600</pubDate>
 <dc:creator>elliot</dc:creator>
 <guid isPermaLink="false">687 at http://townx.org</guid>
</item>
</channel>
</rss>
