zsh に移行してみた。
さすが最強のシェルと呼ばれるだけあって、なかなか素晴らしい。
一日かけて設定を色々と書いてみた。
.zshrcと.zshenvに分けたほうが良さそうだね。
#!/usr/bin/zshrc
## PATH
path=(/usr/local/sbin /usr/local/bin /usr/sbin
/usr/bin /sbin /bin /usr/games
/opt/google/chrome/
)
## 基本環境変数
export EDITOR=emacs
export LANG=ja_JP.UTF-8
case ${UID} in
0)
LANG=C
;;
esac
## プロンプトの設定
autoload -Uz promptinit
promptinit
prompt walters
bindkey -e # emacsバインド
#- プロンプトの表示設定
autoload colors
colors
case ${UID} in
0)
PROMPT="%{${fg[red]}%}[%n@%m] %(!.#.$) %{${reset_color}%}"
PROMPT2="%{${fg[red]}%}%_> %{${reset_color}%}"
SPROMPT="%{${fg[red]}%}correct: %R -> %r [nyae]? %{${reset_color}%}"
RPROMPT="%{${fg[red]}%}[%~]%{${reset_color}%}"
;;
*)
PROMPT="%B%{${fg[red]}%}%n %(!.#.$) %{${reset_color}%}"
PROMPT2="%B%{${fg[red]}%}%_> %{${reset_color}%}"
SPROMPT="%B%{${fg[red]}%}correct: %R -> %r [nyae]? %{${reset_color}%}"
RPROMPT="%B%{${fg[yellow]}%}[%~]%{${reset_color}%}"
;;
esac
## 履歴の設定
HISTFILE=~/.zsh_history
HISTSIZE=100000
SAVEHIST=100000
setopt share_history # 履歴を共有する。
setopt hist_ignore_dups # 直前のコマンドの重複を削除する。
setopt hist_ignore_all_dups # 重複するコマンドが記録される時、古い方を削除する。
setopt hist_save_no_dups # 重複するコマンドが保存される時、古い方を削除する。
setopt hist_expire_dups_first # 古い履歴を削除する必要がある場合、まず重複しているものから削除する。
setopt hist_find_no_dups # 履歴検索で重複しているものを表示しない。
setopt append_history # 履歴を上書きしないで追加する。
setopt hist_no_store # historyコマンドは除去する。
#- 履歴検索機能のショートカット設定
autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^P" history-beginning-search-backward-end # CTRL-P
bindkey "^N" history-beginning-search-forward-end # CTRL-N
bindkey "\\ep" history-beginning-search-backward-end # ESC-P
bindkey "\\en" history-beginning-search-forward-end # ESC-N
## 色の設定
# to restore default color
# 1 for brighter colors
# 4 for underlined text
# 5 for flashing text
# 30 for black foreground
# 31 for red foreground
# 32 for green foreground
# 33 for yellow (or brown) foreground
# 34 for blue foreground
# 35 for purple foreground
# 36 for cyan foreground
# 37 for white (or gray) foreground
# 40 for black background
# 41 for red background
# 42 for green background
# 43 for yellow (or brown) background
# 44 for blue background
# 45 for purple background
# 46 for cyan background
# 47 for white (or gray) background
autoload colors
colors
eval `dircolors` # export LS_COLORS
case "${TERM}" in
xterm)
export TERM=xterm-color
;;
kterm)
export TERM=kterm-color
# set BackSpace control character
stty erase
;;
cons25)
unset LANG
export LSCOLORS=ExFxCxdxBxegedabagacad
export ZLS_COLORS=$LS_COLORS
;;
esac
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
## alias の設定
#- 基本alias
setopt complete_aliases # 補完時にオリジナルのコマンドまで展開してから補完する。
alias szsh='source ~/.zshrc'
alias ls='ls -aF --color'
alias la='ls -laF --color'
alias top='htop'
alias rm='rm -i'
alias du='du -h'
alias df='df -h'
alias his='history -i'
alias tarc='tar czvf' # アーカイブ作成
alias tarx='tar xvf' # アーカイブ解凍
#- cat hoge | less をcat hoge L という風に記述できる。
#alias -g L='| less' # ll でzshは同様の動作が可能。
alias -g G='| grep'
alias -g H='| head'
alias -g T='| tail'
## 自動補完
autoload -Uz compinit
compinit
autoload predict-on # 履歴による先方予測補完
predict-on
zstyle ':completion:*' menu select=1 eval "$(dircolors -b)"
zstyle ':completion:*:default' menu select=1 # 補完メニューをカーソルで選択可能にする。
zstyle ':completion:*:cd:*' tag-order local-directories path-directories # カレントに候補が無い場合のみcdpath 上のディレクトリが候補となる。
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*' # 補完の時に大文字小文字を区別しない
export LISTMAX=-1 # 補完リストが多いときに尋ねる数。-1は尋ねない。
setopt list_packed # 補完候補をつめて表示する
setopt auto_menu # TAB で順に補完候補を切り替える
setopt auto_list # 複数の補完候補があったときに、そのリストを自動的に表示
setopt complete_in_word # 補完開始時にカーソルは単語の終端になくても良い。
setopt list_types # 種類を示すマーク表示をつける(ls -fと同じもの)
setopt extended_history # コマンド開始時のタイムスタンプと、実行時間(秒)をヒストリファイルに書き込む。
setopt auto_param_keys # カッコの対応などを自動的に補完
setopt auto_param_slash # ディレクトリ名の補完で末尾の / を自動的に付加し、次の補完に備える
## コマンドライン cd関連
cdpath=($HOME) # カレントディレクトリにサブディレクトリが見つからない場合にcdが検索する場所
setopt aliases
setopt auto_cd # そのディレクトリへのcdコマンドが実行される。
setopt auto_pushd # [cd -TAB] でディレクトリを記録したディレクトリを表示する。
setopt pushd_ignore_dups # 同じディレクトリを pushd しない
setopt correct # リターンを押す度にスペルチェックをする。
setopt correct_all # リターンを押す度にスペルチェックをする。
setopt nolistbeep # ビープ音カット
setopt noautoremoveslash # パスの最後の/を削除しない(たまに/でコマンドの意味が変化するので有効推奨)
setopt check_jobs # ジョブ制御を行っているシェルが終了する前に、バックグラウンドやサスペンド状態のジョブの状態を報告する。
setopt chase_links # シンボリックリンクを正しいパスに変更する。
setopt print_eight_bit # 出力時8ビットを通す
setopt no_clobber # リダイレクトで上書きする事を許可しない。
setopt brace_ccl # {a-c} を a b c に展開する機能を使えるようにする
setopt extended_glob # globを拡張する。
## その他
xmodmap ~/.Xmodmap
autoload zed # zed テキストエディタ
## zstyle
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
## .zshrc.mine に試験用の設定を書き込む。初めての設定は分離することで安定性と保守性を高める。
[ -f ~/.zshrc.mine ] && source ~/.zshrc.mine
補完素敵。
でも、predict-onはお友達になれないかもしれない。
便利なんだけど、ちょっとうざいんだよなあ。