一部で「究極のシェル」と名高い zsh の設定ファイル .zshrc
(旧 .zshrc
はこちら)
ディレクトリ構成
$HOME/
├─.zshenv
└─.zsh/
├─.zshrc
├─.zcompdump
└─.history
関連ファイルをホームディレクトリにばら撒かず .zsh/
に集めることにする.
そのために環境変数 ZDOTDIR
を .zshenv
ファイル中で指定する.
% mkdir ~/.zsh
% echo 'ZDOTDIR="$HOME/.zsh"' >> ~/.zshenv
これで .zshenv
以外の設定ファイル (.zshrc
, .zprofile
など) を ~/
ではなく ~/.zsh/
に置くことができる.
もし .zshenv
もホームディレクトリに置きたくないのであれば, .zshenv
ではなく /etc/zshrc
に
ZDOTDIR="$HOME/.zsh"
と設定すればよい. その場合のディレクトリ構成は以下の通り.
$HOME/
└─.zsh/
├─.zshenv
├─.zshrc
├─.zcompdump
└─.history
とくに便利と感じるもの (無印は bindkey -e
による設定、* はカスタム設定)
[tab]
expand-or-complete とにかく頻用. 気がつけば連打[shift]+[tab]
reverse-menu-complete(*) [tab] と逆順に選ぶ[control]+a
beginning-of-line カーソルを行頭へ移動[control]+e
end-of-line カーソルを行末へ移動[control]+f
forward-word(*) カーソルを単語ひとつぶん後ろへ移動[control]+b
backward-word(*) カーソルを単語ひとつぶん前へ移動[control]+w
backward-kill-word 単語ひとつぶん削除[control]+k
kill-line カーソルから行末まで削除[control]+q
push-line 入力中のコマンドを保持して新しいコマンドラインを用意する[control]+p
history-beginning-search-backward-end(*) 履歴を検索 (新しい方から)[control]+n
history-beginning-search-forward-end(*) 履歴を検索 (古い方から)[control]+r
history-incremental-pattern-search-backward(*) 履歴をインクリメンタル検索 (新しい方から)[control]+s
history-incremental-pattern-search-forward(*) 履歴をインクリメンタル検索 (古い方から)[control]+j
run-help(*) 入力中のコマンドを保持して man を開く[control]+l
clear-screen 画面をクリア (clearコマンドと同じ)
^F, ^B の挙動はデフォルトでは [esc]+f, [esc]+b. 自分は [esc] より押しやすい [control] に割りあてた.
ちなみに
% bindkey -L
でキーバインドの一覧を見ることができる.
- add: 自作補完関数の置き場所 (.zsh/completion) の設定を追加
- add:
alias less
を追加、LESSHISTFILE
の設定を移動
- add:
alias sudo
を追加 - modify:
alias ls
を変更 (OS X での-O
,-e
,-@
オプションを追加)
- remove:
alias nano
を削除 (漢ならvi
)
- modify:
alias nano
の内容を変更
- modify: 一部 Keybind を変更
- ^F, ^B のカーソル移動を 1 字単位から 1 語単位へ変更
- ^R, ^S の履歴検索にワイルドカードを使用可能にした
- ^H を
run-help
からデフォルト (backward-delete-char
) に変更 - ^J を
accept-line
(return) からrun-help
に変更
- 書き直し (旧
.zshrc
は こちら)- add:
cd
直後にls
を実行 - add: 直前のコマンドの終了ステータスをプロンプトの色で表示
- add: 実行に時間を要したコマンドの直後に elapsed time を表示
- add: 補完候補を大幅に増量
- modify: 設定ファイル等の置き場所を変更
- modify: プロンプト記号を
$
から%
に変更 - modify:
time
の出力書式を変更 (bash
風にカスタマイズしてたのを戻した) - modify: 補完結果の配色を
ls
の配色と合せてたけどグレー単色に変更 - modify:
ls
の配色を変更 (Mac, Linux で統一してたけど各環境のデフォルトに戻した) - remove: コマンド訂正機能 (
correct
) を削除 (代りに補完機能を強力にした) - remove: ディレクトリ名で自動的に
cd
する機能 (autocd
) を削除 (全然使ってなかった) - remove:
completealiases
オプションを削除 (エイリアスを元のコマンドとは別物とみなすので、適切な補完が効かなかった) - remove: 一部 Keybind (Home, Del, End) を削除
- add:
- ドキュメント追加