mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Skip existing foreign shell aliases
This commit is contained in:
parent
27a37758c7
commit
182b7c6433
3 changed files with 37 additions and 3 deletions
16
news/no-fs-over.rst
Normal file
16
news/no-fs-over.rst
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
**Added:** None
|
||||||
|
|
||||||
|
**Changed:**
|
||||||
|
|
||||||
|
* Sourcing foreign shells will now safely skip applying aliases
|
||||||
|
with the same name as existing xonsh aliases by default.
|
||||||
|
This prevents accitidentally overwriting important xonsh standard
|
||||||
|
aliases, such as ``cd``.
|
||||||
|
|
||||||
|
**Deprecated:** None
|
||||||
|
|
||||||
|
**Removed:** None
|
||||||
|
|
||||||
|
**Fixed:** None
|
||||||
|
|
||||||
|
**Security:** None
|
|
@ -199,10 +199,14 @@ def _SOURCE_FOREIGN_PARSER():
|
||||||
parser.add_argument('--seterrpostcmd', default=None, dest='seterrpostcmd',
|
parser.add_argument('--seterrpostcmd', default=None, dest='seterrpostcmd',
|
||||||
help='command(s) to set exit-on-error after all'
|
help='command(s) to set exit-on-error after all'
|
||||||
'other commands.')
|
'other commands.')
|
||||||
|
parser.add_argument('--overwrite-aliases', default=False, action='store_true',
|
||||||
|
dest='overwrite_aliases',
|
||||||
|
help='flag for whether or not sourced aliases should '
|
||||||
|
'replace the current xonsh aliases.')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def source_foreign(args, stdin=None):
|
def source_foreign(args, stdin=None, stdout=None, stderr=None):
|
||||||
"""Sources a file written in a foreign shell language."""
|
"""Sources a file written in a foreign shell language."""
|
||||||
ns = _SOURCE_FOREIGN_PARSER.parse_args(args)
|
ns = _SOURCE_FOREIGN_PARSER.parse_args(args)
|
||||||
if ns.prevcmd is not None:
|
if ns.prevcmd is not None:
|
||||||
|
@ -244,7 +248,13 @@ def source_foreign(args, stdin=None):
|
||||||
for k, v in fsaliases.items():
|
for k, v in fsaliases.items():
|
||||||
if k in baliases and v == baliases[k]:
|
if k in baliases and v == baliases[k]:
|
||||||
continue # no change from original
|
continue # no change from original
|
||||||
baliases[k] = v
|
elif ns.overwite_aliases or k not in baliases:
|
||||||
|
baliases[k] = v
|
||||||
|
else:
|
||||||
|
msg = ('Skipping application of {0!r} alias from {1!r} '
|
||||||
|
'since it shares a name with an existing xonsh alias. '
|
||||||
|
'Use "--overwrite-alias" option to apply it anyway.')
|
||||||
|
print(msg.format(k, ns.shell), file=stderr)
|
||||||
|
|
||||||
|
|
||||||
def source_alias(args, stdin=None):
|
def source_alias(args, stdin=None):
|
||||||
|
|
|
@ -1134,8 +1134,16 @@ def static_config_run_control(filename, ctx, env, execer=None, login=True):
|
||||||
windows_foreign_env_fixes(foreign_env)
|
windows_foreign_env_fixes(foreign_env)
|
||||||
foreign_env_fixes(foreign_env)
|
foreign_env_fixes(foreign_env)
|
||||||
env.update(foreign_env)
|
env.update(foreign_env)
|
||||||
|
aliase = builtins.aliases
|
||||||
foreign_aliases = load_foreign_aliases(config=filename, issue_warning=True)
|
foreign_aliases = load_foreign_aliases(config=filename, issue_warning=True)
|
||||||
builtins.aliases.update(foreign_aliases)
|
for k, v in foreign_aliases.items():
|
||||||
|
if k in aliases:
|
||||||
|
msg = ('Skipping application of {0!r} alias from foreign shell '
|
||||||
|
'(loaded from {1!r}) since it shares a name with an '
|
||||||
|
'existing xonsh alias.')
|
||||||
|
print(msg.format(k, filename))
|
||||||
|
else:
|
||||||
|
aliases[k] = v
|
||||||
# load xontribs
|
# load xontribs
|
||||||
names = conf.get('xontribs', ())
|
names = conf.get('xontribs', ())
|
||||||
for name in names:
|
for name in names:
|
||||||
|
|
Loading…
Add table
Reference in a new issue