From ee1bef9bb20db31c20ced33458d4484c73d3f5dd Mon Sep 17 00:00:00 2001 From: Stephen Mackenzie Date: Mon, 5 Aug 2019 22:43:04 -0400 Subject: [PATCH] initial implementation of zsh shell plugin --- src/rezplugins/shell/rezconfig | 3 + src/rezplugins/shell/zsh.py | 104 +++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 src/rezplugins/shell/zsh.py diff --git a/src/rezplugins/shell/rezconfig b/src/rezplugins/shell/rezconfig index 965285417..dee2b4086 100644 --- a/src/rezplugins/shell/rezconfig +++ b/src/rezplugins/shell/rezconfig @@ -10,6 +10,9 @@ csh: tcsh: prompt: '>' +zsh: + prompt: '%' + cmd: prompt: '$G' diff --git a/src/rezplugins/shell/zsh.py b/src/rezplugins/shell/zsh.py new file mode 100644 index 000000000..203c0f404 --- /dev/null +++ b/src/rezplugins/shell/zsh.py @@ -0,0 +1,104 @@ +""" +Zsh shell +""" +import os +import os.path +from rez.shells import Shell +from rez.utils.platform_ import platform_ +from rezplugins.shell.sh import SH +from rez import module_root_path + + +class Zsh(SH): + rcfile_arg = '--rcs' + norc_arg = '--no-rcs' + _executable = None + + @property + def executable(cls): + if cls._executable is None: + cls._executable = Shell.find_executable('zsh') + return cls._executable + + @classmethod + def name(cls): + return 'zsh' + + @classmethod + def startup_capabilities(cls, rcfile=False, norc=False, stdin=False, + command=False): + if norc: + cls._overruled_option('rcfile', 'norc', rcfile) + rcfile = False + if command is not None: + cls._overruled_option('stdin', 'command', stdin) + cls._overruled_option('rcfile', 'command', rcfile) + stdin = False + rcfile = False + if stdin: + cls._overruled_option('rcfile', 'stdin', rcfile) + rcfile = False + return (rcfile, norc, stdin, command) + + @classmethod + def get_startup_sequence(cls, rcfile, norc, stdin, command): + 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: + for file_ in ( + "~/.zprofile", + "~/.zlogin", + "~/.zshrc", + "~/.zshenv"): + if os.path.exists(os.path.expanduser(file_)): + files.append(file_) + + bind_files = [ + "~/.zprofile", + "~/.zshrc" + ] + + return dict( + stdin=stdin, + command=command, + do_rcfile=do_rcfile, + envvar=envvar, + files=files, + bind_files=bind_files, + source_bind_files=True + ) + + def _bind_interactive_rez(self): + super(Zsh, self)._bind_interactive_rez() + completion = os.path.join(module_root_path, "completion", "complete.sh") + self.source(completion) + + +def register_plugin(): + if platform_.name != "windows": + return Zsh + + +# Copyright 2013-2016 Allan Johns. +# +# This library is free software: you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation, either +# version 3 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see .