commit
2465f821ba
@ -0,0 +1,59 @@
|
|||||||
|
import re
|
||||||
|
try:
|
||||||
|
import argcomplete
|
||||||
|
except ImportError:
|
||||||
|
|
||||||
|
class FakeModule:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _fun(*args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __getattr__(self, _):
|
||||||
|
return self._fun
|
||||||
|
|
||||||
|
argcomplete = FakeModule()
|
||||||
|
|
||||||
|
from . import repo
|
||||||
|
|
||||||
|
|
||||||
|
def autocomplete(parser):
|
||||||
|
argcomplete.autocomplete(parser)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseCompleter(object):
|
||||||
|
|
||||||
|
def __init__(self, conf):
|
||||||
|
self.conf = conf
|
||||||
|
|
||||||
|
def __call__(self, **kwargs):
|
||||||
|
try:
|
||||||
|
return self._complete(**kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
argcomplete.warn(e)
|
||||||
|
|
||||||
|
|
||||||
|
class CiteKeyCompletion(BaseCompleter):
|
||||||
|
|
||||||
|
def _complete(self, **kwargs):
|
||||||
|
rp = repo.Repository(self.conf)
|
||||||
|
return rp.citekeys
|
||||||
|
|
||||||
|
|
||||||
|
class CiteKeyOrTagCompletion(BaseCompleter):
|
||||||
|
|
||||||
|
def _complete(self, **kwargs):
|
||||||
|
rp = repo.Repository(self.conf)
|
||||||
|
return rp.citekeys.union(rp.get_tags())
|
||||||
|
|
||||||
|
|
||||||
|
class TagModifierCompletion(BaseCompleter):
|
||||||
|
|
||||||
|
regxp = r"[^:+-]*$" # prefix of tag after last separator
|
||||||
|
|
||||||
|
def _complete(self, prefix, **kwargs):
|
||||||
|
tags = repo.Repository(self.conf).get_tags()
|
||||||
|
start, _ = re.search(self.regxp, prefix).span()
|
||||||
|
partial_expr = prefix[:start]
|
||||||
|
t_prefix = prefix[start:]
|
||||||
|
return [partial_expr + t for t in tags if t.startswith(t_prefix)]
|
@ -1,2 +1,3 @@
|
|||||||
from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf
|
from .conf import (get_confpath, load_default_conf, load_conf, save_conf,
|
||||||
|
check_conf, ConfigurationNotFound)
|
||||||
from .conf import default_open_cmd, post_process_conf
|
from .conf import default_open_cmd, post_process_conf
|
||||||
|
Loading…
Reference in new issue