LoginSignup
46
41

More than 5 years have passed since last update.

fish shellの設定メモ

Posted at

自分のblogからQiitaに転載

転職に伴いMacのTerminalを新たに設定する機会がありました。せっかくなのでメモしておきます。

Terminalでの仕事が快適にできるような自分的「最低限」の設定ができるまでがゴールです。
fish shellといくつかのCLIツールのインストールや設定について書いていきます。
fish shellは予め用意されている設定が多いので、こういう記事で書くことが少なくて便利ですね。

前提

  • Homebrewがインストール済みであること
  • iTerm2がインストール済みであること(Terminal.appでも別にいいけど、気分です)

Install fish_shell

まずはこれをしなくちゃ始まらない。fish shellをインストールします。

$ brew install fish

インストール後のガイドに従って /etc/shells にfishを追加してデフォルトシェルをfishに変更します。

Install fisher

fishのplugin manage fisher をインストールします。

$ curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish

Install peco, ghq, hub

いくつかの便利ツールをインストールします。

peco

インクリメンタル検索便利ツール peco

$ brew install peco

ghq

GitHubリポジトリ管理ツール ghq

$ brew install ghq

以下のようにgit repositoryを置いているディレクトリを設定します。今回は ~/dev/ を指定しました。

$ git config --global ghq.root ~/dev/

hub

GitHub便利コマンド hub

$ brew install hub

~/.config/fish/config.fish ファイルに以下のようにaliasを追記して設定します。bashとはalias記法が異なるので注意してください。

~/.config/fish/config.fish
eval (hub alias -s)

completionについては特に何もしなくてもbrew installで設定が追加されるようです。

Install plugins

自分的に最低限必要だなと思うpluginをインストール・設定していきます。

plugin-peco

pecoでhistoryをインクリメンタルに検索できるやつ。便利すぎる。

$ fisher add oh-my-fish/plugin-peco

~/.config/fish/config.fish ファイルを編集して以下のように設定を追記します。

~/.config/fish/config.fish
function fish_user_key_bindings
  bind \cr 'peco_select_history (commandline -b)'
  bind \cx\ck peco_kill
end

peco_select_historypeco_kill をそれぞれキーバインド設定しています。
bind \crcontrol + rbind \cx\ckcontrol + x の直後に control + k という意味になります。
後者は結構すばやくコマンド入力しないと反応しないので素早くコマンド入力する練習をしましょう。

z

過去に訪れたディレクトリに一発で飛べる。便利。

$ fisher add jethrokuan/z

fish-bd

ディレクトリを簡単に遡れるやつ。これも便利。

$ fisher add 0rax/fish-bd

fish-peco_select_ghq_repository

$ fisher add yoshiori/fish-peco_select_ghq_repository

以下のキーバインドを追加します。

function fish_user_key_bindings
  bind \c] peco_select_ghq_repository
end

fish-peco_recentd

z コマンドで頻繁に訪れるディレクトリを peco で選択して移動する。

とのこと。めちゃくちゃ便利。

$ fisher add tsu-nera/fish-peco_recentd

これも以下のようにキーバインドを追記します。

function fish_user_key_bindings
  bind \cx\cr peco_recentd
end

fish設定を反映

ここまで設定すると ~/.config/fish/config.fish ファイルは以下のようになっています。

~/.config/fish/config.fish
eval (hub alias -s)

function fish_user_key_bindings
  bind \cr 'peco_select_history (commandline -b)'
  bind \cx\ck peco_kill
  bind \c] peco_select_ghq_repository
  bind \cx\cr peco_recentd
end

sourceやterminalの再起動などをしてfishの設定変更を反映しましょう。
fishのsourceはbashと記法が異なるため注意してください。
以下のようにすればOKです。

$ source ~/.config/fish/config.fish

以上でプラグインのインストールとキーバインド設定が完了しました。

Config fish

基本的な設定は完了していますが、プロンプトやカラーをお好みで変更していきましょう。
fish_config コマンドを実行するとブラウザでfishの設定変更が可能になります。

私は colorを"fish default"、promptは "Informative" に設定しています。

このままでは暗い文字色が少し見づらいのでiTerm2のカラーも変更します。
iTerm2のカラー設定は iTerm2 > Preferences > Profiles > Colors > Color Presets で変更できます。
[f:id:tacke:20181207113815p:plain]iTerm2 > Preferences > Profiles > Colors > Color Presets

私は "Tango Dark" に設定しています。

以上で私的に最低限の設定ができました!
fishで簡単便利なshell lifeを!

参考

fish shell
[https://fishshell.com/:embed:cite]

peco
[https://github.com/peco/peco:embed:cite]

hub
[https://github.com/github/hub:embed:cite]

plugin参考
[https://futurismo.biz/archives/6087/:embed:cite]

fisher
[https://github.com/jorgebucaran/fisher:embed:cite]

jethrokuan/z
[https://github.com/jethrokuan/z:embed:cite]

0rax/fish-bd
[https://github.com/0rax/fish-bd:embed:cite]

yoshiori/fish-peco_select_ghq_repository
[https://github.com/yoshiori/fish-peco_select_ghq_repository:embed:cite]

tsu-nera/fish-peco_recentd
[https://github.com/tsu-nera/fish-peco_recentd:embed:cite]

oh-my-fish/plugin-peco
[https://github.com/oh-my-fish/plugin-peco:embed:cite]

46
41
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
46
41