Skip to content

Commit a4eaab6

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

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
@@ -224,6 +225,26 @@ def run(options: argparse.Namespace) -> int:
224225
tmprc.flush()
225226
args.append("--rcfile")
226227
args.append(tmprc.name)
228+
elif args[0].endswith('fish'):
229+
# Ignore SIGINT while using fish as the shell to make it behave
230+
# like other shells such as bash and zsh.
231+
# See: https://gitlab.freedesktop.org/gstreamer/gst-build/issues/18
232+
signal.signal(signal.SIGINT, lambda _, __: True)
233+
if prompt_prefix:
234+
args.append('--init-command')
235+
prompt_cmd = f'''functions --copy fish_prompt original_fish_prompt
236+
function fish_prompt
237+
echo -n '[{prompt_prefix}] '(original_fish_prompt)
238+
end'''
239+
args.append(prompt_cmd)
240+
elif args[0].endswith('zsh'):
241+
# Let the GC remove the tmp file
242+
tmpdir = tempfile.TemporaryDirectory()
243+
with open(os.path.join(tmpdir.name, '.zshrc'), 'w', encoding='utf-8') as zshrc:
244+
zshrc.write('[ -e ~/.zshrc ] && . ~/.zshrc\n')
245+
if prompt_prefix:
246+
zshrc.write(f'export PROMPT="[{prompt_prefix}] $PROMPT"\n')
247+
devenv['ZDOTDIR'] = tmpdir.name
227248
else:
228249
# Try to resolve executable using devenv's PATH
229250
abs_path = shutil.which(args[0], path=devenv.get('PATH', None))

0 commit comments

Comments
 (0)