77"""
88import os
99import os .path
10+ from rez .config import config
11+ from rez .rex import EscapedString
1012from rez .utils .platform_ import platform_
1113from rezplugins .shell .sh import SH
1214from rez import module_root_path
15+ from shlex import quote
1316
1417
1518class 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,25 +60,51 @@ 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 )
8086
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
107+
81108
82109def register_plugin ():
83110 if platform_ .name != "windows" :
0 commit comments