Skip to content

Commit

Permalink
Use argcomplete to auto-generate autocompletion (#269)
Browse files Browse the repository at this point in the history
* use argcomplete to auto-generate autocompletion

Signed-off-by: Tin Lai <[email protected]>

* update readme on auto-completion instruction

Signed-off-by: Tin Lai <[email protected]>

* Revert replacing autocompletion files

---------

Signed-off-by: Tin Lai <[email protected]>
  • Loading branch information
soraxas authored Dec 11, 2023
1 parent 2b70e72 commit 1b6319b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: dist test install clean twine
.PHONY: dist test install clean twine auto-completion

install:
pip3 install -e .
Expand All @@ -10,3 +10,10 @@ twine:
twine upload dist/*
clean:
git clean -fdx
auto-completion:
@ mkdir -p auto-completion/bash
@ mkdir -p auto-completion/zsh
@ mkdir -p auto-completion/fish
register-python-argcomplete gita -s bash > auto-completion/bash/.gita-completion.bash
register-python-argcomplete gita -s zsh > auto-completion/zsh/_gita
register-python-argcomplete gita -s fish > auto-completion/fish/gita.fish
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ the branch color to work.
See [this stackoverflow post](https://stackoverflow.com/questions/51680709/colored-text-output-in-powershell-console-using-ansi-vt100-codes) for details.

## Auto-completion

You can download the generated auto-completion file in the following locations for your specific shell. Alternatively, if you have installed `argcomplete` on your system, you can also directly run `eval "$(register-python-argcomplete gita -s SHELL)"` (e.g. `SHELL` as `bash`/`zsh`) in your dotfile.

### Bash
Download [.gita-completion.bash](https://github.com/nosarthur/gita/blob/master/.gita-completion.bash) and source it in shell.

Expand All @@ -168,6 +171,9 @@ Add `autoload -U +X bashcompinit && bashcompinit` in .zshrc and source the zsh f
- [_gita](https://github.com/nosarthur/gita/blob/master/contrib.completion/zsh/_gita_).
Completion more Zsh style. Copy it in a folder and add this folder path in `FPATH` variable. This completion file doesn't take account to command from cmds.json

### Fish
Download [gita.fish](https://github.com/nosarthur/gita/tree/master/auto-completion/fish/gita.fish) and place it in `~/.config/fish/completions/`


## <a name='superman'></a> Superman mode

Expand Down
17 changes: 17 additions & 0 deletions auto-completion/fish/gita.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

function __fish_gita_complete
set -x _ARGCOMPLETE 1
set -x _ARGCOMPLETE_DFS \t
set -x _ARGCOMPLETE_IFS \n
set -x _ARGCOMPLETE_SUPPRESS_SPACE 1
set -x _ARGCOMPLETE_SHELL fish
set -x COMP_LINE (commandline -p)
set -x COMP_POINT (string length (commandline -cp))
set -x COMP_TYPE
if set -q _ARC_DEBUG
gita 8>&1 9>&2 1>&9 2>&1
else
gita 8>&1 9>&2 1>/dev/null 2>&1
end
end
complete --command gita -f -a '(__fish_gita_complete)'
2 changes: 2 additions & 0 deletions gita/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sys
import csv
import argparse
import argcomplete
import subprocess
from functools import partial
import pkg_resources
Expand Down Expand Up @@ -807,6 +808,7 @@ def main(argv=None):
cmd = cmd.split()
sp.set_defaults(func=f_git_cmd, cmd=cmd)

argcomplete.autocomplete(p)
args = p.parse_args(argv)

args.async_blacklist = {
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
author_email="[email protected]",
entry_points={"console_scripts": ["gita = gita.__main__:main"]},
python_requires="~=3.6",
install_requires=["argcomplete"],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand Down

0 comments on commit 1b6319b

Please sign in to comment.