今日はこちらをインストールして、使ってみます。
インストール
インストール手順はGithubに記載がある通りです。
一番汎用的でみんな使えると思われるgit cloneで入れます。
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
ちなみにhomebrewだったら以下のような感じ
brew install fzf
設定
(homebrewの場合)fzfのキー設定をインストール
$(brew --prefix)/opt/fzf/install
Downloading bin/fzf ...
- Already exists
- Checking fzf executable ... 0.65.1
Do you want to enable fuzzy auto-completion? ([y]/n) y
Do you want to enable key bindings? ([y]/n) y
Generate /Users/sayaka/.fzf.bash ... OK
Generate /Users/sayaka/.fzf.zsh ... OK
Do you want to update your shell configuration files? ([y]/n) y
Update /Users/sayaka/.bashrc:
- [ -f ~/.fzf.bash ] && source ~/.fzf.bash
+ Added
Update /Users/sayaka/.zshrc:
- [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
+ Added
Finished. Restart your shell or reload config file.
source ~/.bashrc # bash (.bashrc should be loaded from .bash_profile)
source ~/.zshrc # zsh
Use uninstall script to remove fzf.
For more information, see: https://github.com/junegunn/fzf
以下を実行させたいので、全部yと答えて進めます。
- fzf 本体のチェック
- 自動補完を有効化
- キーバインド有効化
-
~/.fzf.zsh
を生成 -
.zshrc
にsource ~/.fzf.zsh
を追記
最後までyをつけたら、あとはsource ~/.zshrc
で適用して、type -a fzf-history-widget
で読み込まれたか確認します。
ここまできたら使えるようになります。
便利な使い方
-
Ctrl+R
で過去コマンド履歴を見ながら選んで入力 -
Ctrl+T
でファインダーやファイルエクスプローラのようにファイル一覧を見ながらファイルパスを入れられる -
fzf --preview 'cat --style=numbers --color=always {}'
で、ファイル一覧を中身のプレビュー付きで見られる - `ls | fzf --preview 'cat {}'でカレントディレクトリのファイルを一覧表示させて中身プレビューできる