From 6220af803030b6bb135d795c754cd7bd2b9338f1 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Thu, 3 Sep 2020 18:00:08 -0400 Subject: [PATCH 1/7] add plugin to notify when command is complete --- terminatorlib/plugins/command_notify.py | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 terminatorlib/plugins/command_notify.py diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py new file mode 100644 index 00000000..8d94c1bd --- /dev/null +++ b/terminatorlib/plugins/command_notify.py @@ -0,0 +1,58 @@ +""" +This plugin will launch a notification when a long running command finishes +and terminal is not active. + +It uses VTE's special sequence which is sent when shell prints the prompt. It +depends on https://github.com/GNOME/vte/blob/vte-0-58/src/vte.sh (which has to +be added to /etc/profile.d) and you need to ensure `__vte_prompt_command` is +executed on `PROMPT_COMMAND` in Bash or in `precmd_functions` in Zsh. + +Code is written in Hy and generated to Python3. +""" +import terminatorlib.plugin as plugin +from terminatorlib.terminator import Terminator +import gi +gi.require_version('Notify', '0.7') +from gi.repository import GObject, GLib, Notify +VERSION = '0.1.0' +AVAILABLE = ['LongCommandNotify'] + + +class LongCommandNotify(plugin.Plugin): + capabilities = ['command_watch'] + watched = set() + + def __init__(self): + self.update_watched() + Notify.init('Terminator') + return None + + def update_watched(self): + """Updates the list of watched terminals""" + new_watched = set() + for term in Terminator().terminals: + new_watched.add(term) + if not term in self.watched: + vte = term.get_vte() + term.connect('focus-out', self.update_watched_delayed, None) + vte.connect('focus-out-event', self. + update_watched_delayed, None) + notify = vte.connect( + 'notification-received', self.notification_received, term) + else: + notify = None + self.watched = new_watched + + def update_watched_delayed(self): + + def add_watch(self): + self.update_watched() + return False + GObject.idle_add(add_watch, self) + return True + + def notification_received(self, vte, summary, body, _terminator_term): + Notify.Notification.new(summary, body, 'terminator').show( + ) if not vte.has_focus() else None + return None + From 93c11691041c3b34e4fd3bacf898bf0d242294fc Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Thu, 3 Sep 2020 18:14:49 -0400 Subject: [PATCH 2/7] update description --- terminatorlib/plugins/command_notify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index 8d94c1bd..613ab338 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -7,7 +7,8 @@ be added to /etc/profile.d) and you need to ensure `__vte_prompt_command` is executed on `PROMPT_COMMAND` in Bash or in `precmd_functions` in Zsh. -Code is written in Hy and generated to Python3. +Code is adapted from https://github.com/x4lldux/terminator-long-cmd-notify +Thanks to @xll4dux on Github for the code and his permission to use it """ import terminatorlib.plugin as plugin from terminatorlib.terminator import Terminator From 752311b8fe3dd0b6818392464966c242cc5915fc Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Thu, 3 Sep 2020 18:18:08 -0400 Subject: [PATCH 3/7] Tweak Name so it does not interfere with @xll4dux plugin --- terminatorlib/plugins/command_notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index 613ab338..a32a4bfb 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -16,7 +16,7 @@ gi.require_version('Notify', '0.7') from gi.repository import GObject, GLib, Notify VERSION = '0.1.0' -AVAILABLE = ['LongCommandNotify'] +AVAILABLE = ['CommandNotify'] class LongCommandNotify(plugin.Plugin): From bad60a03f2686b415096f78074ce2f572a82df82 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Fri, 4 Sep 2020 10:29:46 -0400 Subject: [PATCH 4/7] tweak class name as well --- terminatorlib/plugins/command_notify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index a32a4bfb..c7575b06 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -19,7 +19,7 @@ AVAILABLE = ['CommandNotify'] -class LongCommandNotify(plugin.Plugin): +class CommandNotify(plugin.Plugin): capabilities = ['command_watch'] watched = set() From 8cd329c5c5694ce0dca987e84a9efe74800d04db Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Fri, 4 Sep 2020 10:40:14 -0400 Subject: [PATCH 5/7] added some more documentation --- terminatorlib/plugins/command_notify.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index c7575b06..65bc0926 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -7,8 +7,12 @@ be added to /etc/profile.d) and you need to ensure `__vte_prompt_command` is executed on `PROMPT_COMMAND` in Bash or in `precmd_functions` in Zsh. +This plugin also relies on the widely distributed vte patches to wire in a +`notification_received` signal to catch the OSC escape sequence in the prompt + Code is adapted from https://github.com/x4lldux/terminator-long-cmd-notify Thanks to @xll4dux on Github for the code and his permission to use it + """ import terminatorlib.plugin as plugin from terminatorlib.terminator import Terminator From 98d11928c60853c97f078765b7248e68e8cbee38 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Fri, 4 Sep 2020 12:15:25 -0400 Subject: [PATCH 6/7] add proper arguments --- terminatorlib/plugins/command_notify.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index 65bc0926..64b3b48b 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -48,8 +48,8 @@ def update_watched(self): notify = None self.watched = new_watched - def update_watched_delayed(self): - + def update_watched_delayed(self, term, event, arg1 = None): + print('foo: %s / bar: %s / baz: %s' % (str(term),str(event),arg1)) def add_watch(self): self.update_watched() return False From dad40bb1b23a1235cf6cd3c285a534142e20ee48 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Tue, 22 Sep 2020 17:48:37 -0400 Subject: [PATCH 7/7] do not advertise as AVAILABLE if the signal is not present in the Vte library --- terminatorlib/plugins/command_notify.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/terminatorlib/plugins/command_notify.py b/terminatorlib/plugins/command_notify.py index 64b3b48b..83849332 100644 --- a/terminatorlib/plugins/command_notify.py +++ b/terminatorlib/plugins/command_notify.py @@ -18,10 +18,15 @@ from terminatorlib.terminator import Terminator import gi gi.require_version('Notify', '0.7') -from gi.repository import GObject, GLib, Notify +from gi.repository import GObject, GLib, Notify, Vte VERSION = '0.1.0' -AVAILABLE = ['CommandNotify'] +### Test for proper signal +try: + Vte.Terminal().connect('notification-received',lambda *args: None,None) + AVAILABLE = ['CommandNotify'] +except TypeError as e: + pass class CommandNotify(plugin.Plugin): capabilities = ['command_watch'] @@ -49,7 +54,6 @@ def update_watched(self): self.watched = new_watched def update_watched_delayed(self, term, event, arg1 = None): - print('foo: %s / bar: %s / baz: %s' % (str(term),str(event),arg1)) def add_watch(self): self.update_watched() return False