mirror of
https://github.com/philippdieter/zsh-auto-notify.git
synced 2025-10-13 03:58:44 +00:00
Add option to enable forwarding of notifications over SSH
Option AUTO_NOTIFY_ENABLE_SSH has been added to enable and disable forwarding of notifications to local client for long running commands issued over SSH on remote servers.
This commit is contained in:
parent
76a527a66b
commit
cbea4aeb58
13
README.rst
13
README.rst
@ -129,6 +129,19 @@ NOTE: This configuration option currently only works for Linux.
|
|||||||
# Set notification expiry to 10 seconds
|
# Set notification expiry to 10 seconds
|
||||||
export AUTO_NOTIFY_EXPIRE_TIME=10000
|
export AUTO_NOTIFY_EXPIRE_TIME=10000
|
||||||
|
|
||||||
|
**Notification Forwarding Over SSH**
|
||||||
|
|
||||||
|
You can configure whether notifications will be forwarded to SSH client by setting the environment
|
||||||
|
variable ``AUTO_NOTIFY_ENABLE_SSH`` to enable ("1") or disable ("0"). The default value is set to 0.
|
||||||
|
NOTE: This configuration option currently only works for Linux.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
# Enable notification forwarding to SSH client
|
||||||
|
export AUTO_NOTIFY_ENABLE_SSH=1
|
||||||
|
# Disable notification forwarding to SSH client
|
||||||
|
export AUTO_NOTIFY_ENABLE_SSH=0
|
||||||
|
|
||||||
|
|
||||||
**Ignored Commands**
|
**Ignored Commands**
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ export AUTO_NOTIFY_VERSION="0.10.2"
|
|||||||
# Threshold in seconds for when to automatically show a notification
|
# Threshold in seconds for when to automatically show a notification
|
||||||
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
|
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
|
||||||
export AUTO_NOTIFY_THRESHOLD=10
|
export AUTO_NOTIFY_THRESHOLD=10
|
||||||
|
# Enable or disable notifications for SSH sessions (0 = disabled, 1 = enabled)
|
||||||
|
[[ -z "$AUTO_NOTIFY_ENABLE_SSH" ]] &&
|
||||||
|
export AUTO_NOTIFY_ENABLE_SSH=0
|
||||||
|
|
||||||
# List of commands/programs to ignore sending notifications for
|
# List of commands/programs to ignore sending notifications for
|
||||||
[[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
|
[[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
|
||||||
@ -68,7 +71,19 @@ function _auto_notify_message() {
|
|||||||
if [[ -n "$icon" ]]; then
|
if [[ -n "$icon" ]]; then
|
||||||
arguments+=("--icon=$icon")
|
arguments+=("--icon=$icon")
|
||||||
fi
|
fi
|
||||||
notify-send ${arguments[@]}
|
|
||||||
|
# Check if the script is running over SSH
|
||||||
|
if [[ -n "${SSH_CLIENT}" || -n "${SSH_CONNECTION}" ]]; then
|
||||||
|
# Extract the client IP address from environment
|
||||||
|
local client_ip="${SSH_CLIENT%% *}"
|
||||||
|
[[ -z "$client_ip" ]] && client_ip="${SSH_CONNECTION%% *}"
|
||||||
|
|
||||||
|
# Forward the notify-send command to the client machine via SSH
|
||||||
|
ssh "${USER}@${client_ip}" "$(printf '%q ' notify-send "${arguments[@]}")"
|
||||||
|
else
|
||||||
|
# If not running over SSH, send notification locally
|
||||||
|
notify-send "${arguments[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
elif [[ "$platform" == "Darwin" ]]; then
|
elif [[ "$platform" == "Darwin" ]]; then
|
||||||
osascript \
|
osascript \
|
||||||
@ -90,8 +105,8 @@ function _is_auto_notify_ignored() {
|
|||||||
# Remove leading whitespace
|
# Remove leading whitespace
|
||||||
target_command="$(echo "$target_command" | sed -e 's/^ *//')"
|
target_command="$(echo "$target_command" | sed -e 's/^ *//')"
|
||||||
|
|
||||||
# If the command is being run over SSH, then ignore it
|
# Ignore the command if running over SSH and AUTO_NOTIFY_ENABLE_SSH is disabled
|
||||||
if [[ -n ${SSH_CLIENT-} || -n ${SSH_TTY-} || -n ${SSH_CONNECTION-} ]]; then
|
if [[ -n ${SSH_CLIENT-} || -n ${SSH_TTY-} || -n ${SSH_CONNECTION-} ]] && [[ "${AUTO_NOTIFY_ENABLE_SSH-1}" == "0" ]]; then
|
||||||
print "yes"
|
print "yes"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user