Skip to content

Commit c425977

Browse files
committed
Various improvments to zsh shell plugin
Signed-off-by: James Horsley <[email protected]>
1 parent 8f6f987 commit c425977

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/rezplugins/shell/zsh.py

+36-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
"""
88
import os
99
import os.path
10+
from rez.config import config
11+
from rez.rex import EscapedString
1012
from rez.utils.platform_ import platform_
1113
from rezplugins.shell.sh import SH
1214
from rez import module_root_path
15+
from shlex import quote
1316

1417

1518
class Zsh(SH):
16-
rcfile_arg = '--rcs'
19+
rcfile_arg = None
1720
norc_arg = '--no-rcs'
21+
histfile = "~/.zsh_history"
1822

1923
@classmethod
2024
def name(cls):
@@ -42,11 +46,8 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
4246
cls.startup_capabilities(rcfile, norc, stdin, command)
4347

4448
files = []
45-
envvar = None
46-
do_rcfile = False
4749

4850
if rcfile or norc:
49-
do_rcfile = True
5051
if rcfile and os.path.exists(os.path.expanduser(rcfile)):
5152
files.append(rcfile)
5253
else:
@@ -59,24 +60,50 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
5960
files.append(file_)
6061

6162
bind_files = [
62-
"~/.zprofile",
6363
"~/.zshrc"
6464
]
6565

6666
return dict(
6767
stdin=stdin,
6868
command=command,
69-
do_rcfile=do_rcfile,
70-
envvar=envvar,
69+
do_rcfile=False,
70+
envvar=None,
7171
files=files,
7272
bind_files=bind_files,
73-
source_bind_files=True
73+
source_bind_files=not norc
7474
)
7575

7676
def _bind_interactive_rez(self):
77-
super(Zsh, self)._bind_interactive_rez()
77+
if config.set_prompt and self.settings.prompt:
78+
self._addline(r'if [ -z "$REZ_STORED_PROMPT_SH" ]; then export REZ_STORED_PROMPT_SH="$PS1"; fi')
79+
if config.prefix_prompt:
80+
cmd = 'export PS1="%s $REZ_STORED_PROMPT_SH"'
81+
else:
82+
cmd = 'export PS1="$REZ_STORED_PROMPT_SH %s"'
83+
self._addline(cmd % r"%{%B%}$REZ_ENV_PROMPT%{%b%}")
7884
completion = os.path.join(module_root_path, "completion", "complete.zsh")
7985
self.source(completion)
86+
87+
def escape_string(self, value, is_path=False):
88+
value = EscapedString.promote(value)
89+
value = value.expanduser()
90+
result = ''
91+
92+
for is_literal, txt in value.strings:
93+
if is_literal:
94+
txt = quote(txt)
95+
if not txt.startswith("'"):
96+
txt = "'%s'" % txt
97+
else:
98+
if is_path:
99+
txt = self.normalize_paths(txt)
100+
101+
txt = txt.replace('\\', '\\\\')
102+
txt = txt.replace('"', '\\"')
103+
txt = txt.replace("%", "%%")
104+
txt = '"%s"' % txt
105+
result += txt
106+
return result
80107

81108

82109
def register_plugin():

0 commit comments

Comments
 (0)