Skip to content

Commit

Permalink
Add: Provide command completion for zsh and bash
Browse files Browse the repository at this point in the history
Allow to install command completions for zsh and bash.
  • Loading branch information
bjoernricks committed Jan 31, 2024
1 parent b752603 commit 0bd6389
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Welcome to **autohooks**!
- [Requirements](#requirements)
- [Plugins](#plugins)
- [Installing autohooks](#installing-autohooks)
- [Command Completion](#command-completion)
- [Maintainer](#maintainer)
- [Contributing](#contributing)
- [License](#license)
Expand Down Expand Up @@ -104,6 +105,33 @@ will use the [pythonpath mode](#pythonpath-mode) by default.
For more details on using [pip], [poetry] or [pipenv] in conjunction with these
modes see the [documentation](https://greenbone.github.io/autohooks).

## Command Completion

`autohooks` comes with support for command line completion in bash
and zsh.

Setup for bash:

```bash
echo "source ~/.autohooks-complete.bash" >> ~/.bashrc
autohooks --print-completion bash > ~/.autohooks-complete.bash
```

Alternatively, you can use the result of the completion command directly with
the eval function of your bash shell:

```bash
eval "$(autohooks --print-completion bash)"
```

Setup for zsh:

```zsh
echo 'fpath=("$HOME/.zsh.d" $fpath)' >> ~/.zsh
mkdir -p ~/.zsh.d/
autohooks --print-completion zsh > ~/.zsh.d/_greenbone_feed_sync
```

## Maintainer

This project is maintained by [Greenbone AG](https://www.greenbone.net/).
Expand Down
3 changes: 3 additions & 0 deletions autohooks/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import argparse
import sys

import shtab

from autohooks.__version__ import __version__ as version
from autohooks.cli.activate import install_hooks
from autohooks.cli.check import check_hooks
Expand All @@ -23,6 +25,7 @@

def main():
parser = argparse.ArgumentParser(description=DESCRIPTION)
shtab.add_argument_to(parser)
parser.add_argument(
"--version",
action="version",
Expand Down
27 changes: 15 additions & 12 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ python = "^3.9"
tomlkit = ">=0.5.11"
pontos = ">=22.8.0"
rich = ">=12.5.1"
shtab = ">=1.6.5"

[tool.poetry.dev-dependencies]
autohooks-plugin-black = ">=21.12.0"
Expand Down

0 comments on commit 0bd6389

Please sign in to comment.