Skip to content

Commit 823e3bb

Browse files
authored
Add shell completions by shtab (#121)
vimdoc --print-completion bash | sudo tee /usr/share/bash-completion/completions/vimdoc vimdoc --print-completion tcsh | sudo tee /etc/profile.d/vimdoc.completion.csh vimdoc --print-completion zsh | sudo tee /usr/share/zsh/site-functions/_vimdoc
1 parent 58b7b8b commit 823e3bb

File tree

4 files changed

+144
-6
lines changed

4 files changed

+144
-6
lines changed

.gitignore

Lines changed: 126 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,127 @@
1-
*.pyc
2-
/MANIFEST
3-
/build/
41
/deb_dist/
5-
/dist/
2+
3+
# Python.gitignore:
4+
# Byte-compiled / optimized / DLL files
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# C extensions
10+
*.so
11+
12+
# Distribution / packaging
13+
.Python
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
pip-wheel-metadata/
27+
share/python-wheels/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
MANIFEST
32+
33+
# PyInstaller
34+
# Usually these files are written by a python script from a template
35+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
36+
*.manifest
37+
*.spec
38+
39+
# Installer logs
40+
pip-log.txt
41+
pip-delete-this-directory.txt
42+
43+
# Unit test / coverage reports
44+
htmlcov/
45+
.tox/
46+
.nox/
47+
.coverage
48+
.coverage.*
49+
.cache
50+
nosetests.xml
51+
coverage.xml
52+
*.cover
53+
.hypothesis/
54+
.pytest_cache/
55+
56+
# Translations
57+
*.mo
58+
*.pot
59+
60+
# Django stuff:
61+
*.log
62+
local_settings.py
63+
db.sqlite3
64+
db.sqlite3-journal
65+
66+
# Flask stuff:
67+
instance/
68+
.webassets-cache
69+
70+
# Scrapy stuff:
71+
.scrapy
72+
73+
# Sphinx documentation
74+
docs/_build/
75+
76+
# PyBuilder
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
.python-version
88+
89+
# pipenv
90+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
91+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
92+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
93+
# install all needed dependencies.
94+
#Pipfile.lock
95+
96+
# celery beat schedule file
97+
celerybeat-schedule
98+
99+
# SageMath parsed files
100+
*.sage.py
101+
102+
# Environments
103+
.env
104+
.venv
105+
env/
106+
venv/
107+
ENV/
108+
env.bak/
109+
venv.bak/
110+
111+
# Spyder project settings
112+
.spyderproject
113+
.spyproject
114+
115+
# Rope project settings
116+
.ropeproject
117+
118+
# mkdocs documentation
119+
/site
120+
121+
# mypy
122+
.mypy_cache/
123+
.dmypy.json
124+
dmypy.json
125+
126+
# Pyre type checker
127+
.pyre/

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
scripts=[
3434
'scripts/vimdoc',
3535
],
36+
extras_require={'completion': ['shtab']},
3637
package_data={'vimdoc': ['VERSION.txt']},
3738
classifiers=[
3839
'Development Status :: 3 - Alpha',

vimdoc/_shtab.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FILE = None
2+
DIRECTORY = DIR = None
3+
4+
5+
def add_argument_to(parser, *args, **kwargs):
6+
from argparse import Action
7+
Action.complete = None # type: ignore
8+
return parser

vimdoc/args.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
import vimdoc
55

6+
try:
7+
import shtab
8+
except ImportError:
9+
from . import _shtab as shtab
10+
611

712
def Source(path):
813
if not os.path.isdir(path):
@@ -11,7 +16,9 @@ def Source(path):
1116
raise argparse.ArgumentTypeError('Cannot access {}'.format(path))
1217
return path
1318

14-
parser = argparse.ArgumentParser(description='Generate vim helpfiles')
15-
parser.add_argument('plugin', type=Source, metavar='PLUGIN')
19+
20+
parser = argparse.ArgumentParser('vimdoc', description='Generate vim helpfiles')
21+
shtab.add_argument_to(parser)
22+
parser.add_argument('plugin', type=Source, metavar='PLUGIN').complete = shtab.DIR
1623
parser.add_argument('--version', action='version',
1724
version='%(prog)s ' + vimdoc.__version__)

0 commit comments

Comments
 (0)