7
7
"""
8
8
import os
9
9
import os .path
10
+ from rez .config import config
11
+ from rez .rex import EscapedString
10
12
from rez .utils .platform_ import platform_
11
13
from rezplugins .shell .sh import SH
12
14
from rez import module_root_path
15
+ from shlex import quote
13
16
14
17
15
18
class Zsh (SH ):
16
- rcfile_arg = '--rcs'
19
+ rcfile_arg = None
17
20
norc_arg = '--no-rcs'
21
+ histfile = "~/.zsh_history"
18
22
19
23
@classmethod
20
24
def name (cls ):
@@ -42,11 +46,8 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
42
46
cls .startup_capabilities (rcfile , norc , stdin , command )
43
47
44
48
files = []
45
- envvar = None
46
- do_rcfile = False
47
49
48
50
if rcfile or norc :
49
- do_rcfile = True
50
51
if rcfile and os .path .exists (os .path .expanduser (rcfile )):
51
52
files .append (rcfile )
52
53
else :
@@ -59,24 +60,50 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
59
60
files .append (file_ )
60
61
61
62
bind_files = [
62
- "~/.zprofile" ,
63
63
"~/.zshrc"
64
64
]
65
65
66
66
return dict (
67
67
stdin = stdin ,
68
68
command = command ,
69
- do_rcfile = do_rcfile ,
70
- envvar = envvar ,
69
+ do_rcfile = False ,
70
+ envvar = None ,
71
71
files = files ,
72
72
bind_files = bind_files ,
73
- source_bind_files = True
73
+ source_bind_files = not norc
74
74
)
75
75
76
76
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%}" )
78
84
completion = os .path .join (module_root_path , "completion" , "complete.zsh" )
79
85
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
80
107
81
108
82
109
def register_plugin ():
0 commit comments