Category: Fish

fisherによるプラグイン管理

インストール手順

curlを使用してfisherのインストーラスクリプトをダウンロードし、それをsourceコマンドで実行し、最後にfisher自身をインストールします。

curl -fsSL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source
fisher install jorgebucaran/fisher

バージョン確認

fisher --version

オプション

目的コマンド
プラグイン追加fisher install [プラグイン名]
プラグイン削除fisher remove [プラグイン名]
管理プラグイン一覧fisher list

使用しているプラグイン

自前の関数をfisherとは別にgit管理したい

fisherは ~/.config/fish/functions/, ~/.config/fish/conf.d/, ~/.config/fish/completions/ 配下にプラグイン由来のファイルを置く。 fisherでinstallしたりremoveしたりしていくので、これらはfisherの生成物として扱い、gitでは追跡しない。

独自に作った関数やconfig.fishはgit管理していきたい。

このため、別のディレクトリを作成し、自前の関数はそこに置いてgit管理していきたい。

現行の fishConfig では次の方針にする。

対象管理方針
fish_pluginsgit管理する。fisher plugin list のsource of truth
bootstrap.fishgit管理する。fish_plugins からfisher管理ファイルを復元する
config.fishgit管理する
my_functions/git管理する。自前関数とkey bindingを置く
functions/, conf.d/, completions/git管理しない。fisherの生成物

カスタムディレクトリの作成と読み込み

例えば、~/.config/fish/my_functionsというディレクトリを作成する。 次に、config.fishに以下のようなスクリプトを追加して、my_functionsディレクトリ内のすべての.fishファイルを読み込む。

for file in ~/.config/fish/my_functions/*.fish
    source $file
end

これで関数が読み込まれる。

Read more...

fish関連のメモ

setでの変数の定義のオプション

  • ユニバーサル変数
    • -U, –universal
      • 現在のセッションだけでなく、将来のすべてのセッションでも利用できる。
        • Fishの設定ディレクトリに保存され、シェルを再起動しても保持されます
  • グローバル変数
    • -g, –global
  • ローカル変数
    • -l, –local
  • 環境変数
    • -x, –export

-e, –eraceで変数の削除ができる。

fishキーバインドのカスタマイズ

下記のようにユーザ定義のキーバインドを定義できる。 fishConfig では fisher生成物の functions/ をgit管理しないため、自前の fish_user_key_bindings~/.config/fish/my_functions/fish_user_key_bindings.fish に置く。 ghq_cd_repository~/.config/fish/my_functions/ghq_cd_repository.fish で定義する。

function fish_user_key_bindings
    bind \cg ghq_cd_repository

    ### fzf.fish ###
    bind \cr _fzf_search_history
    bind \eh __hugo_content_search_key_binding

    ### 移動をワード単位で行う
    bind \en backward-word
    bind \em forward-word
end

my_functions/*.fishconfig.fish で source するだけでは、fish の key binding 初期化後に関数が定義される構成になり、fish_user_key_bindings が自動実行されない場合がある。 現行の fishConfig では my_functions の読み込み後、interactive shell のときに fish_user_key_bindings を明示実行する。

Read more...