From patchwork Sat Jun 3 09:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleg Pykhalov X-Patchwork-Id: 50580 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id EDA2E27BBE9; Sat, 3 Jun 2023 10:39:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id AA6F116C7B for ; Sat, 3 Jun 2023 10:39:19 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q5Niy-0006a3-KJ; Sat, 03 Jun 2023 05:39:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q5Niw-0006Ze-If for guix-patches@gnu.org; Sat, 03 Jun 2023 05:39:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q5Niw-000110-Ay for guix-patches@gnu.org; Sat, 03 Jun 2023 05:39:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q5Niw-0007nQ-6z for guix-patches@gnu.org; Sat, 03 Jun 2023 05:39:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63860] [PATCH v2] Add Bash completion file. References: <20230602221923.16196-1-go.wigust@gmail.com> In-Reply-To: <20230602221923.16196-1-go.wigust@gmail.com> Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 03 Jun 2023 09:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63860 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 63860@debbugs.gnu.org Cc: Oleg Pykhalov Received: via spool by 63860-submit@debbugs.gnu.org id=B63860.168578513829958 (code B ref 63860); Sat, 03 Jun 2023 09:39:02 +0000 Received: (at 63860) by debbugs.gnu.org; 3 Jun 2023 09:38:58 +0000 Received: from localhost ([127.0.0.1]:41568 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5Nir-0007n7-Jy for submit@debbugs.gnu.org; Sat, 03 Jun 2023 05:38:58 -0400 Received: from mail-lf1-f49.google.com ([209.85.167.49]:40150) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5Nio-0007mu-Or for 63860@debbugs.gnu.org; Sat, 03 Jun 2023 05:38:56 -0400 Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-4f60924944aso456920e87.0 for <63860@debbugs.gnu.org>; Sat, 03 Jun 2023 02:38:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685785128; x=1688377128; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=VNjkQJ5H3lSdRAbYOwc4PZQv//94zQhPGimZlSInhSU=; b=g5O4+6gV0Ya+A63t8XzqkALAVJEbCmd+BnGB3E5bI/1BLvC7lkClmMAndxrSMRpQ4c V6lptymr3k9JaRDEqVno2DAcDIPPR0WKio/NdrdOxUzr1Pr5YdWWbpSfBV5TyTxq1d+U aUFdIGgoC08xvgfZ1KOfyPkBHkQOIpDZUyc2nFywxqAXqULHwSGU2XlqVEqUkj3xcvLE KEH8N0HOXoMGwranKULzzcgL7dH78SGkp2ZKNiD80XHnSi+FQfMdzeC0fLZXPAtFuCt1 e7so3PCCOYH5s6d6Y8MCiy2NK3mdZfDAxAqmCy7x6rNzJD9vaJS0lsW9eMGuCPneiDuV wQBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685785128; x=1688377128; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VNjkQJ5H3lSdRAbYOwc4PZQv//94zQhPGimZlSInhSU=; b=TpaWTsxa/2oblASVxl467p38jVo/Dtu+txS5mXCyCpatZRI6l7FCcZNuctnmzAuc1G Zgr+GhpP0Ug1MRfhRUW+8kHThhd8TnoqJHTaVDaV/GOzko0mB8VU+TJCOxsxW56NqEwK 3p4EFjnwkeEMfjc5N3oiMCyfooauPz+S4el2iH0LCcZMEUOFDLJnX/7uKntEBpcZ9b+c mTHt3wq/7FkA0MV420WNUP2I+yA723U6rtvt3evUUJrRiJa+DeFRFSEaE1ByxL4A5dGc 9RZQq+g5jrucpgHmnh47oiZ2pMFvLd+w1uo6cgFJAwVOM72m+lVrxt26GX+V4K3zFudH NvNg== X-Gm-Message-State: AC+VfDzS3LtdGe/nQ8OwUbqJY1rJDD64+UZGSMC0nPI3AMLbZTc1nplY Q3gN5v8x/lne4Bfc+y/JoX89PPq59Ug= X-Google-Smtp-Source: ACHHUZ6XJbZOf8/F7vjBm2nFLk0Zrex2JOBUSPhSJoPNpgL7Kk9A7GzjDR5bfVHCGf48oZ3/FkJMqg== X-Received: by 2002:ac2:55b0:0:b0:4f6:949:8434 with SMTP id y16-20020ac255b0000000b004f609498434mr3300677lfg.0.1685785128076; Sat, 03 Jun 2023 02:38:48 -0700 (PDT) Received: from guixsd.wugi.info ([88.201.161.72]) by smtp.gmail.com with ESMTPSA id p17-20020a19f011000000b004f60ac51ff2sm433707lfc.189.2023.06.03.02.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Jun 2023 02:38:47 -0700 (PDT) From: Oleg Pykhalov Date: Sat, 3 Jun 2023 12:37:01 +0300 Message-Id: <20230603093659.14873-1-go.wigust@gmail.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * 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 # Copyright © 2013-2016, 2018-2020, 2022-2023 Ludovic Courtès # Copyright © 2018 Carlo Zancanaro +# Copyright © 2023 Oleg Pykhalov # # 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 +# +# 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 . + +# 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