- autoload functions aren't surrounded in an addition function { } - export cross platform notify function - control notify behavior with zstylespull/443/head
parent
f99f480eee
commit
36559d9978
@ -0,0 +1,27 @@
|
|||||||
|
# Pops up a notification with the provided arg.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Alex Reece <awreece@gmail.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
# I actually want all the args as one string.
|
||||||
|
message="$*"
|
||||||
|
|
||||||
|
case "$OSTYPE" in
|
||||||
|
(darwin*)
|
||||||
|
if is-callable terminal-notifier && \
|
||||||
|
! zstyle -t ':prezto:module:notify' force-growl; then
|
||||||
|
terminal-notifier >/dev/null -message $message
|
||||||
|
elif is-callable growlnotify; then
|
||||||
|
growlnotify --message $message
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
(linux-gnu*)
|
||||||
|
notify-send $message
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
@ -0,0 +1,40 @@
|
|||||||
|
# Sends a notification that the last command completed.
|
||||||
|
#
|
||||||
|
# Assumes $terminal_window_id is the id of the terminals window and that
|
||||||
|
# last_comand module is loaded.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Alex Reece <awreece@gmail.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
message=$(printf "Command \"%s\" finished (%d) after %s." \
|
||||||
|
$last_command \
|
||||||
|
$last_command_status \
|
||||||
|
$(time_to_human $last_command_time))
|
||||||
|
|
||||||
|
# We duplicate a lot of the functionality of notify, but it means we can
|
||||||
|
# have this nifty callback to select the window that finished.
|
||||||
|
|
||||||
|
# TODO(awreece) Add support for user defined callback.
|
||||||
|
case "$OSTYPE" in
|
||||||
|
(darwin*)
|
||||||
|
if is-callable terminal-notifier &&
|
||||||
|
! zstyle -t ':prezto:module:notify' force-growl; then
|
||||||
|
callback="osascript -e 'tell application \"Terminal\"' \
|
||||||
|
-e 'activate' \
|
||||||
|
-e 'set index of window id $terminal_window_id to 1' \
|
||||||
|
-e 'end tell'"
|
||||||
|
terminal-notifier -message $message -execute $callback >/dev/null
|
||||||
|
elif is-callable growlnotify; then
|
||||||
|
growlnotify --message $message
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
(linux-gnu*)
|
||||||
|
notify-send "Command finished" $message
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
@ -0,0 +1,35 @@
|
|||||||
|
# Check if it makes sense to load the notify module.
|
||||||
|
#
|
||||||
|
# Checks for requirements, that it is an xsession, etc.
|
||||||
|
#
|
||||||
|
# Authors:
|
||||||
|
# Alex Reece <awreece@gmail.com>
|
||||||
|
#
|
||||||
|
|
||||||
|
if ! zstyle -t ':prezto:module:notify' auto-notify; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$OSTYPE" in
|
||||||
|
(darwin*)
|
||||||
|
# TODO(awreece) Disable if ssh with no windows?
|
||||||
|
is-callable terminal-notifier || is-callable growlnotify
|
||||||
|
;;
|
||||||
|
(linux-gnu*)
|
||||||
|
# Disable if don't have X.
|
||||||
|
if [[ -z $XAUTHORITY ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We need both of these functions to operate.
|
||||||
|
if (( ! $+commands[notify-send] || ! $+commands[xprop] )); then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
(*)
|
||||||
|
# If we don't know, then just disable.
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
@ -1,34 +0,0 @@
|
|||||||
# Check if it makes sense to load the notify module.
|
|
||||||
#
|
|
||||||
# Checks for requirements, that it is an xsession, etc.
|
|
||||||
#
|
|
||||||
# Authors:
|
|
||||||
# Alex Reece <awreece@gmail.com>
|
|
||||||
#
|
|
||||||
|
|
||||||
function should_load_notify_module {
|
|
||||||
case "$OSTYPE" in
|
|
||||||
(darwin*)
|
|
||||||
# For now, always enable on mac osx.
|
|
||||||
# TODO(awreece) Disable if ssh with no windows?
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
(linux-gnu*)
|
|
||||||
# Disable if don't have X.
|
|
||||||
if [[ -z $XAUTHORITY ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# We need both of these functions to operate.
|
|
||||||
if (( ! $+commands[notify-send] || ! $+commands[xprop] )); then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
# If we don't know, then just disable.
|
|
||||||
return 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
}
|
|
Loading…
Reference in new issue