diff --git a/README.rst b/README.rst index 2b412a4..2b2a7d7 100644 --- a/README.rst +++ b/README.rst @@ -111,6 +111,16 @@ a new array. # redefine what is ignored by auto-notify export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep") +*Running Custom Commands* + +By default ``notify-send`` is used to send notifications on Linux and ``osascript`` is used on MacOSX. +However the command that is executed can be configured by setting the ``AUTO_NOTIFY_COMMAND`` variable. +Specify where the text should be placed using the ``%text`` marker. An example can be seen below: + +:: + + export AUTO_NOTIFY_COMAND="my-fancy-notifier -rd -t20 \"%text\"" + Temporarily Disabling Notifications ----------------------------------- diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 2b9b161..0805cfd 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -15,13 +15,17 @@ export AUTO_NOTIFY_IGNORE=( function _auto_notify_message() { - local command="$1" + local command_run="$1" local elapsed="$2" # Run using echo -e in order to make sure notify-send picks up new line - text="$(echo -e "\"$command\" has completed\n(Total time: $elapsed seconds)")" + text="$(echo -e "\"$command_run\" has completed\n(Total time: $elapsed seconds)")" platform="$(uname)" - if [[ "$platform" == "Linux" ]]; then + if [[ -n "$AUTO_NOTIFY_COMMAND" ]]; then + local COMMAND="${AUTO_NOTIFY_COMMAND//\%text/$text}" + echo $COMMAND + eval $COMMAND + elif [[ "$platform" == "Linux" ]]; then notify-send "$text" elif [[ "$platform" == "Darwin" ]]; then osascript -e "display notification \"$text\" with title \"Command Completed\"" diff --git a/tests/test_auto_notify.zunit b/tests/test_auto_notify.zunit index f461e2d..36f54e1 100644 --- a/tests/test_auto_notify.zunit +++ b/tests/test_auto_notify.zunit @@ -78,6 +78,23 @@ done } +@test 'auto-notify sends notifications with custom command' { + AUTO_NOTIFY_COMMAND="bazzy -ef \"%text\" something" + AUTO_COMMAND="f bar -r" + AUTO_COMMAND_FULL="foo bar -r" + AUTO_COMMAND_START=11080 + + function bazzy { + echo - $@ + } + + run _auto_notify_send + + assert $state equals 0 + assert "$lines[1]" same_as "bazzy -ef \"\"f bar -r\" has completed" + assert "$lines[2]" same_as "(Total time: 20 seconds)\" something" +} + @test 'auto-notify-send sends notification on Linux' { AUTO_COMMAND="f bar -r" AUTO_COMMAND_FULL="foo bar -r"