From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 6Pk7GSdSfGQyfwEASxT56A (envelope-from ) for ; Sun, 04 Jun 2023 10:58:15 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id MK4cGSdSfGQ8fAAAauVa8A (envelope-from ) for ; Sun, 04 Jun 2023 10:58:15 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A65419287 for ; Sun, 4 Jun 2023 10:58:14 +0200 (CEST) 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1685869095; a=rsa-sha256; cv=none; b=jliCmurnnydlrtX1cFbYCfwlUSbttbr2/G0nakdYTz+UmArfJYlepJ1P5K5WCCrvLOA7ir PzxjoB3y6qjh1Ny/YiAmCvnDhGj16AiAxFpcPtl4RDEqs0dDYzSOu/ErTvyQykPZRMAQPX 2vwcZBgPZxj74mR9Oz5Xo7Eit7I4pJjlKWRJTeL6WwnHJjwzIUGSEO9fhmfv5s5coeE/qo I3+gLW3QfqRa435M6jY9b1b+jJdTm8gbgwsvuyQr+c85Nf5PBdj1D0uWgTr0RuA7L9MKqB VdUlx6I64kDoY+GO9yNh3Wj5L3b7GvVDFWRxFsJtANSa3IgZdbFhvqYcZutajw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=EIQ4kfJ5; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1685869095; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=XuOtMlBBJGDFZAwG2iQz9OAbHOG2iECBpoZcEuwK2oc=; b=HLpM9l80RlLWc4Qy35mj8RzdnjPVD3e7xTZWM4f3B3w4F3t2AEui8rPHSl8w8ICwoo4VCo sB854fehlDdZW9I4cDn0vZxwOiCjUqVPSBEGgLv/I1gPsSq0w+6/e6nx2KViBXwsUDjfXq j+bUbNJLpLmPK4TMI14plvxQW7zBVKHUyILboUi4iqSrn+q+95+Rb68MqbXzFF7AY/zfGU yeUjG1+KceiE7gNxHuVGkzu/62ol+QuvsEzDj5VgSRr9rlx8hqVla9xyeGOlG1XApHSoY0 63dvxYu8edSkGf86PTvWsgM+Ji1miWRaAcUesQrV5J7H7onK7omEr3JCBtZ2XQ== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=EIQ4kfJ5; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -2.58 X-Spam-Score: -2.58 X-Migadu-Queue-Id: A65419287 X-TUID: P/5KyiGL3Xcf * 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 -- 2.38.0