Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WezTerm support #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions notify.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

plugin_dir="$(dirname $0:A)"

if [[ "$TERM_PROGRAM" == 'iTerm.app' ]] || [[ "$TERM_PROGRAM" == 'Apple_Terminal' ]] || [[ -n "$ITERM_SESSION_ID" ]] || [[ -n "$TERM_SESSION_ID" ]]; then
if [[ "$TERM_PROGRAM" == 'WezTerm' ]]; then
source "$plugin_dir"/wezterm/functions
elif [[ "$TERM_PROGRAM" == 'iTerm.app' ]] || [[ "$TERM_PROGRAM" == 'Apple_Terminal' ]] || [[ -n "$ITERM_SESSION_ID" ]] || [[ -n "$TERM_SESSION_ID" ]]; then
source "$plugin_dir"/applescript/functions
elif [[ "$DISPLAY" != '' ]] && command -v xdotool > /dev/null 2>&1 && command -v wmctrl > /dev/null 2>&1; then
source "$plugin_dir"/xdotool/functions
Expand All @@ -17,7 +19,6 @@ zstyle ':notify:*' error-log /dev/stderr
zstyle ':notify:*' notifier zsh-notify
zstyle ':notify:*' expire-time 0
zstyle ':notify:*' app-name ''
zstyle ':notify:*' notifier zsh-notify
zstyle ':notify:*' success-title '#win (in #{time_elapsed})'
zstyle ':notify:*' success-sound ''
zstyle ':notify:*' success-icon ''
Expand Down
52 changes: 52 additions & 0 deletions wezterm/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# vim: set nowrap filetype=zsh:
#
# is-terminal-active always exits with status 1 since the WezTerm script itself
# handles this detection.
function is-terminal-active() {
# FIXME: re-add tmux support
return 1
}

function zsh-notify() {
local message title time_elapsed type check_focus

if [[ $# -lt 2 ]]; then
echo usage: zsh-notify TYPE TIME_ELAPSED 1>&2
return 1
fi

zstyle -s ':notify:' plugin-dir plugin_dir
source "$plugin_dir"/lib

type="$1"
time_elapsed="$(format-time $2)"
message=$(<&0)

# sound and icon not supported by WezTerm

title=$(notification-title "$type" time_elapsed "$time_elapsed")

check_focus='false'
zstyle -t ':notify:*' check-focus \
&& check_focus='true'

zstyle -s ':notify:' expire-time expire_time

__wezterm_set_user_var NOTIFICATION "$(jq \
-nc \
--arg title "$title" \
--arg message "$message" \
--argjson check_focus "$check_focus" \
--argjson timeout_milliseconds "$expire_time" \
'{
title: $title,
message: $message,
check_focus: $check_focus,
timeout_milliseconds: $timeout_milliseconds
}' \
)"

if zstyle -t ':notify:' activate-terminal; then
wezterm cli activate-pane
fi
}