2020-09-03 22:00:08 +00:00
|
|
|
"""
|
|
|
|
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.
|
|
|
|
|
2020-09-04 14:40:14 +00:00
|
|
|
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
|
|
|
|
|
2020-09-03 22:14:49 +00:00
|
|
|
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
|
2020-09-04 14:40:14 +00:00
|
|
|
|
2020-09-03 22:00:08 +00:00
|
|
|
"""
|
|
|
|
import terminatorlib.plugin as plugin
|
|
|
|
from terminatorlib.terminator import Terminator
|
|
|
|
import gi
|
|
|
|
gi.require_version('Notify', '0.7')
|
2020-09-22 21:48:37 +00:00
|
|
|
from gi.repository import GObject, GLib, Notify, Vte
|
2020-09-03 22:00:08 +00:00
|
|
|
VERSION = '0.1.0'
|
|
|
|
|
2020-09-22 21:48:37 +00:00
|
|
|
### Test for proper signal
|
|
|
|
try:
|
|
|
|
Vte.Terminal().connect('notification-received',lambda *args: None,None)
|
2020-11-09 15:22:43 +00:00
|
|
|
AVAILABLE = ['CommandNotify']
|
2020-09-22 21:48:37 +00:00
|
|
|
except TypeError as e:
|
2020-10-26 16:35:26 +00:00
|
|
|
AVAILABLE = []
|
2020-09-22 21:48:37 +00:00
|
|
|
pass
|
2020-09-03 22:00:08 +00:00
|
|
|
|
2020-09-04 14:29:46 +00:00
|
|
|
class CommandNotify(plugin.Plugin):
|
2020-09-03 22:00:08 +00:00
|
|
|
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
|
|
|
|
|
2020-09-04 16:15:25 +00:00
|
|
|
def update_watched_delayed(self, term, event, arg1 = None):
|
2020-09-03 22:00:08 +00:00
|
|
|
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
|
|
|
|
|