support autocd path highlight

This commit is contained in:
BlahGeek 2016-09-13 11:29:49 +08:00
parent acb0bfe3cb
commit f9abbc8a05
2 changed files with 15 additions and 2 deletions

View file

@ -109,6 +109,9 @@ def test_path():
])
check_token('cd X={}'.format(test_dir), [(Name.Constant, test_dir)])
with builtins.__xonsh_env__.swap(AUTO_CD=True):
check_token(test_dir, [(Name.Constant, test_dir)])
def test_subproc_args():
check_token('cd 192.168.0.1', [(Text, '192.168.0.1')])

View file

@ -37,6 +37,13 @@ def _command_is_valid(cmd):
(os.path.isfile(cmd_abspath) and os.access(cmd_abspath, os.X_OK))
def _command_is_autocd(cmd):
if not builtins.__xonsh_env__['AUTO_CD']:
return False
cmd_abspath = os.path.abspath(os.path.expanduser(cmd))
return os.path.isdir(cmd_abspath)
def subproc_cmd_callback(_, match):
"""Yield Builtin token if match contains valid command,
otherwise fallback to fallback lexer.
@ -148,9 +155,12 @@ class XonshLexer(PythonLexer):
yield m.start(1), Whitespace, m.group(1)
cmd = m.group(2)
cmd_is_valid = _command_is_valid(cmd)
cmd_is_autocd = _command_is_autocd(cmd)
if cmd_is_valid:
yield m.start(2), Name.Builtin, cmd
if cmd_is_valid or cmd_is_autocd:
yield (m.start(2),
Name.Builtin if cmd_is_valid else Name.Constant,
cmd)
start = m.end(2)
state = ('subproc', )