Skip to content

Commit 4633d2a

Browse files
agattidpgeorge
authored andcommitted
tools/ci.sh: Add zsh and fish shell completion support.
This commit adds custom command completion functions for both the zsh and fish shell. The behaviour for those new completions follow the existing completion for the bash shell, including the way to generate the completion alias (with appropriately named command line switches). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent d1caa9d commit 4633d2a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

docs/develop/gettingstarted.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,15 @@ If you use the bash shell, you can add a ``ci`` command with tab completion:
338338

339339
.. code-block:: bash
340340
341-
$ eval `tools/ci.sh --bash-completion`
341+
$ eval $(tools/ci.sh --bash-completion)
342+
343+
For the zsh shell, replace ``--bash-completion`` with ``--zsh-completion``.
344+
For the fish shell, replace ``--bash-completion`` with ``--fish-completion``.
345+
346+
Then, typing:
347+
348+
.. code-block:: bash
349+
342350
$ ci unix_cov<tab>
343351
344352
This will complete the ci step name to ``unix_coverage_``.

tools/ci.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,14 @@ function _ci_bash_completion {
10491049
echo "alias ci=\"$(readlink -f "$0")\"; complete -W '$(grep '^function ci_' $0 | awk '{print $2}' | sed 's/^ci_//')' ci"
10501050
}
10511051

1052+
function _ci_zsh_completion {
1053+
echo "alias ci=\"$(readlink -f "$0"\"); _complete_mpy_ci_zsh() { compadd $(grep '^function ci_' $0 | awk '{sub(/^ci_/,"",$2); print $2}' | tr '\n' ' ') }; autoload -Uz compinit; compinit; compdef _complete_mpy_ci_zsh $(readlink -f "$0")"
1054+
}
1055+
1056+
function _ci_fish_completion {
1057+
echo "alias ci=\"$(readlink -f "$0"\"); complete -c ci -p $(readlink -f "$0") -f -a '$(grep '^function ci_' $(readlink -f "$0") | awk '{sub(/^ci_/,"",$2); print $2}' | tr '\n' ' ')'"
1058+
}
1059+
10521060
function _ci_main {
10531061
case "$1" in
10541062
(-h|-?|--help)
@@ -1057,6 +1065,12 @@ function _ci_main {
10571065
(--bash-completion)
10581066
_ci_bash_completion
10591067
;;
1068+
(--zsh-completion)
1069+
_ci_zsh_completion
1070+
;;
1071+
(--fish-completion)
1072+
_ci_fish_completion
1073+
;;
10601074
(-*)
10611075
echo "Unknown option: $1" 1>&2
10621076
exit 1

0 commit comments

Comments
 (0)