-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bash and Zsh completion scripts (#22646)
This PR adds contrib scripts for bash and zsh completion. Simply call: ```bash source contrib/autocompletion/bash_autocomplete ``` or for Zsh: ```bash source contrib/autocompletion/zsh_autocomplete ``` Signed-off-by: Andrew Thornton <art27@cantab.net> --------- Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: a1012112796 <1012112796@qq.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
- Loading branch information
1 parent
4de5cd9
commit 43405c3
Showing
8 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Bash and Zsh completion | ||
======================= | ||
|
||
From within the gitea root run: | ||
|
||
```bash | ||
source contrib/autocompletion/bash_autocomplete | ||
``` | ||
|
||
or for zsh run: | ||
|
||
```bash | ||
source contrib/autocompletion/zsh_autocomplete | ||
``` | ||
|
||
These scripts will check if gitea is on the path and if so add autocompletion for `gitea`. Or if not autocompletion will work for `./gitea`. | ||
If gitea has been installed as a different program pass in the `PROG` environment variable to set the correct program name. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#! /bin/bash | ||
# Heavily inspired by https://github.com/urfave/cli | ||
|
||
_cli_bash_autocomplete() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) | ||
else | ||
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) | ||
fi | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
fi | ||
} | ||
|
||
if [ -z "$PROG" ] && [ ! "$(command -v gitea &> /dev/null)" ] ; then | ||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete gitea | ||
elif [ -z "$PROG" ]; then | ||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete ./gitea | ||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PWD/gitea" | ||
else | ||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PROG" | ||
unset PROG | ||
fi | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#compdef ${PROG:=gitea} | ||
|
||
|
||
# Heavily inspired by https://github.com/urfave/cli | ||
|
||
_cli_zsh_autocomplete() { | ||
|
||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") | ||
else | ||
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") | ||
fi | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
|
||
return | ||
} | ||
|
||
if [ -z $PROG ] ; then | ||
compdef _cli_zsh_autocomplete gitea | ||
else | ||
compdef _cli_zsh_autocomplete $(basename $PROG) | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters