ablog

不器用で落着きのない技術者のメモ

zsh でコマンドオプションの補完が効かない

$ tar -<Tab>

あれ?オプションが表示されない。
http://journal.mycom.co.jp/column/zsh/001/index.html によると、

autoload -U compinit
compinit

を実行しないと有効にならない補完機能があるみたい。

 $ tar -<Tab>
 A   -- append to an archive
 c   -- create a new archive
 f   -- specify archive file or device
 t   -- list archive contents 
 u   -- update archive
 v   -- verbose output
 x   -- extract files from an archive

おお、出た。

zsh入門してみたら便利すぎて鼻息が抑えられない - はてブロ@ama_ch を参考に .zshrc にいろいろ設定しておく。
.zshrc に追記しておく。

# Autocomplete
autoload -U compinit
compinit

# Prompt
case ${UID} in
0)
    PROMPT="%{^[[31m%}%n%%%{^[[m%} "
    RPROMPT="[%~]"
    PROMPT2="%B%{^[[31m%}%_#%{^[[m%}%b "
    SPROMPT="%B%{^[[31m%}%r is correct? [n,y,a,e]:%{^[[m%}%b "
    [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && 
        PROMPT="%{^[[37m%}${HOST%%.*} ${PROMPT}"
    ;;
*)
    PROMPT="%{^[[31m%}%n%%%{^[[m%} "
    RPROMPT="[%~]"
    PROMPT2="%{^[[31m%}%_%%%{^[[m%} "
    SPROMPT="%{^[[31m%}%r is correct? [n,y,a,e]:%{^[[m%} "
    [ -n "${REMOTEHOST}${SSH_CONNECTION}" ] && 
        PROMPT="%{^[[37m%}${HOST%%.*} ${PROMPT}"
    ;;
esac

# History
HISTFILE=~/.zsh_history
HISTSIZE=6000000
SAVEHIST=6000000
setopt hist_ignore_dups     # ignore duplication command history list
setopt share_history        # share command history data

# History search
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
bindkey "^N" history-beginning-search-forward-end

# Change directory when only path typed
setopt auto_cd

# d -[Tab] --> list history 
setopt auto_pushd

# Correct command
setopt correct

# Display packed list
setopt list_packed 

# Beep off
setopt nolistbeep

"^["はエスケープ記号なので、そのままコピペすると動かない。
Emacsで置換する。

M-x replace-string
Replace string: ^[
Replace string ^[ with: C-q ESC

追記(2009/6/19):
vi で置換する。

:%s/\^\[/Ctrl-v ESC/g