Open wada811 opened 5 years ago
ディレクトリの履歴から絞り込んでディレクトリを開きたい。
zsh の組み込みの cdr コマンドでディレクトリの履歴から peco で絞り込む。
zsh
cdr
peco
~/.zshrc に以下を設定する。
~/.zshrc
autoload -Uz add-zsh-hook
autoload -Uz chpwd_recent_dirs cdr add-zsh-hook chpwd chpwd_recent_dirs
zstyle ':completion:*' recent-dirs-insert both zstyle ':chpwd:*' recent-dirs-max 500 zstyle ':chpwd:*' recent-dirs-default true zstyle ':chpwd:*' recent-dirs-file "$HOME/.cache/shell/chpwd-recent-dirs" zstyle ':chpwd:*' recent-dirs-pushd true
mkdir -p ~/.cache/shell/
function peco-cdr() { local selected_dir=$(cdr -l | awk '{ print $2 }' | peco) if [ -n "$selected_dir" ]; then BUFFER="cd ${selected_dir}" zle accept-line fi zle clear-screen } zle -N peco-cdr # 履歴から cd bindkey '^@' peco-cdr
Why
ディレクトリの履歴から絞り込んでディレクトリを開きたい。
What
zsh
の組み込みのcdr
コマンドでディレクトリの履歴からpeco
で絞り込む。How
~/.zshrc
に以下を設定する。add-zsh-hook を有効にする
cdr を有効にする
cdr の設定
peco の設定
Ref