LoginSignup
5
3

More than 5 years have passed since last update.

fish shellで長いコマンドが終わったら通知する(OS X, powerline)

Posted at

最近zshからfish shellに移行してみました。
shellは詳しくないんですが、fishはzshよりも気軽に書けそうな雰囲気があり、自分で設定を書いてみてます。

今回はzsh-notifyをfishで実装してみました。

やりかた

必要なもの

~/.config/fish/config.d/fish-notify.fish
function fish_notify --on-event fish_prompt
    set _display_status $status
    if test $CMD_DURATION
        set secs (math "$CMD_DURATION / 1000")
        # 3秒以上掛かったら通知する
        if test $secs -ge 3
            terminal-notifier -title $history[1] -message "Returned $_display_status, took $secs seconds"
        end
    end
end

調べたこと

すでに同じ目的のモノがあって、

こちらではpromptのデザインを決めるfunction fish_promptの中で実行時間$CMD_DURATIONを参照して通知するか決めていたんですが、自分はpowerlineも使いたかったので、上書きしない方法を検討しました。

zsh-notifyを見ると、add-zsh-hookというのでコマンドが出力する前に関数をhookしていたので、同様のことをfishでもできないかと調べると--on-eventというものがあり今回はこれを使いました。

参考

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