<?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>Chen Yufei's blog &#187; zsh</title>
	<atom:link href="http://chenyufei.info/blog/tag/zsh/feed/" rel="self" type="application/rss+xml" />
	<link>http://chenyufei.info/blog</link>
	<description>Keep your head about you while all those are losing theirs</description>
	<lastBuildDate>Wed, 21 Jul 2010 05:30:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>更新 zsh 的 command hash table</title>
		<link>http://chenyufei.info/blog/2009-11-14/updating-zsh-command-hash-table/</link>
		<comments>http://chenyufei.info/blog/2009-11-14/updating-zsh-command-hash-table/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 15:26:42 +0000</pubDate>
		<dc:creator>chenyufei</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://chenyufei.info/blog/?p=282</guid>
		<description><![CDATA[zsh 下新装了一个软件，tab 补全时新装软件的命令不会出现。以前的解决办法是执行 export PATH=$PATH 让 zsh 去更新缓存。 今天在 Pylons 的 activate 脚本里看到了一条 builtin 命令 hash (man zshbuiltins)，这条命令可以直接修改 command hash table。$PATH 路径下的内容发生变化时可以用 hash -r 来更新。]]></description>
			<content:encoded><![CDATA[<p>zsh 下新装了一个软件，tab 补全时新装软件的命令不会出现。以前的解决办法是执行 <code>export PATH=$PATH</code> 让 zsh 去更新缓存。</p>
<p>今天在 Pylons 的 activate 脚本里看到了一条 builtin 命令 <code>hash</code> (man zshbuiltins)，这条命令可以直接修改 command hash table。$PATH 路径下的内容发生变化时可以用 <code>hash -r</code> 来更新。</p>
]]></content:encoded>
			<wfw:commentRss>http://chenyufei.info/blog/2009-11-14/updating-zsh-command-hash-table/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>zsh + screen</title>
		<link>http://chenyufei.info/blog/2009-11-12/zsh-screen/</link>
		<comments>http://chenyufei.info/blog/2009-11-12/zsh-screen/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 15:12:14 +0000</pubDate>
		<dc:creator>chenyufei</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://chenyufei.info/blog/?p=267</guid>
		<description><![CDATA[screen 提供多个 shell 来回切换是很方便，不过有时会忘记应该切换到哪个 window。如果可以根据执行的命令和当前目录来动态设置 window title 的话来回切换时就会可以方便的找到目标 window。其实 zsh-lovers 里就有说明。 screen 可以通过 echo 特殊的字符来设置 window 的 title，而 zsh 有两个特殊的函数 preexec 和 precmd，前者在用户输入命令按下回车但 zsh 还未执行命令前被调用，后者在 zsh 更新 prompt 前被调用（具体说明见 man zshmisc）。把 zsh 和 screen 的功能结合起来就可以在执行命令时把 screen window 的标题设置成当前执行的命令，而在 zsh 等待用户命令时，将 title 设置成当前目录。 先贴 zsh 的相关配置，PS1 的配置不喜欢可以去掉。 autoload colors colors case $TERM in screen*) function sctitle() [...]]]></description>
			<content:encoded><![CDATA[<p>screen 提供多个 shell 来回切换是很方便，不过有时会忘记应该切换到哪个 window。如果可以根据执行的命令和当前目录来动态设置 window title 的话来回切换时就会可以方便的找到目标 window。其实 zsh-lovers 里就有说明。</p>
<p>screen 可以通过 echo 特殊的字符来设置 window 的 title，而 zsh 有两个特殊的函数 preexec 和 precmd，前者在用户输入命令按下回车但 zsh 还未执行命令前被调用，后者在 zsh 更新 prompt 前被调用（具体说明见 man zshmisc）。把 zsh 和 screen 的功能结合起来就可以在<strong>执行命令时把 screen window 的标题设置成当前执行的命令，而在 zsh 等待用户命令时，将 title 设置成当前目录</strong>。</p>
<p>先贴 zsh 的相关配置，PS1 的配置不喜欢可以去掉。</p>
<pre>
autoload colors
colors

case $TERM in
    screen*)
        function sctitle() { print -Pn "\ek$1\e\\"}
        function precmd() { sctitle "%20< ..<%~%<<" }
        function preexec() { sctitle "%20>..>$1%< <" }
        export PS1="%{${fg[cyan]}%}[%D{%H:%M} %20<..<%~%<<]%{$reset_color%} "
    ;;
    *)
        export PS1="%{${fg[cyan]}%}[%D{%H:%M} %n@%m:%20<..<%~%<<]%{$reset_color%} "
    ;;
esac
</pre>
<p>有时命令或者当前目录很长，screen 的 status bar 宽度会不够，zsh 有内置的截短字符串的功能，用 %20< ..<%~%<< 限制目录最长为 20 个字符，把左边的多余字符去掉，截短后用两个点表示，%~ 表示当前目录，如果包含 HOME 目录则用波浪号表示，%<< 标志截短操作的结束。%20>..>$1%< < 类似，preexec 的第一个参数是完整的命令行输入，同样截短成 20 个字符，不过是去掉右边的多余字符。sctitle 就是打印特殊字符来设置 screen window title 的函数。</p>
<p>接下来是 .screenrc。</p>
<pre>
startup_message off
# use visual bell
vbell off
# replace Ctrl-A by `
escape ``
# set a big scrolling buffer
defscrollback 5000
# Set the caption on the bottom line
caption always '%{= kg}[%{G}%H%{g}][%= %{= kw}%?%-Lw%?%{+b r}(%{y}%n %t%?(%u)%?%{r})%{= w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'
# %{= kG} first set default color (=), back ground black (k), foreground green (G)
# [%{G}%H%{g}] color bright green, host name (%H), color green
# [%= ...] padding (%=), window left to the current focus window if exists,
#      (current focus window with color yellow), window to the right of the
#      focus window
# [%{B} %m/%d %{W}%c %{g}] color bright blue, month/date (%m%d), color bright white,
#      current time(%c), color green

# open several terminals at startup
screen 5
screen 4
screen 3
screen 2
screen 1
</pre>
<p>因为我用 vim，而且我觉得切换 window 时要按数字键，所以我把 escape 设置成 back tick。这个配置最关键的就是 caption 了，忘记从哪里 copy 过来的了（用 hardstatus 的话 screen 的消息也是在 hardstatus 上显示，所以我喜欢用 caption）。我直接在配置文件里加了点注释，语法很恶心，我都看晕了。关于  caption/hardstatus 里的转义字符说明见 man screen 的 string escape 一节。</p>
<p>试试看吧，这个配置还是很炫而且也蛮实用的。</p>
]]></content:encoded>
			<wfw:commentRss>http://chenyufei.info/blog/2009-11-12/zsh-screen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
