Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various improvments to zsh shell plugin #1865

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions src/rezplugins/shell/zsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
"""
import os
import os.path
from rez.config import config
from rez.rex import EscapedString
from rez.utils.platform_ import platform_
from rezplugins.shell.sh import SH
from rez import module_root_path
from shlex import quote


class Zsh(SH):
rcfile_arg = '--rcs'
rcfile_arg = None
norc_arg = '--no-rcs'
histfile = "~/.zsh_history"

@classmethod
def name(cls):
Expand Down Expand Up @@ -42,11 +46,8 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
cls.startup_capabilities(rcfile, norc, stdin, command)

files = []
envvar = None
do_rcfile = False

if rcfile or norc:
do_rcfile = True
if rcfile and os.path.exists(os.path.expanduser(rcfile)):
files.append(rcfile)
else:
Expand All @@ -59,25 +60,51 @@ def get_startup_sequence(cls, rcfile, norc, stdin, command):
files.append(file_)

bind_files = [
"~/.zprofile",
"~/.zshrc"
]

return dict(
stdin=stdin,
command=command,
do_rcfile=do_rcfile,
envvar=envvar,
do_rcfile=False,
envvar=None,
files=files,
bind_files=bind_files,
source_bind_files=True
source_bind_files=not norc
)

def _bind_interactive_rez(self):
super(Zsh, self)._bind_interactive_rez()
if config.set_prompt and self.settings.prompt:
self._addline(r'if [ -z "$REZ_STORED_PROMPT_SH" ]; then export REZ_STORED_PROMPT_SH="$PS1"; fi')
if config.prefix_prompt:
cmd = 'export PS1="%s $REZ_STORED_PROMPT_SH"'
else:
cmd = 'export PS1="$REZ_STORED_PROMPT_SH %s"'
self._addline(cmd % r"%{%B%}$REZ_ENV_PROMPT%{%b%}")
completion = os.path.join(module_root_path, "completion", "complete.zsh")
self.source(completion)

def escape_string(self, value, is_path=False):
value = EscapedString.promote(value)
value = value.expanduser()
result = ''

for is_literal, txt in value.strings:
if is_literal:
txt = quote(txt)
if not txt.startswith("'"):
txt = "'%s'" % txt
else:
if is_path:
txt = self.normalize_paths(txt)

txt = txt.replace('\\', '\\\\')
txt = txt.replace('"', '\\"')
txt = txt.replace("%", "%%")
txt = '"%s"' % txt
result += txt
return result


def register_plugin():
if platform_.name != "windows":
Expand Down
Loading