fish shellの設定メモ
転職に伴い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
$ 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記法が異なるので注意してください。
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
ファイルを編集して以下のように設定を追記します。
function fish_user_key_bindings bind \cr 'peco_select_history (commandline -b)' bind \cx\ck peco_kill end
peco_select_history
と peco_kill
をそれぞれキーバインド設定しています。
bind \cr
は control + r
、 bind \cx\ck
は control + 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
ファイルは以下のようになっています。
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
で変更できます。
私は "Tango Dark" に設定しています。
以上で私的に最低限の設定ができました! fishで簡単便利なshell lifeを!
参考
fish shell fishshell.com
peco github.com
hub github.com
plugin参考 futurismo.biz
fisher github.com
jethrokuan/z github.com
0rax/fish-bd github.com
yoshiori/fish-peco_select_ghq_repository github.com
tsu-nera/fish-peco_recentd github.com
oh-my-fish/plugin-peco github.com