mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
commit
e572c85532
3 changed files with 50 additions and 5 deletions
18
news/zsh.rst
Normal file
18
news/zsh.rst
Normal file
|
@ -0,0 +1,18 @@
|
|||
**Added:**
|
||||
|
||||
* Sourcing foreign shells now have the ``--show`` option, which
|
||||
lets you see when script will be run, and the ``--dryrun``
|
||||
option which prevents the source from actually taking place.
|
||||
Xonsh's foriegn shell API also added these keyword arguments.
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Fixed ``source-zsh`` to work with zsh v5.2.
|
||||
|
||||
**Security:** None
|
|
@ -203,6 +203,10 @@ def _SOURCE_FOREIGN_PARSER():
|
|||
dest='overwrite_aliases',
|
||||
help='flag for whether or not sourced aliases should '
|
||||
'replace the current xonsh aliases.')
|
||||
parser.add_argument('--show', default=False, action='store_true', dest='show',
|
||||
help='Will show the script output.')
|
||||
parser.add_argument('-d', '--dry-run', default=False, action='store_true',
|
||||
dest='dryrun', help='Will not actually source the file.')
|
||||
return parser
|
||||
|
||||
|
||||
|
@ -228,10 +232,15 @@ def source_foreign(args, stdin=None, stdout=None, stderr=None):
|
|||
sourcer=ns.sourcer,
|
||||
use_tmpfile=ns.use_tmpfile,
|
||||
seterrprevcmd=ns.seterrprevcmd,
|
||||
seterrpostcmd=ns.seterrpostcmd)
|
||||
seterrpostcmd=ns.seterrpostcmd,
|
||||
show=ns.show,
|
||||
dryrun=ns.dryrun)
|
||||
if fsenv is None:
|
||||
return (None, 'xonsh: error: Source failed: '
|
||||
'{}\n'.format(ns.prevcmd), 1)
|
||||
if ns.dryrun:
|
||||
return
|
||||
else:
|
||||
msg = 'xonsh: error: Source failed: {}\n'.format(ns.prevcmd)
|
||||
return (None, msg, 1)
|
||||
# apply results
|
||||
env = builtins.__xonsh_env__
|
||||
denv = env.detype()
|
||||
|
|
|
@ -65,11 +65,19 @@ fi
|
|||
echo $namefile"""
|
||||
|
||||
DEFAULT_ZSH_FUNCSCMD = """# get function names
|
||||
autoload -U is-at-least # We'll need to version check zsh
|
||||
namefile="{"
|
||||
for name in ${(ok)functions}; do
|
||||
# force zsh to load the func in order to get the filename,
|
||||
# but use +X so that it isn't executed.
|
||||
autoload +X $name || continue
|
||||
loc=$(whence -v $name)
|
||||
loc=${(z)loc}
|
||||
file=${loc[7,-1]}
|
||||
if is-at-least 5.2; then
|
||||
file=${loc[-1]}
|
||||
else
|
||||
file=${loc[7,-1]}
|
||||
fi
|
||||
namefile="${namefile}\\"${name}\\":\\"${(Q)file:A}\\","
|
||||
done
|
||||
if [[ "{" == "${namefile}" ]]; then
|
||||
|
@ -171,7 +179,8 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
aliascmd=None, extra_args=(), currenv=None,
|
||||
safe=True, prevcmd='', postcmd='', funcscmd=None,
|
||||
sourcer=None, use_tmpfile=False, tmpfile_ext=None,
|
||||
runcmd=None, seterrprevcmd=None, seterrpostcmd=None):
|
||||
runcmd=None, seterrprevcmd=None, seterrpostcmd=None,
|
||||
show=False, dryrun=False):
|
||||
"""Extracts data from a foreign (non-xonsh) shells. Currently this gets
|
||||
the environment, aliases, and functions but may be extended in the future.
|
||||
|
||||
|
@ -228,6 +237,11 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
of the script. For example, this is "if errorlevel 1 exit 1" in
|
||||
cmd.exe. To disable exit-on-error behavior, simply pass in an
|
||||
empty string.
|
||||
show : bool, optional
|
||||
Whether or not to display the script that will be run.
|
||||
dryrun : bool, optional
|
||||
Whether or not to actually run and process the command.
|
||||
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
@ -257,6 +271,10 @@ def foreign_shell_data(shell, interactive=True, login=False, envcmd=None,
|
|||
postcmd=postcmd, funcscmd=funcscmd,
|
||||
seterrprevcmd=seterrprevcmd,
|
||||
seterrpostcmd=seterrpostcmd).strip()
|
||||
if show:
|
||||
print(command)
|
||||
if dryrun:
|
||||
return None, None
|
||||
cmd.append(runcmd)
|
||||
if not use_tmpfile:
|
||||
cmd.append(command)
|
||||
|
|
Loading…
Add table
Reference in a new issue