LoginSignup
21
21

More than 5 years have passed since last update.

バージョンに依存した zshrc の書き方

Last updated at Posted at 2012-12-02

同じ zshrc を複数の環境で使っているとたまにあることですが、古いバージョンだと無効な設定があったりしておこられることがあります。

以前は zsh --version | awk '{print $2}' みたいな感じでバージョンを取得して "." で split して比較してた頃もありました。

これだと細かいバージョンの指定をしようとするとめんどくさかったりします。
同様のことを is-at-least を使えば簡単にできますよっていうお話です。

例えば vcs_info を使おうとした際は 4.3.10 以上となるので以下のようにかけばおkです

~/.zshrc
autoload -Uz is-at-least
if is-at-least 4.3.10; then
    autoload -Uz vcs_info

    # ここに vcs_info に関わる設定をかく
fi

これでバージョンに依存した設定でも気軽にかけますね!

おまけ

~/.zshrc
REPORTTIME=3

3秒以上時間がかかった際に実行後、以下のように出力されます

$ perl hoge.pl
perl hoge.pl 3.38s user 3.10s system 32% cpu 38.203 total

これ地味に便利です!

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