Add an option :opt:command_on_bell to run an arbitrary command when a bell occurs

Fixes #1660
This commit is contained in:
Kovid Goyal 2019-05-29 09:42:52 +05:30
parent ca2c419c9b
commit 4e9dabfb25
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 37 additions and 11 deletions

View File

@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
0.14.1 [future]
---------------------
- Add an option :opt:`command_on_bell` to run an arbitrary command when
a bell occurs (:iss:`1660`)
- Add support for the underscore key found in some keyboard layouts
(:iss:`1639`)

View File

@ -57,6 +57,13 @@ else:
return ans
def checked_terminfo_dir():
ans = getattr(checked_terminfo_dir, 'ans', None)
if ans is None:
ans = checked_terminfo_dir.ans = terminfo_dir if os.path.isdir(terminfo_dir) else None
return ans
def processes_in_group(grp):
gmap = getattr(process_group_map, 'cached_map', None)
if gmap is None:
@ -149,6 +156,23 @@ class Child:
self.stdin = stdin
self.env = env or {}
@property
def final_env(self):
env = getattr(self, '_final_env', None)
if env is None:
env = self._final_env = default_env().copy()
env.update(self.env)
env['TERM'] = self.opts.term
env['COLORTERM'] = 'truecolor'
if self.cwd:
# needed incase cwd is a symlink, in which case shells
# can use it to display the current directory name rather
# than the resolved path
env['PWD'] = self.cwd
if checked_terminfo_dir():
env['TERMINFO'] = checked_terminfo_dir()
return env
def fork(self):
if self.forked:
return
@ -164,17 +188,7 @@ class Child:
remove_cloexec(stdin_read_fd)
else:
stdin_read_fd = stdin_write_fd = -1
env = default_env().copy()
env.update(self.env)
env['TERM'] = self.opts.term
env['COLORTERM'] = 'truecolor'
if self.cwd:
# needed incase cwd is a symlink, in which case shells
# can use it to display the current directory name rather
# than the resolved path
env['PWD'] = self.cwd
if os.path.isdir(terminfo_dir):
env['TERMINFO'] = terminfo_dir
env = self.final_env
env = tuple('{}={}'.format(k, v) for k, v in env.items())
argv = list(self.argv)
exe = argv[0]

View File

@ -513,6 +513,9 @@ o('bell_on_tab', True, long_text=_('''
Show a bell symbol on the tab if a bell occurs in one of the windows in the
tab and the window is not the currently focused window'''))
o('command_on_bell', 'none', option_type=to_cmdline, long_text=_('''
Program to run when a bell occurs.
'''))
# }}}
g('window') # {{{

View File

@ -306,6 +306,12 @@ class Window:
return get_boss().active_window is self
def on_bell(self):
if self.opts.command_on_bell and self.opts.command_on_bell != ['none']:
import subprocess
import shlex
env = self.child.final_env
env['KITTY_CHILD_CMDLINE'] = ' '.join(map(shlex.quote, self.child.cmdline))
subprocess.Popen(self.opts.command_on_bell, env=env, cwd=self.child.foreground_cwd)
if not self.is_active:
self.needs_attention = True
tab = self.tabref()