From patchwork Sun Jun 4 08:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Oleg Pykhalov X-Patchwork-Id: 50590 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 8A02C27BBE9; Sun, 4 Jun 2023 09:58:17 +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 B3F751718C for ; Sun, 4 Jun 2023 09:58:14 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q5jYq-0005fT-Ov; Sun, 04 Jun 2023 04:58: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 1q5jYo-0005f1-T5 for guix-patches@gnu.org; Sun, 04 Jun 2023 04:58: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 1q5jYo-0000hx-K8 for guix-patches@gnu.org; Sun, 04 Jun 2023 04:58:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q5jYo-0002yu-FN for guix-patches@gnu.org; Sun, 04 Jun 2023 04:58:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63860] [PATCH v3] Add Bash completion file. Resent-From: Oleg Pykhalov Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 04 Jun 2023 08:58: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 , Liliana Marie Prikler Received: via spool by 63860-submit@debbugs.gnu.org id=B63860.168586908111453 (code B ref 63860); Sun, 04 Jun 2023 08:58:02 +0000 Received: (at 63860) by debbugs.gnu.org; 4 Jun 2023 08:58:01 +0000 Received: from localhost ([127.0.0.1]:44983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5jYm-0002yf-WF for submit@debbugs.gnu.org; Sun, 04 Jun 2023 04:58:01 -0400 Received: from mail-lj1-f180.google.com ([209.85.208.180]:40045) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q5jYj-0002yF-Jv for 63860@debbugs.gnu.org; Sun, 04 Jun 2023 04:57:59 -0400 Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2b1a4d74f7fso3957881fa.0 for <63860@debbugs.gnu.org>; Sun, 04 Jun 2023 01:57:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685869071; x=1688461071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XuOtMlBBJGDFZAwG2iQz9OAbHOG2iECBpoZcEuwK2oc=; b=EIQ4kfJ5rGludxKyYglggNo4cceqVsyKYBs5eQnYzdWUDmAft29nbi6TI4MfgK6u4X o7yhWqxtWttI6k761K4ZFz9MwUCRkMnJVKqibQIDWAaV5WwnD5QlPZOv4GTqLJyLFeMW BJao+1RTp3TjmD+i0tK1PeJMtv/4qSL3Na1GTvZaDzR6EOtsKq2D2bnGRn02mCWLr64x PPYmHl7PpTUgVE7vVD18TXJRpZc+0MhpQx785Wvy4HU/TVfWnVyZtTrjhS9jFYM/t0il Ozn1GnfwWsCcZIqWjQgFPK0KGNKQs3DYKfPGtV3kkgntpDZZEzmoTQRE+Sfu2cyJDnLL w/Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685869071; x=1688461071; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XuOtMlBBJGDFZAwG2iQz9OAbHOG2iECBpoZcEuwK2oc=; b=VVGxYk29ZuEy60z4BtMc5wPhiZrHe9aWE/qGiySgeUTmI6xbnk3K8wzpNfiwJdyTYE dfn3zNi8xOnK3FVWaUTyfnU16NjpYu0glZeiuUXRTcYhPTLvRntvwvMZi+ezlhRxoIXN DpDfGAGxRBCgpczJS0QS2DPjNa1tXdJ3BH/Pn5QqeigxzgSLjsr6/MY2x5BjZGf6tYzw 20uU8lwWsAxNyMEEG+YKl0FmGPQI6XcETgHopZgo1uXeDuWyaRAnXjcdplsrPHakg3Vh dKsLBbTy8Kk2in8fsM65Tl4fx201DVOTAzMTOS4JN+6HOk/nQN0HAjpx3dFB92T9jECv zHWQ== X-Gm-Message-State: AC+VfDzEjqIfH7EpzxJiRP1pJR+/K3/JjhkCrJm0JuD+oM2uWoDgl0XN Pxh3bUN2hV8Kf3Ky6rQXCKtjm7GrZ0Q= X-Google-Smtp-Source: ACHHUZ66OZQqz25pLo98BtYGZJG8hkJT2jYtuvFwLyeGJHVhj3RiAsk2Mi6gFnr5ZO/kuiw1ZlSrCg== X-Received: by 2002:ac2:5d24:0:b0:4f3:a878:2c02 with SMTP id i4-20020ac25d24000000b004f3a8782c02mr5930006lfb.4.1685869070800; Sun, 04 Jun 2023 01:57:50 -0700 (PDT) Received: from guixsd.wugi.info ([88.201.161.72]) by smtp.gmail.com with ESMTPSA id p22-20020ac246d6000000b004f606755537sm719832lfo.298.2023.06.04.01.57.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jun 2023 01:57:50 -0700 (PDT) From: Oleg Pykhalov Date: Sun, 4 Jun 2023 11:57:16 +0300 Message-Id: <20230604085716.31735-1-go.wigust@gmail.com> X-Mailer: git-send-email 2.38.0 In-Reply-To: <940cd99ec2de7a9d6b6e0ea98670f0031891cdda.camel@gmail.com> References: <940cd99ec2de7a9d6b6e0ea98670f0031891cdda.camel@gmail.com> 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 | 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 # 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..f006b86 --- /dev/null +++ b/etc/completion/bash/herd @@ -0,0 +1,100 @@ +# 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) + 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