zsh

コマンドhookしたい! コマンド終わったら、terminal-notifier 使ってうぇーい。

function __what_command_execute() {
  local cmd=$1
  export __NOTIFY_COMMAND="$cmd"
}

function __notify_complete_command() {
  local cmd=$__NOTIFY_COMMAND
  if [[ $cmd =~ "(be |bundle exec |bin/)rspec|(rails test)" ]] ||
    [[ $cmd =~ "(npm (test|install|run)|^mocha)" ]] ||
    [[ $cmd =~ "rails db:(migrate|reset|seed_fu)" ]]; then
    terminal-notifier -title "😎$MATCH" -message "💚Complete" -sound Submarine -timeout 10 -activate "com.googlecode.iterm2"
  fi
  unset __NOTIFY_COMMAND
}

if which terminal-notifier >/dev/null 2>&1; then
  add-zsh-hook preexec __what_command_execute
  add-zsh-hook precmd __notify_complete_command
fi