zsh導入記録

新年度なのでちょっと気分を変えようと、shellを今まで使ってたbashから、色々捗ると評判のzshに変えてみたのでその記録。
まだ設定はデフォのままでいじってない。

環境

Ubuntu 10.04.1

インストール

参考: http://d.hatena.ne.jp/foo22222/20110321/1300668757
まずは実験用サーバーで…と思ったら、zshが入ってなかった

$zsh --version
プログラム 'zsh' は以下のパッケージで見つかりました:
* zsh
* zsh-beta
次の操作を試してください: sudo apt-get install <選択したパッケージ>

ので、インストールから。

sudo apt-get update && apt-get install zsh

shell の変更

インストールできたらzshをデフォルトのshellに設定。

$which zsh
/usr/bin/zsh
$ chsh
パスワード:
Changing the login shell for tachi
Enter the new value, or press ENTER for the default
Login Shell [/bin/bash]: /usr/bin/zsh

再ログインしないとshellが変わらないので、いったんログアウト。

設定

ログインし直すと、初回ログイン時の設定ウィザードが開く

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 ---

公開されてる設定ファイルをコピペしてきてもいいんだけど、ある程度はこのウィザードに乗っかって設定できるみたいなので 1 を選択。

Attempting to extract information from manual pages...
Please pick one of the following options:

(1) Configure settings for history, i.e. command lines remembered
and saved by the shell. (Recommended.)

(2) Configure the new completion system. (Recommended.)

(3) Configure how keys behave when editing command lines. (Recommended.)

(4) Pick some of the more common shell options. These are simple "on"
or "off" switches controlling the shell's features.

(0) Exit, creating a blank ~/.zshrc file.

(a) Abort all settings and start from scratch. Note this will overwrite
any settings from zsh-newuser-install already in the startup file.
It will not alter any of your other settings, however.

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

      • Type one of the keys in parentheses ---

1 がヒストリーの設定
2 がコンプリーションの設定
3 がキーバインドの設定
4 がその他の設定
とのことなので1 〜 3を順に設定。

1 ヒストリ

History configuration
=====================

# (1) Number of lines of history kept within the shell.
HISTSIZE=1000 (not yet saved)
# (2) File where history is saved.
HISTFILE=~/.histfile (not yet saved)
# (3) Number of lines of history to save to $HISTFILE.
SAVEHIST=1000 (not yet saved)

# (0) Remember edits and return to main menu (does not save file yet)
# (q) Abandon edits and return to main menu

      • Type one of the keys in parentheses --- 0

1000ぐらいならすぐ埋まりそうなので後で変更するとして、まずはこのまま。
0 で戻る。

2 コンプリーション

The new completion system (compsys) allows you to complete
commands, arguments and special shell syntax such as variables. It provides
completions for a wide range of commonly used commands in most cases simply
by typing the TAB key. Documentation is in the zshcompsys manual page.
If it is not turned on, only a few simple completions such as filenames
are available but the time to start the shell is slightly shorter.

You can:
(1) Turn on completion with the default options.

(2) Run the configuration tool (compinstall). You can also run
this from the command line with the following commands:
autoload -Uz compinstall
compinstall
if you don't want to configure completion now.

(0) Don't turn on completion.

      • Type one of the keys in parentheses --- 1

コンプリーション ON の1を選択

3 キーバインド

The keys in the shell's line editor can be made to behave either
like Emacs or like Vi, two common Unix editors. If you have no
experience of either, Emacs is recommended. If you don't pick one,
the shell will try to guess based on the EDITOR environment variable.
Usually it's better to pick one explicitly.

# (1) Change default editing configuration
bindkey -e (not yet saved)

# (0) Remember edits and return to main menu (does not save file yet)
# (q) Abandon edits and return to main menu

      • Type one of the keys in parentheses ---

すでに binding -e とemacs風になっていたのでそのままで。
ちなみにこういうオプションがあるみたい

Pick a keymap (set of keys) to use when editing.
Type:
(e) for Emacs keymap (recommended unless you are vi user)
(v) for Vi keymap
(n) not to set a keymap (allow shell to choose)
(k) to keep the current setting, (e):

      • Type one of the keys in parentheses ---

で、戻って設定をセーブ。

出来上がった .zshrc はこんな感じ

# Lines configured by zsh-newuser-install HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
bindkey -e
# End of lines configured by zsh-newuser-install # The following lines were added by compinstall zstyle :compinstall filename '/home/username/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

とりあえず導入まで完了。
今のところコンプリーションが楽しいという印象。
これから↓とかを参考に設定いじっていこうと思う。


http://journal.mycom.co.jp/column/zsh/index.html
zshの基本的な使い方 1/3 「導入~基本設定」編 - ナレッジエース
http://linuxserver.jp/Linux/ZSH%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB.php
zshで究極のオペレーションを:連載|gihyo.jp … 技術評論社