LoginSignup
7
7

More than 5 years have passed since last update.

peco で man を絞り込み検索する

Last updated at Posted at 2016-09-25

ぐぐってみたところ同じことをやっている人が見当たらなかったので自分で書いてみました.

man のコマンドライン引数は補完できますが,項目がうろ覚えの場合に検索するのにはちょっと不便です.なので,peco で man を複数キーワードでインタラクティブに絞りこめるようにしてみました.

tmp.gif

~/.zshrc に下記のように設定しておきます.

function peco-man-list-all() {
    local parent dir file
    local paths=("${(s/:/)$(man -aw)}")
    for parent in $paths; do
        for dir in $(/bin/ls -1 $parent); do
            local p="${parent}/${dir}"
            if [ -d "$p" ]; then
                IFS=$'\n' local lines=($(/bin/ls -1 "$p"))
                for file in $lines; do
                    echo "${p}/${file}"
                done
            fi
        done
    done
}

function peco-man() {
    local selected=$(peco-man-list-all | peco --prompt 'man >')
    if [[ "$selected" != "" ]]; then
        man "$selected"
    fi
}
zle -N peco-man
bindkey -M viins '^ m' peco-man

Ctrl+Space → M に割り当てていますが,peco-man コマンドでそのまま使うこともできます.また, peco-man-list-all はすべての man ファイルを列挙するので,他のフィルターコマンドでもこれを使えば同じような事ができるはずです.

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7