better zsh support

This commit is contained in:
Anthony Scopatz 2016-02-05 23:50:46 -05:00
parent 3e2b3fc08e
commit 5f5c2c71f9
3 changed files with 24 additions and 5 deletions

View file

@ -13,8 +13,13 @@ Current Developments
fail at the first error.
* If the ``setproctitle`` package is installed, the process title will be
set to ``'xonsh'`` rather than the path to the Python interpreter.
* zsh foreign shell interface now supported natively in xonsh, like with Bash.
New ``source-zsh`` alias allows easy access to zsh scripts and functions.
**Changed:** None
**Changed:**
* The ``foreign_shell_data()`` keyword arguments ``envcmd`` and ``aliascmd``
now default to ``None``.
**Deprecated:** None
@ -24,6 +29,7 @@ Current Developments
* Fixed path completion not working for absolute paths or for expanded paths on Windows.
* Fixed issue with hg dirty branches and $PATH.
* Fixed issues related to foreign shell data in files with whitespace in the names.
**Security:** None

View file

@ -77,7 +77,7 @@ def source_foreign(args, stdin=None):
pass # don't change prevcmd if given explicitly
elif os.path.isfile(ns.files_or_code[0]):
# we have filename to source
ns.prevcmd = '{0} {1}'.format(ns.sourcer, ' '.join(ns.files_or_code))
ns.prevcmd = '{0} "{1}"'.format(ns.sourcer, '" "'.join(ns.files_or_code))
elif ns.prevcmd is None:
ns.prevcmd = ' '.join(ns.files_or_code) # code to run, no files
foreign_shell_data.cache_clear() # make sure that we don't get prev src

View file

@ -59,6 +59,17 @@ namefile="${namefile%?}}"
echo $namefile
""".strip()
DEFAULT_ZSH_FUNCSCMD = """
namefile="{"
for name in ${(ok)functions}; do
loc=$(whence -v $name)
loc=${(z)loc}
file=${loc[7,-1]}
namefile="${namefile}\\"${name}\\":\\"${(Q)file:A}\\","
done
namefile="${namefile%?}}"
echo ${namefile}
""".strip()
DEFAULT_ENVCMDS = {
'bash': 'env',
@ -75,8 +86,8 @@ DEFAULT_ALIASCMDS = {
DEFAULT_FUNCSCMDS = {
'bash': DEFAULT_BASH_FUNCSCMD,
'/bin/bash': DEFAULT_BASH_FUNCSCMD,
'zsh': 'echo {}',
'/usr/bin/zsh': 'echo {}',
'zsh': DEFAULT_ZSH_FUNCSCMD,
'/usr/bin/zsh': DEFAULT_ZSH_FUNCSCMD,
}
DEFAULT_SOURCERS = {
'bash': 'source',
@ -231,6 +242,8 @@ def parse_funcs(s, shell, sourcer=None):
for funcname, filename in namefiles.items():
if funcname.startswith('_'):
continue # skip private functions
if not os.path.isabs(filename):
filename = os.path.abspath(filename)
wrapper = ForeignShellFunctionAlias(name=funcname, shell=shell,
sourcer=sourcer, filename=filename)
funcs[funcname] = wrapper
@ -242,7 +255,7 @@ class ForeignShellFunctionAlias(object):
they were aliases. This does not currently support taking stdin.
"""
INPUT = ('{sourcer} {filename}\n'
INPUT = ('{sourcer} "{filename}"\n'
'{funcname} {args}\n')
def __init__(self, name, shell, filename, sourcer=None):