all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oleg Pykhalov <go.wigust@gmail.com>
To: 63860@debbugs.gnu.org
Cc: Oleg Pykhalov <go.wigust@gmail.com>,
	Liliana Marie Prikler <liliana.prikler@gmail.com>
Subject: [bug#63860] [PATCH v3] Add Bash completion file.
Date: Sun,  4 Jun 2023 11:57:16 +0300	[thread overview]
Message-ID: <20230604085716.31735-1-go.wigust@gmail.com> (raw)
In-Reply-To: <940cd99ec2de7a9d6b6e0ea98670f0031891cdda.camel@gmail.com>

* 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@pro-linux.de>
 # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès <ludo@gnu.org>
 # Copyright © 2018 Carlo Zancanaro <carlo@zancanaro.id.au>
+# Copyright © 2023 Oleg Pykhalov <go.wigust@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@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





  reply	other threads:[~2023-06-04  8:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-02 22:19 [bug#63860] [PATCH] Shepherd: Add Bash completion file Oleg Pykhalov
2023-06-02 22:21 ` [bug#63860] [PATCH] " Oleg Pykhalov
2023-06-03  9:37 ` [bug#63860] [PATCH v2] " Oleg Pykhalov
2023-06-03  9:41   ` [bug#63860] [PATCH] Shepherd: " Oleg Pykhalov
2023-06-03 18:20   ` [bug#63860] [PATCH v2] " Liliana Marie Prikler
2023-06-03 19:28     ` Oleg Pykhalov
2023-06-03 21:42       ` Liliana Marie Prikler
2023-06-04  8:57         ` Oleg Pykhalov [this message]
2023-06-05 12:03           ` bug#63860: [PATCH] Shepherd: " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230604085716.31735-1-go.wigust@gmail.com \
    --to=go.wigust@gmail.com \
    --cc=63860@debbugs.gnu.org \
    --cc=liliana.prikler@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.