mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
more
This commit is contained in:
parent
e6ef990dae
commit
a55b760516
3 changed files with 25 additions and 20 deletions
|
@ -7,9 +7,12 @@ import pathlib
|
|||
import builtins
|
||||
import subprocess
|
||||
|
||||
from xonsh.platform import ON_WINDOWS
|
||||
import xonsh.lazyasd as xl
|
||||
import xonsh.platform as xp
|
||||
|
||||
RE_DASHF = re.compile(r'-F\s+(\w+)')
|
||||
|
||||
RE_DASHF = xl.LazyObject(lambda: re.compile(r'-F\s+(\w+)'),
|
||||
globals(), 'RE_DASHF')
|
||||
|
||||
INITED = False
|
||||
|
||||
|
@ -32,13 +35,6 @@ for ((i=0;i<${{#COMPREPLY[*]}};i++)) do echo ${{COMPREPLY[i]}}; done
|
|||
"""
|
||||
|
||||
|
||||
if ON_WINDOWS:
|
||||
from xonsh.platform import windows_bash_command
|
||||
BASH_COMMAND = windows_bash_command()
|
||||
else:
|
||||
BASH_COMMAND = 'bash'
|
||||
|
||||
|
||||
def update_bash_completion():
|
||||
global BASH_COMPLETE_FUNCS, BASH_COMPLETE_FILES, BASH_COMPLETE_HASH
|
||||
global CACHED_FUNCS, CACHED_FILES, CACHED_HASH, INITED
|
||||
|
@ -113,7 +109,7 @@ def complete_from_bash(prefix, line, begidx, endidx, ctx):
|
|||
end=endidx + 1, prefix=prefix, prev=shlex.quote(prev))
|
||||
try:
|
||||
out = subprocess.check_output(
|
||||
[BASH_COMMAND], input=script, universal_newlines=True,
|
||||
[xp.bash_command()], input=script, universal_newlines=True,
|
||||
stderr=subprocess.PIPE, env=builtins.__xonsh_env__.detype())
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
out = ''
|
||||
|
@ -168,8 +164,9 @@ def _load_bash_complete_files():
|
|||
def _source_completions(source):
|
||||
try:
|
||||
return subprocess.check_output(
|
||||
[BASH_COMMAND], input='\n'.join(source), universal_newlines=True,
|
||||
env=builtins.__xonsh_env__.detype(), stderr=subprocess.DEVNULL)
|
||||
[xp.bash_command()], input='\n'.join(source),
|
||||
universal_newlines=True, env=builtins.__xonsh_env__.detype(),
|
||||
stderr=subprocess.DEVNULL)
|
||||
except FileNotFoundError:
|
||||
return ''
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import os
|
||||
import builtins
|
||||
|
||||
from xonsh.tools import executables_in
|
||||
from xonsh.platform import ON_WINDOWS
|
||||
import xonsh.tools as xt
|
||||
import xonsh.platform as xp
|
||||
|
||||
from xonsh.completers.tools import get_filter_function
|
||||
|
||||
SKIP_TOKENS = {'sudo', 'time', 'timeit', 'which', 'showcmd', 'man'}
|
||||
|
@ -16,14 +17,13 @@ def complete_command(cmd, line, start, end, ctx):
|
|||
out = {s + space
|
||||
for s in builtins.__xonsh_commands_cache__
|
||||
if get_filter_function()(s, cmd)}
|
||||
if ON_WINDOWS:
|
||||
out |= {i
|
||||
for i in executables_in('.')
|
||||
if xp.ON_WINDOWS:
|
||||
out |= {i for i in xt.executables_in('.')
|
||||
if i.startswith(cmd)}
|
||||
base = os.path.basename(cmd)
|
||||
if os.path.isdir(base):
|
||||
out |= {os.path.join(base, i)
|
||||
for i in executables_in(base)
|
||||
for i in xt.executables_in(base)
|
||||
if i.startswith(cmd)}
|
||||
return out
|
||||
|
||||
|
@ -51,6 +51,5 @@ def complete_skipper(cmd, line, start, end, ctx):
|
|||
start - len(first) - 1,
|
||||
end - len(first) - 1,
|
||||
ctx)
|
||||
|
||||
else:
|
||||
return set()
|
||||
|
|
|
@ -227,7 +227,7 @@ def git_for_windows_path():
|
|||
|
||||
@functools.lru_cache(1)
|
||||
def windows_bash_command():
|
||||
"""Determines teh command for Bash on windows."""
|
||||
"""Determines the command for Bash on windows."""
|
||||
# Check that bash is on path otherwise try the default directory
|
||||
# used by Git for windows
|
||||
wbc = 'bash'
|
||||
|
@ -247,6 +247,15 @@ def windows_bash_command():
|
|||
# Environment variables defaults
|
||||
#
|
||||
|
||||
@functools.lru_cache(1)
|
||||
def bash_command():
|
||||
"""Determines the command for Bash on the current plaform."""
|
||||
if ON_WINDOWS:
|
||||
bc = windows_bash_command()
|
||||
else:
|
||||
bc = 'bash'
|
||||
return bc
|
||||
|
||||
|
||||
@lazyobject
|
||||
def BASH_COMPLETIONS_DEFAULT():
|
||||
|
|
Loading…
Add table
Reference in a new issue