public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo commit in xml/htdocs/doc/zh_cn: zsh.xml
@ 2010-01-19 14:28 Le Zhang (r0bertz)
  0 siblings, 0 replies; only message in thread
From: Le Zhang (r0bertz) @ 2010-01-19 14:28 UTC (permalink / raw
  To: gentoo-commits

r0bertz     10/01/19 14:28:42

  Added:                zsh.xml
  Log:
  [zh_cn] added zsh.xml, thanks to Jiang Zezhou

Revision  Changes    Path
1.1                  xml/htdocs/doc/zh_cn/zsh.xml

file : http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/zsh.xml?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/zh_cn/zsh.xml?rev=1.1&content-type=text/plain

Index: zsh.xml
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/zh_cn/zsh.xml,v 1.1 2010/01/19 14:28:42 r0bertz Exp $ -->
<!-- English CVS version: 1.6 -->


<guide link="/doc/zh_cn/zsh.xml" lang="zh_cn" disclaimer="draft">
<title>zsh安装配置指南</title>

<author title="作者">
  <mail link="hekonsek@gmail.com">Henryk Konsek</mail>
</author>
<author title="作者">
  <mail link="morritt.andrew@gmail.com">Andrew Morritt</mail>
</author>
<author title="编辑">
  <mail link="chriswhite@gentoo.org">Chris White</mail>
</author>
<author title="编辑">
  <mail link="welp@gentoo.org">Peter Weller</mail>
</author>
<author title="译者">
  <mail link="ritksm@gmail.com">江泽洲</mail>
</author>

<abstract>
本指南将为你展示如何快速地安装和配置zsh。在读完本指南后,你将能够使用许多zsh的特性,比如先进的tab补全、命令纠错和提示符管理。
</abstract>

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/2.5 -->


<license/>

<version>2</version>
<date>2006-10-18</date>

<chapter>
<title>安装</title>
<section>
<title>安装zsh</title>
<body>

<p>
在Gentoo中安装<c>zsh</c>,我们需要通过emerge来安装<c>app-shells/zsh</c>(zsh本身)和<c>app-shells/zsh-completion</c>
(zsh补全脚本)两个软件包。
</p>

<pre caption="通过emerge安装zsh">
# <i>emerge zsh zsh-completion</i>
</pre>

</body>
</section>
<section>
<title>进入zsh</title>
<body>

<p>
当你第一次运行<c>zsh</c>的时候,你会得到如下的一些信息。因为我们会在后面创建一个init文件,所以你可以跳过这一个功能选单。
</p>

<pre caption="跳过初始配置">
$ <i>zsh</i>
This is the Z Shell configuration function for new users, zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

--- Type one of the keys in parentheses --- <i>q</i>
</pre>

</body>
</section>
</chapter>

<chapter>
<title>配置</title>
<section>
<title>简介</title>
<body>

<p>
运行<c>zsh</c>会为一个会话启动zsh。如果你要一个永久的解决方案,请参考<uri link="#savingsettings">保存设置</uri>这一个章节。在安装完成以后,<c>zsh</c>看起来可能非常的简单并且功能十分有限。为了改变这个状况,你需要对几个配置进行修改。
</p>

</body>
</section>
<section>
<title>先进的Tab补全</title>
<body>

<p>
你需要运行以下的命令来开启<c>zsh</c>的tab补全系统:
</p>

<pre caption="开启补全系统">
% <i>autoload -U compinit</i>
% <i>compinit</i>
</pre>

<p>
默认的补全风格非常的普通和简陋。如果你要改进它的外观,运行以下的命令:
</p>

<pre caption="改进补全风格">
% <i>zstyle ':completion:*:descriptions' format '%U%B%d%b%u'</i>
% <i>zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'</i>
</pre>

</body>
</section>
<section>
<title>命令纠错</title>
<body>

<p>
开启命令自动纠错功能也是一个不错的主意:
</p>

<pre caption="开启纠错功能">
% <i>setopt correctall</i>
</pre>

</body>
</section>
<section>
<title>提示符</title>
<body>

<p>
当前的提示符可能看起来很乏味,然而我们可以通过简单的几个步骤来解决它。首先,我们需要初始化高级命令提示符支持:
</p>

<pre caption="开启高级命令提示符功能">
% <i>autoload -U promptinit</i>
% <i>promptinit</i>
</pre>

<p>
我们可以使用<c>prompt -p</c>命令来列出可用的提示符样本。现在我们可以激活一个我们喜欢的了:
</p>

<pre caption="选择一个提示符样本">
<comment>(使用你选择的提示符替代“gentoo”)</comment>
% <i>prompt gentoo</i>
</pre>

<note>
如果你在尝试不同的提示符,并且你不想看到每一个提示符的示例,那么你可以使用<c>prompt -l</c>来列出可用的提示符。
</note>

<p>
另一个选择是创建你自己的提示符。你需要设置PS1环境变量来实现这个想法。
</p>

<pre caption="一个简单的自定义提示符">
% <i>export PS1="[Test Prompt] > "</i>
[Test Prompt] >
</pre>

<p>
能够创建自定义的文本提示符一定很不错,与此同时zsh也提供了许多的转义序列来允许你把系统信息插入到提示符里。一些可用的转义序列如下:
</p>

<table>
<tr>
  <th>转义序列</th>
  <th>打印效果</th>
</tr>
<tr>
  <ti>%T</ti>
  <ti>系统时间(时:分)</ti>
</tr>
<tr>
  <ti>%*</ti>
  <ti>系统时间(时:分:秒)</ti>
</tr>
<tr>
  <ti>%D</ti>
  <ti>系统日期(年-月-日)</ti>
</tr>
<tr>
  <ti>%n</ti>
  <ti>你的用户名</ti>
</tr>
<tr>
  <ti>%B - %b</ti>
  <ti>开始到结束使用粗体打印</ti>
</tr>
<tr>
  <ti>%U - %u</ti>
  <ti>开始到结束使用下划线打印</ti>
</tr>
<tr>
  <ti>%d</ti>
  <ti>你目前的工作目录</ti>
</tr>
<tr>
  <ti>%~</ti>
  <ti>你目前的工作目录相对于~的相对路径</ti>
</tr>
<tr>
  <ti>%M</ti>
  <ti>计算机的主机名</ti>
</tr>
<tr>
  <ti>%m</ti>
  <ti>计算机的主机名(在第一个句号之前截断)</ti>
</tr>
<tr>
  <ti>%l</ti>
  <ti>你当前的tty</ti>
</tr>
</table>

<p>
你只要将这些转义序列插入到环境变量PS1里就可以了,而后zsh会自动地解析他们。
</p>

<pre caption="一个更复杂的提示符">
% <i>export PS1="[%* - %D] %d %% "</i>
[08:44:23 - 06-02-18] /home/username %
</pre>

</body>
</section>
<section>
<title>历史记录</title>
<body>

<p>
不幸的是Gentoo里默认的zsh配置不包含对命令行历史记录的支持。因为使用没有历史记录功能的shell是十分令人沮丧的,所以我们应该输入以下的命令:
</p>

<pre caption="基础的历史记录配置">
% <i>export HISTSIZE=2000</i>
% <i>export HISTFILE="$HOME/.history"</i>

<comment>(如果没有以下命令,历史记录不会被存储)</comment>
% <i>export SAVEHIST=$HISTSIZE</i>
</pre>

<!-- does not work
<p>

It is very comfortable to search commands in history using the up/down arrow
keys, especially after typing the few first letters of the desired command.
</p>

<p>
To enable this feature, enter the following commands:
</p>

<pre caption="Setting context searching">
% <i>bindkey `tput kcuu1` history-beginning-search-backward >/dev/null 2>&amp;1</i>
% <i>bindkey `tput kcud1` history-beginning-search-forward >/dev/null 2>&amp;1 </i>
</pre>

<p>
To try the above feature, try the following commands:
</p>

TODO: use commands that *are* in the history, i.e. commands from above samples

<pre caption="History searching based on the first letters of the commands">
<comment>(Do not press Enter after typing)</comment>
% <i>vim /etc/</i>
<comment>(Now press up arrow key)</comment>
% <i>vim /etc/fstab</i>
<comment>(Press up arrow key once again)</comment>
% <i>vim /etc/X11/xorg.conf</i>
</pre>
-->


<p>
为了防止记录重复的输入(比如<c>ls -l</c>在同一个shell会话中输入了太多次),你可以设置<c>hist_ignore_all_dups</c>选项:
</p>

<pre caption="设置忽略重复的记录">
% <i>setopt hist_ignore_all_dups</i>
</pre>

<p>
一个小技巧可以用来防止某些特定的输入被记录,那就是在输入他们之前先输入至少一个空格。
</p>

<pre caption="防止某些特定的输入被记录">
% <i>setopt hist_ignore_space</i>

<comment>(这个命令不会被记录。请注意在它之前的多出来的那个空格。)</comment>
% <i> cat /proc/cpuinfo</i>
</pre>

</body>
</section>
<section>
<title>杂项设置</title>
<body>

<p>
如果你想要避免在切换目录时一直输入乏味的<c>cd</c>命令(比如使用<c>/etc</c>而不是<c>cd /etc</c>)你可以设置<c>autocd</c>选项。
</p>

<pre caption="设置autocd选项">
% <i>setopt autocd</i>
</pre>

<p>
如果标准的bash样式的文件名替换(globbing)不和你的胃口,你可以通过<c>extendedglob</c>选项来设置开启扩展的文件名替换(globbing)(与正则表达式有些类似)。
</p>

<pre caption="设置扩展的文件名替换">
% <i>setopt extendedglob</i>
</pre>

<p>
当上面的选项被设置了以后,你可以使用扩展的文件名替换查询,例如:<c>cp ^*.(tar|bz2|gz)</c>。
</p>

</body>
</section>
</chapter>

<chapter id="savingsettings">
<title>保存设置</title>
<section>
<title>保存zsh设置</title>
<body>

<p>
当我们将<c>zsh</c>设置成我们喜欢的样子后,我们最好把这些设置保存成zsh的默认设置。一个可行的方法是把我们的配置写入到<path>/etc/zsh/zshrc</path>脚本里,这样这些设置就会成为系统默认的设置。还有一个替代方案就是通过编辑<path>/etc/zsh/zshrc</path>文件来使我们的设置只对自己的帐号有效。
</p>

<pre caption="一个zshrc范例">
#!/bin/zsh

# completion
autoload -U compinit
compinit

# correction
setopt correctall

# prompt
autoload -U promptinit
promptinit
prompt gentoo
</pre>

</body>
</section>
</chapter>

<chapter>
<title>把zsh设置成默认的shell</title>
<section>
<title>对于有root权限的用户的选择</title>
<body>

<p>
我们可以通过<c>usermod</c>命令来设置某一个给定用户的shell。
</p>

<pre caption="使用usermod命令永久地切换到zsh">
# <i>usermod -s /bin/zsh userlogin</i>
</pre>

</body>
</section>
<section>
<title>对于非root用户的替代解决方案</title>
<body>

<p>
如果你的系统管理员拒绝为你把shell设置成zsh(无论你的请求多么地温和),那么你可以设置<c>bash</c>在启动的时候执行<c>zsh</c>,你要做的一切就是对你的<path>~/.bashrc</path>做一个小修改。
</p>

<pre caption="~/.bashrc样本">
<comment>(把以下内容加入到你的~/.bashrc里)</comment>
exec zsh
</pre>

<p>
改变shell的另外一种方法就是使用<c>chsh</c>命令(一个改变用户登录shell的实用程序)。一个普通用户只能改变自己账户的登录shell。而作为root,你可以改变所有用户的登录shell。
</p>

<pre caption="使用chsh命令永久地切换到zsh">
<comment>(使用你的用户名替代"username")</comment>
$ <i>chsh -s /bin/zsh username</i>
</pre>

</body>
</section>
</chapter>
</guide>






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-01-19 14:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19 14:28 [gentoo-commits] gentoo commit in xml/htdocs/doc/zh_cn: zsh.xml Le Zhang (r0bertz)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox