Package: guix-patches;
Reported by: Oleg Pykhalov <go.wigust <at> gmail.com>
Date: Fri, 2 Jun 2023 22:20:01 UTC
Severity: normal
Tags: patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 63860 in the body.
You can then email your comments to 63860 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Fri, 02 Jun 2023 22:20:01 GMT) Full text and rfc822 format available.Oleg Pykhalov <go.wigust <at> gmail.com>
:guix-patches <at> gnu.org
.
(Fri, 02 Jun 2023 22:20:01 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: guix-patches <at> gnu.org Cc: Oleg Pykhalov <go.wigust <at> gmail.com> Subject: [PATCH] Shepherd: Add Bash completion file. Date: Sat, 3 Jun 2023 01:19:23 +0300
This patch adds a Bash completion file discussed in the 45004 issue: awk replaced with grep and sed; added more Guix related subcommands; fixed typo with 't' letter in 'for word in ${COMP_WORDS[*]}t'. Tested with command: guix build -f guix.scm which produced: /gnu/store/hr4rqm9wi9i2fpcd75zpqfd04vqavyif-shepherd-0.10.99-git/etc/bash_completion.d/herd Oleg Pykhalov (1): Add Bash completion file. Makefile.am | 4 ++ configure.ac | 9 ++++ etc/completion/bash/herd | 104 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 etc/completion/bash/herd base-commit: b9b15db9e5bda27287706b6727c462df686e7621 -- 2.38.0
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Fri, 02 Jun 2023 22:23:01 GMT) Full text and rfc822 format available.Message #8 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: 63860 <at> debbugs.gnu.org Cc: Oleg Pykhalov <go.wigust <at> gmail.com> Subject: [PATCH] Add Bash completion file. Date: Sat, 3 Jun 2023 01:21:22 +0300
* etc/completion/bash/herd: New file. * Makefile.am (dist_bashcompletion_DATA): New variable. * configure.ac: Add --with-bash-completion-dir. --- Makefile.am | 4 ++ configure.ac | 9 ++++ etc/completion/bash/herd | 104 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 etc/completion/bash/herd diff --git a/Makefile.am b/Makefile.am index d82e75c..d7b5d36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ # Copyright © 2002, 2003 Wolfgang Jährling <wolfgang <at> pro-linux.de> # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès <ludo <at> gnu.org> # Copyright © 2018 Carlo Zancanaro <carlo <at> zancanaro.id.au> +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> # # This file is part of the GNU Shepherd. # @@ -135,6 +136,9 @@ doc/%.8: modules/shepherd/scripts/%.scm configure.ac dist_man1_MANS = doc/shepherd.1 doc/herd.1 dist_man8_MANS = doc/halt.8 doc/reboot.8 +# Bash completion file. +dist_bashcompletion_DATA = etc/completion/bash/herd + # Things not automatically included in the distribution. EXTRA_DIST += \ build-aux/config.rpath \ diff --git a/configure.ac b/configure.ac index 18455a0..8aaea92 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,15 @@ esac AC_MSG_RESULT([$build_crash_handler]) AM_CONDITIONAL([BUILD_CRASH_HANDLER], [test "x$build_crash_handler" = "xyes"]) +dnl Bash completion file. + +AC_ARG_WITH([bash-completion-dir], + AC_HELP_STRING([--with-bash-completion-dir=DIR], + [name of the Bash completion directory]), + [bashcompletiondir="$withval"], + [bashcompletiondir='${sysconfdir}/bash_completion.d']) +AC_SUBST([bashcompletiondir]) + dnl Manual pages. AM_MISSING_PROG([HELP2MAN], [help2man]) diff --git a/etc/completion/bash/herd b/etc/completion/bash/herd new file mode 100644 index 0000000..c6a1a63 --- /dev/null +++ b/etc/completion/bash/herd @@ -0,0 +1,104 @@ +# GNU Shepherd --- System service manager for GNU +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> +# +# This file is part of GNU Shepherd. +# +# GNU Shepherd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Shepherd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shepherd. If not, see <http://www.gnu.org/licenses/>. + +# Bash completion for Shepherd commands. + +_herd_complete_subcommand() +{ + local command="${COMP_WORDS[1]}" + case "$command" in + discover) + complitions="guix-daemon" + COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + schedule) + complitions="mcron" + COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + set-http-proxy) + complitions="guix-daemon" + COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + *) + local services="$(herd status | grep '^ +\|^ -\| \*' | cut -d ' ' -f3)" + COMPREPLY=($(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + esac +} + +_herd_complete_3() +{ + local command="${COMP_WORDS[2]}" + case "$command" in + guix-daemon) + complitions="on off" + COMPREPLY=($(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + *) + ;; + esac +} + +_herd_is_command () +{ + local word + local result="false" + for word in ${COMP_WORDS[*]} + do + if [ "$word" = "$1" ] + then + result=true + break + fi + done + $result +} + +_herd_complete() +{ + local word_count=${#COMP_WORDS[*]} + local word_at_point="${COMP_WORDS[$COMP_CWORD]}" + case $COMP_CWORD in + 1) + if [ -z "$_herd_subcommands" ] + then + # Cache the list of subcommands to speed things up. + _herd_subcommands=( + disable + discover + enable + schedule + set-http-proxy + start + status + stop + ) + _herd_subcommands="${_herd_subcommands[@]}" + fi + COMPREPLY=($(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}")) + ;; + *) + case $COMP_CWORD in + 2) _herd_complete_subcommand;; + 3) _herd_complete_3;; + esac + ;; + esac +} + +complete -F _herd_complete herd -- 2.38.0
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sat, 03 Jun 2023 09:39:02 GMT) Full text and rfc822 format available.Message #11 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: 63860 <at> debbugs.gnu.org Cc: Oleg Pykhalov <go.wigust <at> gmail.com> Subject: [PATCH v2] Add Bash completion file. Date: Sat, 3 Jun 2023 12:37:01 +0300
* etc/completion/bash/herd: New file. * Makefile.am (dist_bashcompletion_DATA): New variable. * configure.ac: Add --with-bash-completion-dir. --- Makefile.am | 4 ++ configure.ac | 9 ++++ etc/completion/bash/herd | 103 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 etc/completion/bash/herd diff --git a/Makefile.am b/Makefile.am index d82e75c..d7b5d36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ # Copyright © 2002, 2003 Wolfgang Jährling <wolfgang <at> pro-linux.de> # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès <ludo <at> gnu.org> # Copyright © 2018 Carlo Zancanaro <carlo <at> zancanaro.id.au> +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> # # This file is part of the GNU Shepherd. # @@ -135,6 +136,9 @@ doc/%.8: modules/shepherd/scripts/%.scm configure.ac dist_man1_MANS = doc/shepherd.1 doc/herd.1 dist_man8_MANS = doc/halt.8 doc/reboot.8 +# Bash completion file. +dist_bashcompletion_DATA = etc/completion/bash/herd + # Things not automatically included in the distribution. EXTRA_DIST += \ build-aux/config.rpath \ diff --git a/configure.ac b/configure.ac index 18455a0..8aaea92 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,15 @@ esac AC_MSG_RESULT([$build_crash_handler]) AM_CONDITIONAL([BUILD_CRASH_HANDLER], [test "x$build_crash_handler" = "xyes"]) +dnl Bash completion file. + +AC_ARG_WITH([bash-completion-dir], + AC_HELP_STRING([--with-bash-completion-dir=DIR], + [name of the Bash completion directory]), + [bashcompletiondir="$withval"], + [bashcompletiondir='${sysconfdir}/bash_completion.d']) +AC_SUBST([bashcompletiondir]) + dnl Manual pages. AM_MISSING_PROG([HELP2MAN], [help2man]) diff --git a/etc/completion/bash/herd b/etc/completion/bash/herd new file mode 100644 index 0000000..06afaae --- /dev/null +++ b/etc/completion/bash/herd @@ -0,0 +1,103 @@ +# GNU Shepherd --- System service manager for GNU +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> +# +# This file is part of GNU Shepherd. +# +# GNU Shepherd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Shepherd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shepherd. If not, see <http://www.gnu.org/licenses/>. + +# Bash completion for Shepherd commands. + +_herd_complete_subcommand() +{ + local command="${COMP_WORDS[1]}" + case "$command" in + discover) + complitions="guix-daemon" + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + schedule) + complitions="mcron" + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + set-http-proxy) + complitions="guix-daemon" + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + local services + services="$(herd status | grep '^ +\|^ -\| \*' | cut -d ' ' -f3)" + mapfile -t COMPREPLY < <(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + esac +} + +_herd_complete_3() +{ + local command="${COMP_WORDS[2]}" + case "$command" in + guix-daemon) + complitions="on off" + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + ;; + esac +} + +_herd_is_command () +{ + local word + local result="false" + for word in "${COMP_WORDS[@]}" + do + if [ "$word" = "$1" ] + then + result=true + break + fi + done + $result +} + +_herd_complete() +{ + case $COMP_CWORD in + 1) + if [ -z "$_herd_subcommands" ] + then + # Cache the list of subcommands to speed things up. + _herd_subcommands_list=( + disable + discover + enable + schedule + set-http-proxy + start + status + stop + ) + _herd_subcommands="${_herd_subcommands_list[*]}" + fi + mapfile -t COMPREPLY < <(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + case $COMP_CWORD in + 2) _herd_complete_subcommand;; + 3) _herd_complete_3;; + esac + ;; + esac +} + +complete -F _herd_complete herd -- 2.38.0
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sat, 03 Jun 2023 09:43:01 GMT) Full text and rfc822 format available.Message #14 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: 63860 <at> debbugs.gnu.org Subject: Re: bug#63860: [PATCH] Shepherd: Add Bash completion file. Date: Sat, 03 Jun 2023 12:41:59 +0300
[Message part 1 (text/plain, inline)]
Oleg Pykhalov <go.wigust <at> gmail.com> writes: > * etc/completion/bash/herd: New file. > * Makefile.am (dist_bashcompletion_DATA): New variable. > * configure.ac: Add --with-bash-completion-dir. > --- > Makefile.am | 4 ++ > configure.ac | 9 ++++ > etc/completion/bash/herd | 103 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 116 insertions(+) > create mode 100644 etc/completion/bash/herd v2 fixes warnings reported by shellcheck utility, which should be used in the first place, apologies. Everything else works in the same way. Regards, Oleg.
[signature.asc (application/pgp-signature, inline)]
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sat, 03 Jun 2023 18:21:01 GMT) Full text and rfc822 format available.Message #17 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Liliana Marie Prikler <liliana.prikler <at> gmail.com> To: Oleg Pykhalov <go.wigust <at> gmail.com>, 63860 <at> debbugs.gnu.org Subject: Re: [PATCH v2] Add Bash completion file. Date: Sat, 03 Jun 2023 20:20:00 +0200
Am Samstag, dem 03.06.2023 um 12:37 +0300 schrieb Oleg Pykhalov: > * etc/completion/bash/herd: New file. > * Makefile.am (dist_bashcompletion_DATA): New variable. > * configure.ac: Add --with-bash-completion-dir. > --- > Makefile.am | 4 ++ > configure.ac | 9 ++++ > etc/completion/bash/herd | 103 > +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 116 insertions(+) > create mode 100644 etc/completion/bash/herd > > diff --git a/Makefile.am b/Makefile.am > index d82e75c..d7b5d36 100644 > --- a/Makefile.am > +++ b/Makefile.am > @@ -2,6 +2,7 @@ > # Copyright © 2002, 2003 Wolfgang Jährling <wolfgang <at> pro-linux.de> > # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès > <ludo <at> gnu.org> > # Copyright © 2018 Carlo Zancanaro <carlo <at> zancanaro.id.au> > +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> > # > # This file is part of the GNU Shepherd. > # > @@ -135,6 +136,9 @@ doc/%.8: modules/shepherd/scripts/%.scm > configure.ac > dist_man1_MANS = doc/shepherd.1 doc/herd.1 > dist_man8_MANS = doc/halt.8 doc/reboot.8 > > +# Bash completion file. > +dist_bashcompletion_DATA = etc/completion/bash/herd > + > # Things not automatically included in the distribution. > EXTRA_DIST += \ > build-aux/config.rpath \ > diff --git a/configure.ac b/configure.ac > index 18455a0..8aaea92 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -172,6 +172,15 @@ esac > AC_MSG_RESULT([$build_crash_handler]) > AM_CONDITIONAL([BUILD_CRASH_HANDLER], [test "x$build_crash_handler" > = "xyes"]) > > +dnl Bash completion file. > + > +AC_ARG_WITH([bash-completion-dir], > + AC_HELP_STRING([--with-bash-completion-dir=DIR], > + [name of the Bash completion directory]), > + [bashcompletiondir="$withval"], > + [bashcompletiondir='${sysconfdir}/bash_completion.d']) > +AC_SUBST([bashcompletiondir]) > + > dnl Manual pages. > AM_MISSING_PROG([HELP2MAN], [help2man]) > > diff --git a/etc/completion/bash/herd b/etc/completion/bash/herd > new file mode 100644 > index 0000000..06afaae > --- /dev/null > +++ b/etc/completion/bash/herd > @@ -0,0 +1,103 @@ > +# GNU Shepherd --- System service manager for GNU > +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> > +# > +# This file is part of GNU Shepherd. > +# > +# GNU Shepherd is free software; you can redistribute it and/or > modify it > +# under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > (at > +# your option) any later version. > +# > +# GNU Shepherd is distributed in the hope that it will be useful, > but > +# WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with GNU Shepherd. If not, see > <http://www.gnu.org/licenses/>. > + > +# Bash completion for Shepherd commands. > + > +_herd_complete_subcommand() > +{ > + local command="${COMP_WORDS[1]}" > + case "$command" in > + discover) > + complitions="guix-daemon" > + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- > "${COMP_WORDS[$COMP_CWORD]}") > + ;; Is there a reason to call the variable "complitions" rather than "completions" or using an immediate value? > + schedule) > + complitions="mcron" > + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- > "${COMP_WORDS[$COMP_CWORD]}") > + ;; > + set-http-proxy) > + complitions="guix-daemon" > + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- > "${COMP_WORDS[$COMP_CWORD]}") > + ;; > + *) > + local services > + services="$(herd status | grep '^ +\|^ -\| \*' | cut -d > ' ' -f3)" > + mapfile -t COMPREPLY < <(compgen -W "$services" -- > "${COMP_WORDS[$COMP_CWORD]}") > + ;; > + esac > +} > + > +_herd_complete_3() > +{ > + local command="${COMP_WORDS[2]}" > + case "$command" in > + guix-daemon) > + complitions="on off" > + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- > "${COMP_WORDS[$COMP_CWORD]}") > + ;; > + *) > + ;; > + esac > +} > + > +_herd_is_command () > +{ > + local word > + local result="false" > + for word in "${COMP_WORDS[@]}" > + do > + if [ "$word" = "$1" ] > + then > + result=true > + break > + fi > + done > + $result > +} > + > +_herd_complete() > +{ > + case $COMP_CWORD in > + 1) > + if [ -z "$_herd_subcommands" ] > + then > + # Cache the list of subcommands to speed things up. > + _herd_subcommands_list=( > + disable > + discover > + enable > + schedule > + set-http-proxy > + start > + status > + stop > + ) > + _herd_subcommands="${_herd_subcommands_list[*]}" > + fi > + mapfile -t COMPREPLY < <(compgen -W "$_herd_subcommands" > -- "${COMP_WORDS[$COMP_CWORD]}") > + ;; > + *) > + case $COMP_CWORD in > + 2) _herd_complete_subcommand;; > + 3) _herd_complete_3;; > + esac > + ;; > + esac > +} > + > +complete -F _herd_complete herd Cheers
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sat, 03 Jun 2023 19:29:01 GMT) Full text and rfc822 format available.Message #20 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: Liliana Marie Prikler <liliana.prikler <at> gmail.com> Cc: 63860 <at> debbugs.gnu.org Subject: Re: [PATCH v2] Add Bash completion file. Date: Sat, 03 Jun 2023 22:28:23 +0300
[Message part 1 (text/plain, inline)]
Liliana Marie Prikler <liliana.prikler <at> gmail.com> writes: […] >> +{ >> + local command="${COMP_WORDS[1]}" >> + case "$command" in >> + discover) >> + complitions="guix-daemon" >> + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- >> "${COMP_WORDS[$COMP_CWORD]}") >> + ;; > Is there a reason to call the variable "complitions" rather than > "completions" No reason, it's a typo probably from autocompletion of my editor. :-) > or using an immediate value? Do you mean to use the following? --8<---------------cut here---------------start------------->8--- case "$command" in discover) mapfile -t COMPREPLY < <(compgen -W guix-daemon -- "${COMP_WORDS[$COMP_CWORD]}") ;; ... --8<---------------cut here---------------end--------------->8--- yes, this will work. No strong opinion on that, both ways would work for me. Regards, Oleg.
[signature.asc (application/pgp-signature, inline)]
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sat, 03 Jun 2023 21:43:02 GMT) Full text and rfc822 format available.Message #23 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Liliana Marie Prikler <liliana.prikler <at> gmail.com> To: Oleg Pykhalov <go.wigust <at> gmail.com> Cc: 63860 <at> debbugs.gnu.org Subject: Re: [PATCH v2] Add Bash completion file. Date: Sat, 03 Jun 2023 23:42:05 +0200
Am Samstag, dem 03.06.2023 um 22:28 +0300 schrieb Oleg Pykhalov: > Liliana Marie Prikler <liliana.prikler <at> gmail.com> writes: > > […] > > > > +{ > > > + local command="${COMP_WORDS[1]}" > > > + case "$command" in > > > + discover) > > > + complitions="guix-daemon" > > > + mapfile -t COMPREPLY < <(compgen -W "$complitions" - > > > - > > > "${COMP_WORDS[$COMP_CWORD]}") > > > + ;; > > Is there a reason to call the variable "complitions" rather than > > "completions" > > No reason, it's a typo probably from autocompletion of my editor. :-) > > > or using an immediate value? > > Do you mean to use the following? > --8<---------------cut here---------------start------------->8--- > case "$command" in > discover) > mapfile -t COMPREPLY < <(compgen -W guix-daemon -- > "${COMP_WORDS[$COMP_CWORD]}") > ;; > ... > --8<---------------cut here---------------end--------------->8--- > > yes, this will work. I'd still quote "guix-daemon", but yeah. Cheers
guix-patches <at> gnu.org
:bug#63860
; Package guix-patches
.
(Sun, 04 Jun 2023 08:58:02 GMT) Full text and rfc822 format available.Message #26 received at 63860 <at> debbugs.gnu.org (full text, mbox):
From: Oleg Pykhalov <go.wigust <at> gmail.com> To: 63860 <at> debbugs.gnu.org Cc: Oleg Pykhalov <go.wigust <at> gmail.com>, Liliana Marie Prikler <liliana.prikler <at> gmail.com> Subject: [PATCH v3] Add Bash completion file. Date: Sun, 4 Jun 2023 11:57:16 +0300
* etc/completion/bash/herd: New file. * Makefile.am (dist_bashcompletion_DATA): New variable. * configure.ac: Add --with-bash-completion-dir. --- Makefile.am | 4 ++ configure.ac | 9 ++++ etc/completion/bash/herd | 100 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 etc/completion/bash/herd diff --git a/Makefile.am b/Makefile.am index d82e75c..d7b5d36 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ # Copyright © 2002, 2003 Wolfgang Jährling <wolfgang <at> pro-linux.de> # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès <ludo <at> gnu.org> # Copyright © 2018 Carlo Zancanaro <carlo <at> zancanaro.id.au> +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> # # This file is part of the GNU Shepherd. # @@ -135,6 +136,9 @@ doc/%.8: modules/shepherd/scripts/%.scm configure.ac dist_man1_MANS = doc/shepherd.1 doc/herd.1 dist_man8_MANS = doc/halt.8 doc/reboot.8 +# Bash completion file. +dist_bashcompletion_DATA = etc/completion/bash/herd + # Things not automatically included in the distribution. EXTRA_DIST += \ build-aux/config.rpath \ diff --git a/configure.ac b/configure.ac index 18455a0..8aaea92 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,15 @@ esac AC_MSG_RESULT([$build_crash_handler]) AM_CONDITIONAL([BUILD_CRASH_HANDLER], [test "x$build_crash_handler" = "xyes"]) +dnl Bash completion file. + +AC_ARG_WITH([bash-completion-dir], + AC_HELP_STRING([--with-bash-completion-dir=DIR], + [name of the Bash completion directory]), + [bashcompletiondir="$withval"], + [bashcompletiondir='${sysconfdir}/bash_completion.d']) +AC_SUBST([bashcompletiondir]) + dnl Manual pages. AM_MISSING_PROG([HELP2MAN], [help2man]) diff --git a/etc/completion/bash/herd b/etc/completion/bash/herd new file mode 100644 index 0000000..f006b86 --- /dev/null +++ b/etc/completion/bash/herd @@ -0,0 +1,100 @@ +# GNU Shepherd --- System service manager for GNU +# Copyright © 2023 Oleg Pykhalov <go.wigust <at> gmail.com> +# +# This file is part of GNU Shepherd. +# +# GNU Shepherd is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Shepherd is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Shepherd. If not, see <http://www.gnu.org/licenses/>. + +# Bash completion for Shepherd commands. + +_herd_complete_subcommand() +{ + local command="${COMP_WORDS[1]}" + case "$command" in + discover) + mapfile -t COMPREPLY < <(compgen -W "guix-daemon" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + schedule) + mapfile -t COMPREPLY < <(compgen -W "mcron" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + set-http-proxy) + mapfile -t COMPREPLY < <(compgen -W "guix-daemon" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + local services + services="$(herd status | grep '^ +\|^ -\| \*' | cut -d ' ' -f3)" + mapfile -t COMPREPLY < <(compgen -W "$services" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + esac +} + +_herd_complete_3() +{ + local command="${COMP_WORDS[2]}" + case "$command" in + guix-daemon) + complitions="on off" + mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + ;; + esac +} + +_herd_is_command () +{ + local word + local result="false" + for word in "${COMP_WORDS[@]}" + do + if [ "$word" = "$1" ] + then + result=true + break + fi + done + $result +} + +_herd_complete() +{ + case $COMP_CWORD in + 1) + if [ -z "$_herd_subcommands" ] + then + # Cache the list of subcommands to speed things up. + _herd_subcommands_list=( + disable + discover + enable + schedule + set-http-proxy + start + status + stop + ) + _herd_subcommands="${_herd_subcommands_list[*]}" + fi + mapfile -t COMPREPLY < <(compgen -W "$_herd_subcommands" -- "${COMP_WORDS[$COMP_CWORD]}") + ;; + *) + case $COMP_CWORD in + 2) _herd_complete_subcommand;; + 3) _herd_complete_3;; + esac + ;; + esac +} + +complete -F _herd_complete herd -- 2.38.0
Ludovic Courtès <ludo <at> gnu.org>
:Oleg Pykhalov <go.wigust <at> gmail.com>
:Message #31 received at 63860-done <at> debbugs.gnu.org (full text, mbox):
From: Ludovic Courtès <ludo <at> gnu.org> To: Oleg Pykhalov <go.wigust <at> gmail.com> Cc: 63860-done <at> debbugs.gnu.org, Liliana Marie Prikler <liliana.prikler <at> gmail.com> Subject: Re: bug#63860: [PATCH] Shepherd: Add Bash completion file. Date: Mon, 05 Jun 2023 14:03:32 +0200
[Message part 1 (text/plain, inline)]
Hello, Oleg Pykhalov <go.wigust <at> gmail.com> skribis: > * etc/completion/bash/herd: New file. > * Makefile.am (dist_bashcompletion_DATA): New variable. > * configure.ac: Add --with-bash-completion-dir. Excellent! Applied with the changes below. Thank you & thanks Liliana for reviewing! Ludo’.
[Message part 2 (text/x-patch, inline)]
diff --git a/NEWS b/NEWS index d6c2fc0..b644adb 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,11 @@ Please send Shepherd bug reports to bug-guix <at> gnu.org. * Changes in 0.10.2 +** New Bash completion + +A Bash completion file is now installed, providing tab completion for the +‘herd’ command. + ** ‘herd’ shows a hint when the service and action are likely swapped The hint is printed for instance when typing ‘herd foobar start’. diff --git a/etc/completion/bash/herd b/etc/completion/bash/herd index f006b86..74e7a24 100644 --- a/etc/completion/bash/herd +++ b/etc/completion/bash/herd @@ -44,8 +44,8 @@ _herd_complete_3() local command="${COMP_WORDS[2]}" case "$command" in guix-daemon) - complitions="on off" - mapfile -t COMPREPLY < <(compgen -W "$complitions" -- "${COMP_WORDS[$COMP_CWORD]}") + completions="on off" + mapfile -t COMPREPLY < <(compgen -W "$completions" -- "${COMP_WORDS[$COMP_CWORD]}") ;; *) ;;
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Tue, 04 Jul 2023 11:24:10 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.