mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
Merge pull request #550 from scopatz/prevcmd
Logic bug in source-foreign alias
This commit is contained in:
commit
12cb3329f7
4 changed files with 23 additions and 16 deletions
|
@ -113,10 +113,6 @@ applicable.
|
||||||
- xonsh.environ.DEFAULT_PROMPT
|
- xonsh.environ.DEFAULT_PROMPT
|
||||||
- The prompt text. May contain keyword arguments which are auto-formatted,
|
- The prompt text. May contain keyword arguments which are auto-formatted,
|
||||||
see `Customizing the Prompt <tutorial.html#customizing-the-prompt>`_.
|
see `Customizing the Prompt <tutorial.html#customizing-the-prompt>`_.
|
||||||
* - PROMPT_TOOLKIT_STYLES
|
|
||||||
- ``None``
|
|
||||||
- This is a mapping of user-specified styles for prompt-toolkit. See the
|
|
||||||
prompt-toolkit documentation for more details. If None, this is skipped.
|
|
||||||
* - PROMPT_TOOLKIT_COLORS
|
* - PROMPT_TOOLKIT_COLORS
|
||||||
- ``{}``
|
- ``{}``
|
||||||
- This is a mapping of from color names to HTML color codes. Whenever
|
- This is a mapping of from color names to HTML color codes. Whenever
|
||||||
|
@ -125,6 +121,10 @@ applicable.
|
||||||
represent that color, instead of its default. If a color is not
|
represent that color, instead of its default. If a color is not
|
||||||
specified here, prompt-toolkit uses the colors from
|
specified here, prompt-toolkit uses the colors from
|
||||||
``xonsh.tools._PT_COLORS``.
|
``xonsh.tools._PT_COLORS``.
|
||||||
|
* - PROMPT_TOOLKIT_STYLES
|
||||||
|
- ``None``
|
||||||
|
- This is a mapping of user-specified styles for prompt-toolkit. See the
|
||||||
|
prompt-toolkit documentation for more details. If None, this is skipped.
|
||||||
* - PUSHD_MINUS
|
* - PUSHD_MINUS
|
||||||
- ``False``
|
- ``False``
|
||||||
- Flag for directory pushing functionality. False is the normal behaviour.
|
- Flag for directory pushing functionality. False is the normal behaviour.
|
||||||
|
@ -133,13 +133,14 @@ applicable.
|
||||||
- Whether or not to supress directory stack manipulation output.
|
- Whether or not to supress directory stack manipulation output.
|
||||||
* - SHELL_TYPE
|
* - SHELL_TYPE
|
||||||
- ``'prompt_toolkit'`` if on Windows, otherwise ``'readline'``
|
- ``'prompt_toolkit'`` if on Windows, otherwise ``'readline'``
|
||||||
- Which shell is used. Currently two shell types are supported: ``'readline'`` that
|
- Which shell is used. Currently two base shell types are supported:
|
||||||
is backed by Python's readline module, and ``'prompt_toolkit'`` that uses
|
``'readline'`` that is backed by Python's readline module, and
|
||||||
external library of the same name. For using prompt_toolkit shell you need
|
``'prompt_toolkit'`` that uses external library of the same name.
|
||||||
to have
|
To use the prompt_toolkit shell you need to have
|
||||||
`prompt_toolkit <https://github.com/jonathanslenders/python-prompt-toolkit>`_
|
`prompt_toolkit <https://github.com/jonathanslenders/python-prompt-toolkit>`_
|
||||||
library installed. To specify which shell should be used, do so in the run
|
library installed. To specify which shell should be used, do so in the run
|
||||||
control file.
|
control file. Additionally, you may also set this value to ``'random'``
|
||||||
|
to get a random choice of shell type on startup.
|
||||||
* - SUGGEST_COMMANDS
|
* - SUGGEST_COMMANDS
|
||||||
- ``True``
|
- ``True``
|
||||||
- When a user types an invalid command, xonsh will try to offer suggestions of
|
- When a user types an invalid command, xonsh will try to offer suggestions of
|
||||||
|
@ -190,8 +191,8 @@ applicable.
|
||||||
- ``('/etc/xonshrc', '~/.xonshrc')`` (Linux and OSX)
|
- ``('/etc/xonshrc', '~/.xonshrc')`` (Linux and OSX)
|
||||||
``('%ALLUSERSPROFILE%\xonsh\xonshrc', '~/.xonshrc')`` (Windows)
|
``('%ALLUSERSPROFILE%\xonsh\xonshrc', '~/.xonshrc')`` (Windows)
|
||||||
- A tuple of the locations of run control files, if they exist. User defined
|
- A tuple of the locations of run control files, if they exist. User defined
|
||||||
run control file will supercede values set in system-wide control file if there
|
run control file will supercede values set in system-wide control file if there
|
||||||
is a naming collision.
|
is a naming collision.
|
||||||
* - XONSH_CONFIG_DIR
|
* - XONSH_CONFIG_DIR
|
||||||
- ``$XDG_CONFIG_HOME/xonsh``
|
- ``$XDG_CONFIG_HOME/xonsh``
|
||||||
- This is location where xonsh configuration information is stored.
|
- This is location where xonsh configuration information is stored.
|
||||||
|
|
|
@ -73,10 +73,13 @@ def source_foreign(args, stdin=None):
|
||||||
"""Sources a file written in a foreign shell language."""
|
"""Sources a file written in a foreign shell language."""
|
||||||
parser = _ensure_source_foreign_parser()
|
parser = _ensure_source_foreign_parser()
|
||||||
ns = parser.parse_args(args)
|
ns = parser.parse_args(args)
|
||||||
if ns.prevcmd is not None and not os.path.isfile(ns.files_or_code[0]):
|
if ns.prevcmd is not None:
|
||||||
ns.prevcmd = ' '.join(ns.files_or_code)
|
pass # don't change prevcmd if given explicitly
|
||||||
elif ns.prevcmd is None:
|
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
|
foreign_shell_data.cache_clear() # make sure that we don't get prev src
|
||||||
fsenv, fsaliases = foreign_shell_data(shell=ns.shell, login=ns.login,
|
fsenv, fsaliases = foreign_shell_data(shell=ns.shell, login=ns.login,
|
||||||
interactive=ns.interactive, envcmd=ns.envcmd,
|
interactive=ns.interactive, envcmd=ns.envcmd,
|
||||||
|
|
|
@ -61,10 +61,10 @@ parser.add_argument('-D',
|
||||||
default=None)
|
default=None)
|
||||||
parser.add_argument('--shell-type',
|
parser.add_argument('--shell-type',
|
||||||
help='What kind of shell should be used. '
|
help='What kind of shell should be used. '
|
||||||
'Possible options: readline, prompt_toolkit. '
|
'Possible options: readline, prompt_toolkit, random. '
|
||||||
'Warning! If set this overrides $SHELL_TYPE variable.',
|
'Warning! If set this overrides $SHELL_TYPE variable.',
|
||||||
dest='shell_type',
|
dest='shell_type',
|
||||||
choices=('readline', 'prompt_toolkit'),
|
choices=('readline', 'prompt_toolkit', 'random'),
|
||||||
default=None)
|
default=None)
|
||||||
parser.add_argument('file',
|
parser.add_argument('file',
|
||||||
metavar='script-file',
|
metavar='script-file',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""The xonsh shell"""
|
"""The xonsh shell"""
|
||||||
|
import random
|
||||||
import builtins
|
import builtins
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
|
@ -31,6 +32,8 @@ class Shell(object):
|
||||||
if shell_type is not None:
|
if shell_type is not None:
|
||||||
env['SHELL_TYPE'] = shell_type
|
env['SHELL_TYPE'] = shell_type
|
||||||
shell_type = env.get('SHELL_TYPE')
|
shell_type = env.get('SHELL_TYPE')
|
||||||
|
if shell_type == 'random':
|
||||||
|
shell_type = random.choice(('readline', 'prompt_toolkit'))
|
||||||
if shell_type == 'prompt_toolkit':
|
if shell_type == 'prompt_toolkit':
|
||||||
if not is_prompt_toolkit_available():
|
if not is_prompt_toolkit_available():
|
||||||
warn('prompt_toolkit is not available, using readline instead.')
|
warn('prompt_toolkit is not available, using readline instead.')
|
||||||
|
|
Loading…
Add table
Reference in a new issue