got bash completion working for "git annex" not just "git-annex"
This needs a patch to git to cause the git-annex completion to be auto-loaded when completing "git annex <tab>". Otherwise, it will only load when "git-annex" is tab completed. Once loaded, it works for both uses. I've submitted the git patch to the git mailing list.
This commit is contained in:
parent
0de63300d6
commit
386b8c394e
4 changed files with 29 additions and 18 deletions
2
Makefile
2
Makefile
|
@ -49,7 +49,7 @@ install: build install-docs Build/InstallDesktopFile
|
||||||
ln -sf git-annex $(DESTDIR)$(PREFIX)/bin/git-annex-shell
|
ln -sf git-annex $(DESTDIR)$(PREFIX)/bin/git-annex-shell
|
||||||
./Build/InstallDesktopFile $(PREFIX)/bin/git-annex || true
|
./Build/InstallDesktopFile $(PREFIX)/bin/git-annex || true
|
||||||
install -d $(DESTDIR)$(PREFIX)/share/bash-completion/completions
|
install -d $(DESTDIR)$(PREFIX)/share/bash-completion/completions
|
||||||
./git-annex --bash-completion-script git-annex > $(DESTDIR)$(PREFIX)/share/bash-completion/completions/git-annex
|
install -m 0644 bash-completion.bash $(DESTDIR)$(PREFIX)/share/bash-completion/completions/git-annex
|
||||||
|
|
||||||
test: git-annex
|
test: git-annex
|
||||||
./git-annex test
|
./git-annex test
|
||||||
|
|
25
bash-completion.bash
Normal file
25
bash-completion.bash
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Use git-annex's built-in bash completion
|
||||||
|
# This bash completion is generated by the option parser, so it covers all
|
||||||
|
# commands, all options, and will never go out of date!
|
||||||
|
source <(git-annex --bash-completion-script git-annex)
|
||||||
|
|
||||||
|
# Called by git's bash completion script when completing "git annex"
|
||||||
|
_git_annex() {
|
||||||
|
local cmdline
|
||||||
|
CMDLINE=(--bash-completion-index $(($COMP_CWORD - 1)))
|
||||||
|
|
||||||
|
local seen_git
|
||||||
|
local seen_annex
|
||||||
|
for arg in ${COMP_WORDS[@]}; do
|
||||||
|
if [ "$arg" = git ] && [ -z "$seen_git" ]; then
|
||||||
|
seen_git=1
|
||||||
|
CMDLINE=(${CMDLINE[@]} --bash-completion-word git-annex)
|
||||||
|
elif [ "$arg" = annex ] && [ -z "$seen_annex" ]; then
|
||||||
|
seen_annex=1
|
||||||
|
else
|
||||||
|
CMDLINE=(${CMDLINE[@]} --bash-completion-word $arg)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
COMPREPLY=( $(git-annex "${CMDLINE[@]}") )
|
||||||
|
}
|
|
@ -3,13 +3,11 @@
|
||||||
subject="""comment 5"""
|
subject="""comment 5"""
|
||||||
date="2015-07-15T15:44:11Z"
|
date="2015-07-15T15:44:11Z"
|
||||||
content="""
|
content="""
|
||||||
I've recently added built-in bash completion to git-annex, which is output
|
I've recently added built-in bash completion to git-annex, enabled by the
|
||||||
by the `--bash-completion-script` option. It knows about all sub-commands,
|
`bash-completion.bash` file. It knows about all sub-commands,
|
||||||
and all options, and will automatically always be up-to-date with the
|
and all options, and will automatically always be up-to-date with the
|
||||||
argument parser!
|
argument parser!
|
||||||
|
|
||||||
Currently, it only works for completing "git-annex", not "git annex".
|
Currently, it only works for completing "git-annex", not "git annex".
|
||||||
Supporting the latter would probably require some hacks to git's own bash
|
I have submitted a patch to git's bash completion to make the latter work.
|
||||||
completion code, or possibly a smart way to hook into it.. Help with that
|
|
||||||
would be appreciated.
|
|
||||||
"""]]
|
"""]]
|
||||||
|
|
|
@ -763,18 +763,6 @@ may not be explicitly listed on their individual man pages.
|
||||||
|
|
||||||
Overrides git configuration settings. May be specified multiple times.
|
Overrides git configuration settings. May be specified multiple times.
|
||||||
|
|
||||||
# COMMAND-LINE TAB COMPLETION
|
|
||||||
|
|
||||||
To enable bash completion, paste this into your shell prompt:
|
|
||||||
|
|
||||||
source <(git-annex --bash-completion-script git-annex)
|
|
||||||
|
|
||||||
The output of "git-annex --bash-completion-script git-annex" can also
|
|
||||||
be written to a bash completion file so bash loads it automatically.
|
|
||||||
|
|
||||||
This bash completion is generated by the option parser, so it covers all
|
|
||||||
commands, all options, and will never go out of date!
|
|
||||||
|
|
||||||
# CONFIGURATION VIA .git/config
|
# CONFIGURATION VIA .git/config
|
||||||
|
|
||||||
Like other git commands, git-annex is configured via `.git/config`.
|
Like other git commands, git-annex is configured via `.git/config`.
|
||||||
|
|
Loading…
Reference in a new issue