LoginSignup
7
2

fish 3.6.0 で abbr の仕様が変わった

Last updated at Posted at 2023-01-23

TL;DR

  • これまでuniversal変数でabbrを管理していたのが変更になった
    • universal変数によるabbrもサポートしている
    • 3.6.0にアップデートしたからといって突然これまでのabbrが使えなくなるわけではない
  • これからは config.fish にabbrを記述することが推奨された
  • これまでのようにコマンドラインから
 > abbr -a hoge 'echo hoge'

のように実行すると保存されない(shellを再起動するとそのabbrが消える)

本文

みなさんはfishのabbr1使っていますでしょうか。aliasと違って展開されるので、後で検索しやすくて私はよく使っています。

2023年1月7日のアップデートでfish 3.6.0になってからabbrの拡張性は増え、以下の機能が追加されました

  • コマンドの展開だけでなく、オプションなどのあらゆるところで展開できるようになった
  • 展開のワード(Matching tokens)がregexに対応した
  • 展開の際に関数が利用できるようになった
  • 展開後のカーソルの位置を設定できるようになった

これによりabbrはより使いやすくなったようです。これに関しての説明は省かせてもらいます。詳細はリリースノート詳細ページ(記事投稿時点)を見てください

universal変数の不使用

機能が増えたのは喜ばしいのですが、これによりabbr自体の仕様が変わりました。
これまでuniversal変数でabbrを管理していた2ものが別管理になりました。リリースノートの「Deprecations and removed features」にも書かれてあります

  • Abbreviations are no longer stored in universal variables. Existing universal abbreviations are still imported, but new abbreviations should be added to config.fish.
    (Abbreviationはユニバーサル変数に保存されなくなりました。現存しているユニバーサルによるabbreviationは使用できますが、新しいabbreviationはconfig.fishに追加してください。)

また、2023/1/22のコミット (まだバージョンには実装されていない) により、この旨がabbrの詳細にも明記されるようです。

※追記
abbrの説明ページに下記文章が反映されていることを確認しました。help abbrとしても確認可能です。

Previous versions of this allowed saving abbreviations in universal variables.
That's no longer possible. Existing variables will still be imported and abbr --erase will also erase the variables.
We recommend adding abbreviations to config.fish by just adding the abbr --add command.
When you run abbr, you will see output like this
> abbr
abbr -a -- foo bar # imported from a universal variable, see help abbr

In that case you should take the part before the # comment and save it in config.fish,
then you can run abbr --erase to remove the universal variable::
> abbr >> ~/.config/fish/config.fish
> abbr --erase (abbr --list)

上記の通り、

> abbr >> ~/.config/fish/config.fish
> abbr --erase (abbr --list)

を実行し、abbrをconfig.fishに追記した後universal変数からabbr関連の変数を削除しましょう。
また、新規のabbrはconfig.fishに書きましょう。

  1. Abbreviation(略語)の略

  2. 例えば git checkoutgco として登録する場合、内部的にはuniversal変数である $_fish_abbr_gcogit checkoutとセットする、という処理を行っていた

7
2
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
7
2