Skip to content

Commit 202d15d

Browse files
xclaessenirbheek
andcommitted
devenv: Implement prompt for fish and zsh
Co-authored-by: Nirbheek Chauhan <[email protected]>
1 parent d25a7ba commit 202d15d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mesonbuild/mdevenv.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import shutil
77
import sys
88
import itertools
9+
import signal
910
import typing as T
1011

1112
from pathlib import Path
@@ -232,6 +233,26 @@ def run(options: argparse.Namespace) -> int:
232233
tmprc.flush()
233234
args.append("--rcfile")
234235
args.append(tmprc.name)
236+
elif args[0].endswith('fish'):
237+
# Ignore SIGINT while using fish as the shell to make it behave
238+
# like other shells such as bash and zsh.
239+
# See: https://gitlab.freedesktop.org/gstreamer/gst-build/issues/18
240+
signal.signal(signal.SIGINT, lambda _, __: True)
241+
if prompt_prefix:
242+
args.append('--init-command')
243+
prompt_cmd = f'''functions --copy fish_prompt original_fish_prompt
244+
function fish_prompt
245+
echo -n '[{prompt_prefix}] '(original_fish_prompt)
246+
end'''
247+
args.append(prompt_cmd)
248+
elif args[0].endswith('zsh'):
249+
# Let the GC remove the tmp file
250+
tmpdir = tempfile.TemporaryDirectory()
251+
with open(os.path.join(tmpdir.name, '.zshrc'), 'w') as zshrc: # pylint: disable=unspecified-encoding
252+
zshrc.write('[ -e ~/.zshrc ] && . ~/.zshrc\n')
253+
if prompt_prefix:
254+
zshrc.write(f'export PROMPT="[{prompt_prefix}] $PROMPT"\n')
255+
devenv['ZDOTDIR'] = tmpdir.name
235256
if 'DYLD_LIBRARY_PATH' in devenv and macos_sip_enabled():
236257
mlog.warning('macOS System Integrity Protection is enabled: DYLD_LIBRARY_PATH cannot be set in the subshell')
237258
mlog.warning('To fix that, use `meson devenv --dump dev.env && source dev.env`')

0 commit comments

Comments
 (0)