0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

zshにfzfを入れて、ターミナル操作を快適に(ファイルパスが入れやすい、コマンド履歴が見やすい)

Posted at

今日はこちらをインストールして、使ってみます。

インストール

インストール手順は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を生成
  • .zshrcsource ~/.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 {}'でカレントディレクトリのファイルを一覧表示させて中身プレビューできる
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?