3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

fish shellでのエイリアス設定方法

Posted at

TL;DR

~/.config/fish/functions/*.fish に書け

fish をよく知らない方向けに

fish には bash で言う alias はありません。代替手段として、function を記述することで、コマンドの挙動を制御することができます。

よくある例

~/.config/fish/config.fish に function を記載します。

function ls
    command ls --color=auto $argv
end
funcsave ls

(今回初めて知った) よくある間違い

~/.config/fish/config.fish に function を記載する場合、funcsaveは不要です。

funcsave は、プロンプト上から動的に関数を定義し、永続化したい場合にのみ使用します。

本題に戻って、~/.config/fish/functions/ を使いましょう、というご紹介

config.fish に function を記載すると

  • config.fish が長くなって、可読性メンテナンス性が下がります

~/.config/fish/functions/*.fish に書く利点

  • 1ファイル1 functionで記述でき、メンテナンス性が高い

まとめと裏話

本当は利点にいちいちfuncsaveする必要がないよ、と書きたかったのですが、いろいろ試してみたところ、そもそもfuncsave要らないということがわかりました。

ということで、~/.config/fish/functions/ をちゃんと使っていきましょう。

3
5
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
3
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?