Skip to content

Commit 0bd6389

Browse files
committed
Add: Provide command completion for zsh and bash
Allow to install command completions for zsh and bash.
1 parent b752603 commit 0bd6389

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Welcome to **autohooks**!
1919
- [Requirements](#requirements)
2020
- [Plugins](#plugins)
2121
- [Installing autohooks](#installing-autohooks)
22+
- [Command Completion](#command-completion)
2223
- [Maintainer](#maintainer)
2324
- [Contributing](#contributing)
2425
- [License](#license)
@@ -104,6 +105,33 @@ will use the [pythonpath mode](#pythonpath-mode) by default.
104105
For more details on using [pip], [poetry] or [pipenv] in conjunction with these
105106
modes see the [documentation](https://greenbone.github.io/autohooks).
106107

108+
## Command Completion
109+
110+
`autohooks` comes with support for command line completion in bash
111+
and zsh.
112+
113+
Setup for bash:
114+
115+
```bash
116+
echo "source ~/.autohooks-complete.bash" >> ~/.bashrc
117+
autohooks --print-completion bash > ~/.autohooks-complete.bash
118+
```
119+
120+
Alternatively, you can use the result of the completion command directly with
121+
the eval function of your bash shell:
122+
123+
```bash
124+
eval "$(autohooks --print-completion bash)"
125+
```
126+
127+
Setup for zsh:
128+
129+
```zsh
130+
echo 'fpath=("$HOME/.zsh.d" $fpath)' >> ~/.zsh
131+
mkdir -p ~/.zsh.d/
132+
autohooks --print-completion zsh > ~/.zsh.d/_greenbone_feed_sync
133+
```
134+
107135
## Maintainer
108136

109137
This project is maintained by [Greenbone AG](https://www.greenbone.net/).

autohooks/cli/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import argparse
77
import sys
88

9+
import shtab
10+
911
from autohooks.__version__ import __version__ as version
1012
from autohooks.cli.activate import install_hooks
1113
from autohooks.cli.check import check_hooks
@@ -23,6 +25,7 @@
2325

2426
def main():
2527
parser = argparse.ArgumentParser(description=DESCRIPTION)
28+
shtab.add_argument_to(parser)
2629
parser.add_argument(
2730
"--version",
2831
action="version",

poetry.lock

Lines changed: 15 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ python = "^3.9"
4141
tomlkit = ">=0.5.11"
4242
pontos = ">=22.8.0"
4343
rich = ">=12.5.1"
44+
shtab = ">=1.6.5"
4445

4546
[tool.poetry.dev-dependencies]
4647
autohooks-plugin-black = ">=21.12.0"

0 commit comments

Comments
 (0)