Zsh
Mac
AppleScript

時間がかかるコマンドの終了を通知センターに出す

More than 1 year has passed since last update.

これ

Screen Shot 2016-05-27 at 15.23.38.png

環境

  • OS X El Capitan 10.11.4
  • zsh 5.0.8 (x86_64-apple-darwin15.0)

全体

以下を追加する

.zshrc
function notify_precmd {
    prev_command_status=$?

    if [[ "$TTYIDLE" -gt 1 ]]; then
        notify_title=$([ "$prev_command_status" -eq 0 ] && echo "Command succeeded \U1F646" || echo "Command failed \U1F645")
        osascript -e "display notification \"$prev_command\" with title \"$notify_title\""
    fi
}

function store_command {
  prev_command=$2
}

autoload -Uz add-zsh-hook
add-zsh-hook preexec store_command
add-zsh-hook precmd notify_precmd

参考

http://qiita.com/izumin5210/items/c683cb6addc58cae59b6
http://qiita.com/zakuroishikuro/items/cfba3e7734036e389768