<?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>The Daily Build &#187; zsh</title>
	<atom:link href="http://blog.bstpierre.org/tag/zsh/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bstpierre.org</link>
	<description>Software Development, version 3.0</description>
	<lastBuildDate>Wed, 26 May 2010 16:08:50 +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>zsh history expansion</title>
		<link>http://blog.bstpierre.org/zsh-history-expansion</link>
		<comments>http://blog.bstpierre.org/zsh-history-expansion#comments</comments>
		<pubDate>Mon, 15 Feb 2010 13:59:52 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[zsh]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=269</guid>
		<description><![CDATA[Exploring zsh features made me want to figure out some of the history-editing wizardry. (Bash has similar history tricks, I just never bothered to dive too deeply into them.)
If you want to experiment with history expansion a bit, you can echo the result instead of executing it:
hostname:~/dir% ls /some/long/path/to/file_0.1-2_i386.changes
hostname:~/dir% echo !?ls?:s/-2/-3/
echo ls /some/long/path/to/file_0.1-3_i386.changes
In this case, [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/zsh-zle-words' rel='bookmark' title='Permanent Link: Make the zsh zle handle &#8220;words&#8221; correctly'>Make the zsh zle handle &#8220;words&#8221; correctly</a> <small> Snippet from my .zshrc: #...</small></li><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Exploring zsh features made me want to figure out some of the history-editing wizardry. (Bash has similar history tricks, I just never bothered to dive too deeply into them.)</p>
<p>If you want to experiment with history expansion a bit, you can echo the result instead of executing it:</p>
<pre>hostname:~/dir% ls /some/long/path/to/file_0.1-2_i386.changes
hostname:~/dir% echo !?ls?:s/-2/-3/
echo ls /some/long/path/to/file_0.1-3_i386.changes</pre>
<p>In this case, what I wanted to do is repeat a long command that referenced a file with a version number in it &#8212; but I wanted to use a different version number (-3 instead of the previously given version -2).</p>
<p>History expansion uses &#8220;!&#8221; (&#8220;bang&#8221;, or exclamation point). If you want to select the previous command to expand based on a string match, &#8220;!?str&#8221; will find the previous command that contains &#8220;str&#8221;. If you want to substitute some part of that previous command, put another question mark on the end, add a colon, and use the the &#8220;s&#8221; modifier. In the example above, &#8220;!?ls?&#8221; means expand the previous command containing &#8220;ls&#8221;. The &#8220;:s/-2/-3/&#8221; means modify that expanded command to replace the occurrence of &#8220;-2&#8243; with &#8220;-3&#8243;.</p>
<p>(Of course, to actually get all of that figured out and working, I had to iterate the sequence of commands above about a dozen times.)</p>
<p>Leave a comment with your favorite zsh history trick. Thanks!</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/open-an-ssh-tunnel-in-four-seconds-or-less' rel='bookmark' title='Permanent Link: Open an SSH Tunnel in Four Seconds or Less'>Open an SSH Tunnel in Four Seconds or Less</a> <small>As I mentioned in a previous...</small></li><li><a href='http://blog.bstpierre.org/zsh-zle-words' rel='bookmark' title='Permanent Link: Make the zsh zle handle &#8220;words&#8221; correctly'>Make the zsh zle handle &#8220;words&#8221; correctly</a> <small> Snippet from my .zshrc: #...</small></li><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/zsh-history-expansion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set Your zsh Prompt</title>
		<link>http://blog.bstpierre.org/zsh-prompt</link>
		<comments>http://blog.bstpierre.org/zsh-prompt#comments</comments>
		<pubDate>Mon, 01 Feb 2010 16:05:13 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[zsh]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=264</guid>
		<description><![CDATA[Since the beginning of time, all the cool kids have had really cool shell prompts. It's a great place to display helpful information, and zsh has features that let you have a flexible, informative, unobtrusive prompt.


Related posts:<ol><li><a href='http://blog.bstpierre.org/moving-to-zsh' rel='bookmark' title='Permanent Link: Moving to zsh'>Moving to zsh</a> <small> To get started: sudo aptitude...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Since the beginning of time, all the cool kids have had really cool shell prompts. It&#8217;s a great place to display helpful information, and zsh has features that let you have a flexible, informative, unobtrusive prompt.</p>
<p>Set your prompt by setting <code>$PROMPT</code>. If you do <code>PROMPT='foo '</code>, the shell will give you a <code>foo </code> prompt for every command. Not terribly useful but you get the point.</p>
<p>There are a bunch of codes you can use in the value of PROMPT to get useful output. For example, %m gives the name of the machine you&#8217;re running on, and %~ gives the name of the current working directory. For a list of all the codes, check the &#8220;<a title="man page for zshmisc" href="http://www.manpagez.com/man/1/zshmisc/">zshmisc</a>&#8221; man page under the section &#8220;SIMPLE PROMPT ESCAPES&#8221;. Note that there are codes for boldface, underline, and colors here too.</p>
<p>The drawback to having all kinds of information in your prompt is that you limit the length of commands that you can enter without scrolling. Scrolling stinks because the command is harder to read. Enter the &#8220;right prompt&#8221;. Set RPS1 to contain the lengthy part of your prompt, and it will be displayed on the right margin of your terminal. Then when commands get long and encroach on the right prompt, it will conveniently disappear. Read Quentin&#8217;s comment on <a href="http://who-t.blogspot.com/2009/08/case-for-zsh.html?showComment=1253567443515#c3597222540288946216">this zsh post</a>.</p>
<p>Here&#8217;s a gotcha with RPS1 and fancy prompt formatting: gnome-terminal does not behave well when these are set. I&#8217;m trying out alternatives to see which will be better.</p>
<p>Lastly, a trick I picked up from <a href="http://justinchouinard.com/">Justin</a>. Zsh provides hooks that you can use to do things before and after a command runs. Just define the functions preexec and precmd. This example sets the title of the xterm while a command is running:</p>
<pre>function title() {
    # escape '%' chars in $1, make nonprintables visible
    local a=${(V)1//\%/\%\%}

    # Truncate command, and join lines.
    a=$(print -Pn "%40&gt;...&gt;$a" | tr -d "\n")

    case $TERM in
        screen*)
            print -Pn "\e]2;$a @ $2\a" # plain xterm title
            print -Pn "\ek$a\e\\"      # screen title (in ^A")
            print -Pn "\e_$2   \e\\"   # screen location
            ;;
        xterm*)
            print -Pn "\e]2;$a @ $2\a" # plain xterm title
            ;;
    esac
}

# precmd is called just before the prompt is printed
function precmd() {
    title "zsh" "%m:%55&lt;...&lt;%~"
}

# preexec is called just before any command line is executed
function preexec() {
    title "$1" "%m:%35&lt;...&lt;%~"
}</pre>
<p><b>Update</b>: Set variable a to local in function title above as suggested in the comment below.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/moving-to-zsh' rel='bookmark' title='Permanent Link: Moving to zsh'>Moving to zsh</a> <small> To get started: sudo aptitude...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li><li><a href='http://blog.bstpierre.org/using-pythons-ctypes-to-make-system-calls' rel='bookmark' title='Permanent Link: Using Python&#8217;s ctypes to Call Into C Libraries'>Using Python&#8217;s ctypes to Call Into C Libraries</a> <small>The ctypes module makes loading and...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/zsh-prompt/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Make the zsh zle handle &#8220;words&#8221; correctly</title>
		<link>http://blog.bstpierre.org/zsh-zle-words</link>
		<comments>http://blog.bstpierre.org/zsh-zle-words#comments</comments>
		<pubDate>Wed, 27 Jan 2010 15:40:18 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[zsh]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=272</guid>
		<description><![CDATA[Snippet from my .zshrc:
# This controls what the line editor considers a word. By default it
# includes '/', which makes it so that when I M-del (attempting to erase
# a directory in a path), I erase the whole path. Annoying.
# WORDCHARS='*?_-.[]~=/&#38;;!#$%^(){}&#60;&#62;' # (default)
WORDCHARS='*?_-.[]~=&#38;;!#$%^(){}&#60;&#62;'

After living with this for a while, I realize that I should probably [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/moving-to-zsh' rel='bookmark' title='Permanent Link: Moving to zsh'>Moving to zsh</a> <small> To get started: sudo aptitude...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Snippet from my .zshrc:</p>
<p><code># This controls what the line editor considers a word. By default it<br />
# includes '/', which makes it so that when I M-del (attempting to erase<br />
# a directory in a path), I erase the whole path. Annoying.<br />
# WORDCHARS='*?_-.[]~=/&amp;;!#$%^(){}&lt;&gt;' # (default)<br />
WORDCHARS='*?_-.[]~=&amp;;!#$%^(){}&lt;&gt;'<br />
</code></p>
<p>After living with this for a while, I realize that I should probably remove the underscore too, since that&#8217;s what I was used to in bash.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/moving-to-zsh' rel='bookmark' title='Permanent Link: Moving to zsh'>Moving to zsh</a> <small> To get started: sudo aptitude...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/zsh-zle-words/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving to zsh</title>
		<link>http://blog.bstpierre.org/moving-to-zsh</link>
		<comments>http://blog.bstpierre.org/moving-to-zsh#comments</comments>
		<pubDate>Mon, 25 Jan 2010 15:20:27 +0000</pubDate>
		<dc:creator>Brian St. Pierre</dc:creator>
				<category><![CDATA[zsh]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.bstpierre.org/?p=258</guid>
		<description><![CDATA[To get started:

sudo aptitude install zsh
chsh /bin/zsh

That&#8217;s pretty simple.
Of course, you&#8217;re not running zsh yet&#8230; either logout and log back in or just run zsh at the prompt. You&#8217;ll get a series of prompts to configure a .zshrc. It only takes a few minutes, so run through the options and save the file.
Next up: setting [...]


Related posts:<ol><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li><li><a href='http://blog.bstpierre.org/zsh-zle-words' rel='bookmark' title='Permanent Link: Make the zsh zle handle &#8220;words&#8221; correctly'>Make the zsh zle handle &#8220;words&#8221; correctly</a> <small> Snippet from my .zshrc: #...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li></ol>]]></description>
			<content:encoded><![CDATA[<p>To get started:</p>
<ol>
<li>sudo aptitude install zsh</li>
<li>chsh /bin/zsh</li>
</ol>
<p>That&#8217;s pretty simple.</p>
<p>Of course, you&#8217;re not <em>running</em> zsh yet&#8230; either logout and log back in or just run zsh at the prompt. You&#8217;ll get a series of prompts to configure a .zshrc. It only takes a few minutes, so run through the options and save the file.</p>
<p>Next up: setting a custom prompt.</p>


<p>Related posts:<ol><li><a href='http://blog.bstpierre.org/zsh-prompt' rel='bookmark' title='Permanent Link: Set Your zsh Prompt'>Set Your zsh Prompt</a> <small>Since the beginning of time, all...</small></li><li><a href='http://blog.bstpierre.org/zsh-zle-words' rel='bookmark' title='Permanent Link: Make the zsh zle handle &#8220;words&#8221; correctly'>Make the zsh zle handle &#8220;words&#8221; correctly</a> <small> Snippet from my .zshrc: #...</small></li><li><a href='http://blog.bstpierre.org/zsh-history-expansion' rel='bookmark' title='Permanent Link: zsh history expansion'>zsh history expansion</a> <small> Exploring zsh features made me...</small></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.bstpierre.org/moving-to-zsh/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
