mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Merge branch 'feature-windows' into wrywerytwreywery-rbrewer-windows
Conflicts: xonsh/built_ins.py
This commit is contained in:
commit
2fb5ed6cf3
7 changed files with 57 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
|||
"""Tests the xonsh lexer."""
|
||||
from __future__ import unicode_literals, print_function
|
||||
import os
|
||||
import re
|
||||
|
||||
import nose
|
||||
from nose.tools import assert_equal, assert_true, assert_not_in
|
||||
|
@ -8,6 +9,7 @@ from nose.tools import assert_equal, assert_true, assert_not_in
|
|||
from xonsh import built_ins
|
||||
from xonsh.built_ins import Env, reglob, regexpath, helper, superhelper, \
|
||||
ensure_list_of_strs
|
||||
from xonsh.tools import ON_WINDOWS
|
||||
|
||||
def test_env_normal():
|
||||
env = Env(VAR='wakka')
|
||||
|
@ -42,6 +44,15 @@ def test_reglob_tests():
|
|||
for f in testfiles:
|
||||
assert_true(f.startswith('test_'))
|
||||
|
||||
if not ON_WINDOWS:
|
||||
def test_repath_backslash():
|
||||
home = os.path.expanduser('~')
|
||||
exp = os.listdir(home)
|
||||
exp = {p for p in exp if re.match(r'\w\w.*', p)}
|
||||
exp = {os.path.join(home, p) for p in exp}
|
||||
obs = set(regexpath(r'~/\w\w.*'))
|
||||
assert_equal(exp, obs)
|
||||
|
||||
def test_repath_home_itself():
|
||||
exp = os.path.expanduser('~')
|
||||
obs = regexpath('~')
|
||||
|
|
|
@ -6,6 +6,7 @@ from nose.tools import assert_equal
|
|||
|
||||
from xonsh.lexer import Lexer
|
||||
from xonsh.tools import subproc_toks, subexpr_from_unbalanced
|
||||
from xonsh.tools import escape_windows_title_string
|
||||
|
||||
LEXER = Lexer()
|
||||
LEXER.build()
|
||||
|
@ -147,5 +148,20 @@ def test_subexpr_from_unbalanced_parens():
|
|||
yield assert_equal, exp, obs
|
||||
|
||||
|
||||
|
||||
def test_escape_windows_title_string():
|
||||
cases = [
|
||||
('', ''),
|
||||
('foo', 'foo'),
|
||||
('foo&bar', 'foo^&bar'),
|
||||
('foo$?-/_"\\', 'foo$?-/_"\\'),
|
||||
('^&<>|', '^^^&^<^>^|'),
|
||||
('this /?', 'this /.')
|
||||
]
|
||||
for st, esc in cases:
|
||||
obs = escape_windows_title_string(st)
|
||||
yield assert_equal, esc, obs
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
nose.runmodule()
|
||||
|
|
|
@ -106,14 +106,11 @@ DEFAULT_ALIASES = {
|
|||
}
|
||||
|
||||
if ON_WINDOWS:
|
||||
DEFAULT_ALIASES['d'] = ['cmd', '/c', 'dir']
|
||||
DEFAULT_ALIASES['xdir'] = ['cmd', '/c', 'dir']
|
||||
else:
|
||||
DEFAULT_ALIASES['grep'] = ['grep', '--color=auto'],
|
||||
|
||||
if ON_MAC:
|
||||
DEFAULT_ALIASES['dir'] = ['cmd', '/c', 'dir']
|
||||
elif ON_MAC:
|
||||
DEFAULT_ALIASES['ls'] = ['ls', '-G']
|
||||
else:
|
||||
DEFAULT_ALIASES['grep'] = ['grep', '--color=auto']
|
||||
DEFAULT_ALIASES['ls'] = ['ls', '--color=auto', '-v']
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ from collections import Sequence, MutableMapping, Iterable, namedtuple, \
|
|||
MutableSequence, MutableSet
|
||||
|
||||
from xonsh.tools import string_types
|
||||
from xonsh.tools import suggest_commands, XonshError, ON_POSIX
|
||||
from xonsh.tools import suggest_commands, XonshError, ON_POSIX, ON_WINDOWS
|
||||
from xonsh.inspectors import Inspector
|
||||
from xonsh.environ import default_env
|
||||
from xonsh.aliases import DEFAULT_ALIASES, bash_aliases
|
||||
|
@ -274,7 +274,12 @@ def reglob(path, parts=None, i=None):
|
|||
base = ''
|
||||
elif len(parts) > 1:
|
||||
i += 1
|
||||
regex = re.compile(os.path.join(base, parts[i]).replace('\\', '\\\\'))
|
||||
regex = os.path.join(base, parts[i])
|
||||
if ON_WINDOWS:
|
||||
# currently unable to access regex backslash sequences
|
||||
# on Windows due to paths using \.
|
||||
regex = regex.replace('\\', '\\\\')
|
||||
regex = re.compile(regex)
|
||||
files = os.listdir(subdir)
|
||||
files.sort()
|
||||
paths = []
|
||||
|
|
|
@ -221,19 +221,22 @@ def default_env(env=None):
|
|||
# Windows default prompt doesn't work.
|
||||
ctx['PROMPT'] = DEFAULT_PROMPT
|
||||
|
||||
# remove these bash variables which only cause problems.
|
||||
for ev in ['HOME', 'OLDPWD']:
|
||||
if ev in ctx:
|
||||
del ctx[ev]
|
||||
|
||||
# Override path-related bash variables; on Windows bash uses
|
||||
# /c/Windows/System32 syntax instead of C:\\Windows\\System32
|
||||
# which messes up these environment variables for xonsh.
|
||||
if 'PATH' in os.environ:
|
||||
ctx['PATH'] = os.environ['PATH']
|
||||
for ev in ['PATH', 'TEMP', 'TMP']:
|
||||
if ev in os.environ:
|
||||
ctx[ev] = os.environ[ev]
|
||||
elif ev in ctx:
|
||||
del ctx[ev]
|
||||
|
||||
ctx['PWD'] = _get_cwd()
|
||||
|
||||
if 'TEMP' in os.environ:
|
||||
ctx['TEMP'] = os.environ['TEMP']
|
||||
|
||||
if 'TMP' in os.environ:
|
||||
ctx['TMP'] = os.environ['TMP']
|
||||
|
||||
if env is not None:
|
||||
ctx.update(env)
|
||||
|
|
|
@ -9,7 +9,7 @@ from argparse import Namespace
|
|||
|
||||
from xonsh.execer import Execer
|
||||
from xonsh.completer import Completer
|
||||
from xonsh.tools import XonshError, escape_windows_command_string
|
||||
from xonsh.tools import XonshError, escape_windows_title_string
|
||||
from xonsh.tools import ON_WINDOWS
|
||||
from xonsh.environ import xonshrc_context, multiline_prompt, format_prompt
|
||||
|
||||
|
@ -198,7 +198,7 @@ class Shell(Cmd):
|
|||
return
|
||||
t = format_prompt(t)
|
||||
if ON_WINDOWS and 'ANSICON' not in env:
|
||||
t = escape_windows_command_string(t)
|
||||
t = escape_windows_title_string(t)
|
||||
os.system('title {}'.format(t))
|
||||
else:
|
||||
sys.stdout.write("\x1b]2;{0}\x07".format(t))
|
||||
|
|
|
@ -373,11 +373,13 @@ def suggestion_sort_helper(x, y):
|
|||
return lendiff + inx + iny
|
||||
|
||||
|
||||
def escape_windows_command_string(s):
|
||||
s = s.replace('%','%%')
|
||||
for c in ('^', '&', '<', '>', '|', "'", '`', ',', ';', '=', '(', ')'):
|
||||
def escape_windows_title_string(s):
|
||||
"""Returns a string that is usable by the Windows cmd.exe title
|
||||
builtin. The escaping is based on details here and emperical testing:
|
||||
http://www.robvanderwoude.com/escapechars.php
|
||||
"""
|
||||
for c in '^&<>|':
|
||||
s = s.replace(c, '^' + c)
|
||||
s = s.replace('!','^^!')
|
||||
for c in ('[', ']', '.', '"', '.', '*', '?'):
|
||||
s = s.replace(c, '\\' + c)
|
||||
|
||||
s = s.replace('/?', '/.')
|
||||
return s
|
||||
|
|
Loading…
Add table
Reference in a new issue