LoginSignup
29
21

More than 5 years have passed since last update.

zshからfishに乗り換えた

Posted at

前から気になっていたのでfish shellに乗り換えてみました。

以下の記事が参考になったので、読んでみると良いと思います。

やったこと

  • fishのインストール
  • fzfのインストール
  • fisherのインストール
    • themeの変更
    • powerline用のfontsをインストール
  • pecoの設定

fishのインストール

まずはfishをインストールします。
Macなのでbrewで。

その他のOSでのインストール方法は以下を参照してください。
https://github.com/fish-shell/fish-shell

$ brew install fish
$ fish -v
fish, version 2.7.1

ログインシェル、デフォルトシェルをfishに変更します。

$ echo /usr/local/bin/fish | sudo tee -a /etc/shells
$ chsh -s /usr/local/bin/fish

fzfのインストール

続いてfzfをインストールします。
fzfは A command-line fuzzy finder とのことで、CLIでインクリメンタルに曖昧な検索が可能になるやつです。(書いていて気づいたけど、後述のpecoと被るのでどちらかで済むかも…)

なぜインストールしたかと言うと、fishにはbashやzshにある Ctrl + Rで動作するreverse incremental searchが無いのがツラかったからです。

無くてもいい感じに補完してくれるのですが、慣れた操作もしたいよねってとこもあり…
fzf自体はCtrl + Rなどのキーバインドで機能するもの以外にも色々機能があるので、活用したいところです。

$ brew install fzf
$ /usr/local/opt/fzf/install

fisherのインストール

てっとり早くいい感じにするにはzshでもあるoh-my-zshのfish版であるoh-my-fishを使うのも良いのですが、fisherの方がシンプルに感じたのと、oh-my-fishのプラグインなども利用可能なためfisherを利用することにしました。

fisherは、fish向けのパッケージマネージャです。

$ curl https://git.io/fisher --create-dirs -sLo ~/.config/fish/functions/fisher.fish
$ fisher -v
fisher version 3.0.8 ~/.config/fish/functions/fisher.fish
$ fisher -h
usage: fisher add <PACKAGES>    add packages
       fisher rm  <PACKAGES>    remove packages

       fisher ls                list installed packages
       fisher self-update       update fisher
       fisher self-uninstall    uninstall fisher & all packages
       fisher help              show this help
       fisher version           show version

examples:
       fisher add jethrokuan/z rafaelrinaldi/pure
       fisher add gitlab.com/owner/foobar@v2
       fisher add ~/myfish/mypkg
       fisher rm rafaelrinaldi/pure
       fisher ls | fisher rm

テーマ、移動を楽にする系、pecoのプラグイン?パッケージを追加。

$ fisher add oh-my-fish/theme-bobthefish
$ fisher add 0rax/fish-bd
$ fisher add oh-my-fish/plugin-peco
$ fisher ls
0rax/fish-bd
oh-my-fish/plugin-peco
oh-my-fish/theme-bobthefish

テーマはpowerlineを利用しているので、絵文字などを表示できるフォントが必要です。
自分は別でインストールしてpecoいたフォントを利用しましたが、入れていない場合は以下のコマンドでpowerline用のフォントをインストールすると良いと思います。

$ git clone https://github.com/powerline/fonts.git --depth=1
# install
$ cd fonts
$ ./install.sh
$ cd ..
$ rm -rf fonts

pecoの設定

上でpecoのプラグインをインストールしていたので、設定ファイルに以下を追加します。
上でも述べましたが、fzfで良い場合はそのままでも良いかと思います。
(書いてはみたものの、fzf良かったのでCtrl + Rは fzfのままにしましたw)

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

こんな感じになりました

fish.gif

29
21
1

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
29
21