This commit is contained in:
pseudometa 2023-05-11 15:25:14 +01:00 committed by GitHub
commit 392c64f9e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -118,6 +118,15 @@ An example of how these values can be set is shown below:
export AUTO_NOTIFY_TITLE="Hey! %command has just finished" export AUTO_NOTIFY_TITLE="Hey! %command has just finished"
export AUTO_NOTIFY_BODY="It completed in %elapsed seconds with exit code %exit_code" export AUTO_NOTIFY_BODY="It completed in %elapsed seconds with exit code %exit_code"
**Notificaton Sound**
The notification can also trigger playing a short sound by changing ``AUTO_NOTIFY_USE_SOUND``.
NOTE: This configuration option currently only works for macOS.
::
  # Enable using sound (default: 0)
  export AUTO_NOTIFY_USE_SOUND=1
**Notification Expiration Time** **Notification Expiration Time**
You can set how long a notification sent by ``auto-notify`` will remain showing by setting the environment You can set how long a notification sent by ``auto-notify`` will remain showing by setting the environment

View file

@ -42,12 +42,15 @@ function _auto_notify_message() {
# 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
local DEFAULT_TITLE="\"%command\" Completed" local DEFAULT_TITLE="\"%command\" Completed"
local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")" local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")"
local DEFAULT_USE_SOUND=0
local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}" local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}" local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}"
local use_sound=${AUTO_NOTIFY_USE_SOUND:=$DEFAULT_USE_SOUND}
title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")" title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")" body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
[[ $use_sound -eq 1 ]] && sound='sound name ""'
if [[ "$platform" == "Linux" ]]; then if [[ "$platform" == "Linux" ]]; then
local urgency="normal" local urgency="normal"
@ -60,7 +63,7 @@ function _auto_notify_message() {
elif [[ "$platform" == "Darwin" ]]; then elif [[ "$platform" == "Darwin" ]]; then
osascript \ osascript \
-e 'on run argv' \ -e 'on run argv' \
-e 'display notification (item 1 of argv) with title (item 2 of argv)' \ -e "display notification (item 1 of argv) with title (item 2 of argv) $sound" \
-e 'end run' \ -e 'end run' \
"$body" "$title" "$body" "$title"
else else