Allow running custom commands using AUTO_NOTIFY_COMMAND
This commit is contained in:
parent
384a2eed6f
commit
ee9ec562f5
3 changed files with 34 additions and 3 deletions
10
README.rst
10
README.rst
|
@ -111,6 +111,16 @@ a new array.
|
||||||
# redefine what is ignored by auto-notify
|
# redefine what is ignored by auto-notify
|
||||||
export AUTO_NOTIFY_IGNORE=("docker" "man" "sleep")
|
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
|
Temporarily Disabling Notifications
|
||||||
-----------------------------------
|
-----------------------------------
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,17 @@ export AUTO_NOTIFY_IGNORE=(
|
||||||
|
|
||||||
|
|
||||||
function _auto_notify_message() {
|
function _auto_notify_message() {
|
||||||
local command="$1"
|
local command_run="$1"
|
||||||
local elapsed="$2"
|
local elapsed="$2"
|
||||||
# Run using echo -e in order to make sure notify-send picks up new line
|
# 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)"
|
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"
|
notify-send "$text"
|
||||||
elif [[ "$platform" == "Darwin" ]]; then
|
elif [[ "$platform" == "Darwin" ]]; then
|
||||||
osascript -e "display notification \"$text\" with title \"Command Completed\""
|
osascript -e "display notification \"$text\" with title \"Command Completed\""
|
||||||
|
|
|
@ -78,6 +78,23 @@
|
||||||
done
|
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' {
|
@test 'auto-notify-send sends notification on Linux' {
|
||||||
AUTO_COMMAND="f bar -r"
|
AUTO_COMMAND="f bar -r"
|
||||||
AUTO_COMMAND_FULL="foo bar -r"
|
AUTO_COMMAND_FULL="foo bar -r"
|
||||||
|
|
Loading…
Add table
Reference in a new issue