Merge pull request #2018 from xonsh/xompletions

Xompletions
This commit is contained in:
Anthony Scopatz 2016-12-16 10:37:19 -08:00 committed by GitHub
commit 25cf37a090
7 changed files with 79 additions and 1 deletions

View file

@ -18,3 +18,4 @@ All of the ways that xonsh completes you.
path path
python python
tools tools
xompletions

View file

@ -0,0 +1,11 @@
.. _xonsh_completers_xompletions:
*********************************************************
Completion Xompletions (``xonsh.completers.xompletions``)
*********************************************************
.. automodule:: xonsh.completers.xompletions
:members:
:undoc-members:
:inherited-members:

View file

@ -378,7 +378,7 @@ def make_events():
title, docstr = docstr.split('\n', 1) title, docstr = docstr.split('\n', 1)
docstr = docstr.strip() docstr = docstr.strip()
under = '.' * (len(title) + 4) under = '.' * (len(title) + 4)
s += sec.format(low=var.lower(), title=title, under=under, s += sec.format(low=name.lower(), title=title, under=under,
docstr=docstr) docstr=docstr)
s = s[:-9] s = s[:-9]
fname = os.path.join(os.path.dirname(__file__), 'eventsbody') fname = os.path.join(os.path.dirname(__file__), 'eventsbody')

13
news/xompletion.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:**
* Completion for ``xonsh`` builtin functions ``xontrib`` and ``xonfig``
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:** None
**Security:** None

View file

@ -12,6 +12,8 @@ else:
_sys.modules['xonsh.completers.pip'] = __amalgam__ _sys.modules['xonsh.completers.pip'] = __amalgam__
tools = __amalgam__ tools = __amalgam__
_sys.modules['xonsh.completers.tools'] = __amalgam__ _sys.modules['xonsh.completers.tools'] = __amalgam__
xompletions = __amalgam__
_sys.modules['xonsh.completers.xompletions'] = __amalgam__
_aliases = __amalgam__ _aliases = __amalgam__
_sys.modules['xonsh.completers._aliases'] = __amalgam__ _sys.modules['xonsh.completers._aliases'] = __amalgam__
commands = __amalgam__ commands = __amalgam__

View file

@ -11,6 +11,7 @@ from xonsh.completers.python import (complete_python, complete_import,
complete_python_mode) complete_python_mode)
from xonsh.completers.commands import complete_skipper from xonsh.completers.commands import complete_skipper
from xonsh.completers.completer import complete_completer from xonsh.completers.completer import complete_completer
from xonsh.completers.xompletions import complete_xonfig, complete_xontrib
def default_completers(): def default_completers():
@ -23,6 +24,8 @@ def default_completers():
('pip', complete_pip), ('pip', complete_pip),
('cd', complete_cd), ('cd', complete_cd),
('rmdir', complete_rmdir), ('rmdir', complete_rmdir),
('xonfig', complete_xonfig),
('xontrib', complete_xontrib),
('bash', complete_from_bash), ('bash', complete_from_bash),
('man', complete_from_man), ('man', complete_from_man),
('import', complete_import), ('import', complete_import),

View file

@ -0,0 +1,48 @@
"""Provides completions for xonsh internal utilities"""
import xonsh.xontribs as xx
import xonsh.tools as xt
def complete_xonfig(prefix, line, start, end, ctx):
"""Completion for ``xonfig``"""
args = line.split(' ')
if len(args) == 0 or args[0] != 'xonfig':
return None
curix = args.index(prefix)
if curix == 1:
possible = {'info', 'wizard', 'styles', 'colors', '-h'}
elif curix == 2 and args[1] == 'colors':
possible = set(xt.color_style_names())
else:
raise StopIteration
return {i for i in possible if i.startswith(prefix)}
def _list_installed_xontribs():
meta = xx.xontrib_metadata()
installed = []
for md in meta['xontribs']:
name = md['name']
spec = xx.find_xontrib(name)
if spec is not None:
installed.append(spec.name.rsplit('.')[-1])
return installed
def complete_xontrib(prefix, line, start, end, ctx):
"""Completion for ``xontrib``"""
args = line.split(' ')
if len(args) == 0 or args[0] != 'xontrib':
return None
curix = args.index(prefix)
if curix == 1:
possible = {'list', 'load'}
elif curix == 2:
if args[1] == 'load':
possible = _list_installed_xontribs()
else:
raise StopIteration
return {i for i in possible if i.startswith(prefix)}