Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp820621ybl; Fri, 16 Aug 2019 04:39:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqyNK4XhagfwRUG4wpGoLEXLlnOajvRGNQL3SltQ8/GX5tfhjgK1et9VAYuAVMg1b7LKmNVZ X-Received: by 2002:a63:5b23:: with SMTP id p35mr7228833pgb.366.1565955561836; Fri, 16 Aug 2019 04:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565955561; cv=none; d=google.com; s=arc-20160816; b=EcwKBQsCPOECGrxtr14RmIVoIcDZ5urmmpGJQzjSDP3X1IR6mLjqMwtAAhgqRtnVlo uUPiJyyooiSFh93uPUv9qdPRvPxp/7wpAkeJ0R5VUyPWRyozhC/3+oBVFqME7ALnkswc wm96k/Ha5OtArMPPOL8n2zEb/72OuuSN2GNsR22XSTRcB5HVmIw0muyNCtZye30DOqWe OkpGvBA9dGZ7hxpCQQRRdTQG7F8ZH2dMgEgD96lF98FA7i2XLJOXTMu0Sbu5zL5kJBH3 9t3Npac3gD6THEkB0FtmYDkFIDhQ0mIUvqWS/LyALl1BEAIzRPe5ZJOYlIi71ksiA4yc Z9Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=8h+jZj0SlIXAcpjmiDPhfxgEwxDRfF67XgoBZjNCiSU=; b=DEOvAL8wzjn01qRO+YwcuMf29n5KxFmpZxiXZBdWyCRqHBfs2mxHtGiiTzMipagM6D i1tK93sDtMqtl/AathuD7rikmiXS51jL+YLIjmDYuuQlKvisMJjFy95PAToL5XE7ERdg UI0hJqX3OB1UtOzB1/9vMAbYrIv/quz83ajvEY06mt1eXJbqkrliRHx1W+5YRx5toUPm LyursFpJVj62ofwhXTL39X5xuB4mhs2U+Ie5ziwuQ4q9OXDz+UXsCtvrbbBZ7NU9qnn4 n4v1tu1XdqxNJzOGb/BnSZyXsTkjvKArMsUy+5r9ASbl8KqCyF4HT6U680Iwl314//0m wA+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X0xmbR8U; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 22si3669048pgu.226.2019.08.16.04.39.04; Fri, 16 Aug 2019 04:39:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=X0xmbR8U; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfHPLhN (ORCPT + 99 others); Fri, 16 Aug 2019 07:37:13 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:35523 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727070AbfHPLhN (ORCPT ); Fri, 16 Aug 2019 07:37:13 -0400 Received: by mail-ot1-f68.google.com with SMTP id g17so8507121otl.2 for ; Fri, 16 Aug 2019 04:37:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8h+jZj0SlIXAcpjmiDPhfxgEwxDRfF67XgoBZjNCiSU=; b=X0xmbR8U6z7/X7k1O8+0PzjOi/AnIebNfVWcRhbnCqVRfSXzhP0uc4zzTOaK57NQ01 zINduROEsZB5/N6buU7/R+qbQZrC922/AVLUTUnx2wcEPSwK2s2CPWmgBpDZvYaPdQRp lDczcwx9PNzSDc8R0RaCVGZiFTrEt2J/xXLMCqPTr+U7t6n20hWO2oDDERwSHlBs+4oB FZaP5se6E2hShmlEQQ7vUcKAZlw61gGZmv8JA17oz/R9ucoOeU6glzS1Ubtj2e6j5w7O Wr966GlfA2DvttxkMY+s62YTEknLqryrsZDMvLHjpsXss2YpqbKz+o9q3RaOASmp+bsA 9GMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8h+jZj0SlIXAcpjmiDPhfxgEwxDRfF67XgoBZjNCiSU=; b=lMNE8lo7Cgqzo5hdPIAITtjaSJrgUtJVoW7haofsk8lm0jfAOhaSLkigfg/WfMLVD1 HsOTxgs2rM2X5XwrvKnYWJ5U0BK/7v2+KV0YXWzjsNK6394YEa7JzUGLjk2GGRyXCneb G62ra4z3h5/9ygf0OewAdGTaW0vd9ApaWJoivkbXiSrCyX2wrEtRUomNJ3PmyeE2f4tL DamhHrKF1D7Pn2oRiGtmYKHpZRIVubY5rLx6Px91CYtl5S7EY27X619ZxvTNAUKBWCYJ Xe9cKIyVN6wEb3TY3M+hzXb/tMzPmXKGy6H2QKFmcO5KAJijFa9u7pegQDrK3vYhu2dk ir/Q== X-Gm-Message-State: APjAAAXGrU019b0WIt/PuZ9b6w9tFGqwyBr09chc7UAO4uZkRYcNfYua uUnnftI8UWmxBsQhmXt/IXWdzoqOxfeqUNvIJTc= X-Received: by 2002:a05:6830:2056:: with SMTP id f22mr6374395otp.177.1565955431998; Fri, 16 Aug 2019 04:37:11 -0700 (PDT) MIME-Version: 1.0 References: <20190816074333.24673-1-rpigott@berkeley.edu> <20190816074333.24673-3-rpigott@berkeley.edu> In-Reply-To: <20190816074333.24673-3-rpigott@berkeley.edu> From: Luiz Augusto von Dentz Date: Fri, 16 Aug 2019 14:36:59 +0300 Message-ID: Subject: Re: [PATCH BlueZ 2/3] completion: add bluetoothctl zsh completions To: Ronan Pigott Cc: "linux-bluetooth@vger.kernel.org" , Ronan Pigott Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Ronan, On Fri, Aug 16, 2019 at 10:48 AM Ronan Pigott wrote: > > From: Ronan Pigott > > --- > completion/zsh/_bluetoothctl | 131 +++++++++++++++++++++++++++++++++++ > 1 file changed, 131 insertions(+) > create mode 100644 completion/zsh/_bluetoothctl > > diff --git a/completion/zsh/_bluetoothctl b/completion/zsh/_bluetoothctl > new file mode 100644 > index 000000000..c9c177a83 > --- /dev/null > +++ b/completion/zsh/_bluetoothctl > @@ -0,0 +1,131 @@ > +#compdef bluetoothctl > + > +_bluezcomp_controller() { > + local -a controllers > + bluetoothctl list | > + while read _ MAC NAME; do > + controllers+="${MAC//:/\\:}:${NAME//:/\\:}" > + done > + _describe -t controllers 'controller' controllers > +} > + > +_bluezcomp_device() { > + local -a devices > + bluetoothctl devices | > + while read _ MAC NAME; do > + devices+="${MAC//:/\\:}:${NAME//:/\\:}" > + done > + _describe -t devices 'device' devices > +} > + > +_bluetoothctl_agent() { > + local -a agent_options=(${(f)"$(bluetoothctl agent help)"}) > + agent_options+=help > + compadd -a agent_options > +} > + > +_bluetoothctl_agent_cap() { > + local -a agent_options=(${(f)"$(bluetoothctl agent help)"}) > + agent_options=( "${(@)agent_options:#(on|off)}" ) > + compadd -a agent_options > +} > + > +_bluetoothctl_advertise() { > + local -a ad_options=(${(f)"$(bluetoothctl advertise help)"}) > + ad_options+=help > + compadd -a ad_options > +} > + > +_bluetoothctl() { > + local curcontext=$curcontext state line ret=1 > + > + local -a simple_commands=( > + "help:Display help" > + "version:Dispaly version" > + "list:List available controllers" > + "devices:List available devices" > + "paired-devices:List paired devices" > + "reset-alias:Reset controller alias" > + "default-agent:Set agent as the default one" > + "export:Print environment variables" > + "system-alias:Set controller alias" > + "set-alias:Set device alias" > + ) > + > + local -a toggle_commands=( > + "power:Set controller power" > + "pairable:Set controller pairable mode" > + "discoverable:Set controller discoverable mode" > + "scan:Scan for devices" > + ) > + > + local -a controller_commands=( > + "show:Controller information" > + "select:Select default controller" > + ) > + > + local -a device_commands=( > + "info:Device information" > + "pair:Pair with device" > + "trust:Trust device" > + "untrust:Untrust device" > + "block:Block device" > + "unblock:Unblock device" > + "remove:Remove device" > + "connect:Connect device" > + "disconnect:Disconnect device" > + ) > + > + local -a other_commands=( > + "agent:Enable/disable advertising with given type" > + "advertise:Enable/disable advertising with the given type" > + ) > + > + local -a all_commands=( > + $simple_commands > + $device_commands > + $toggle_commands > + $controller_commands > + $other_commands > + ) > + > + _arguments -C \ > + + '(info)' \ > + '--help[Show help message and exit]' \ > + '--version[Show version info and exit]' \ > + + 'mod' \ > + '(info)--timeout[Timeout in seconds for non-interactive mode]' \ > + '(info)--agent=[Register agent handler]:agent:_bluetoothctl_agent_cap' \ > + + 'command' \ > + '(info):command:->command' \ > + '(info):: :->argument' \ > + ': :_message "no more arguments"' > + > + if [[ $state == "command" ]]; then > + _describe -t commands 'command' all_commands > + elif [[ $state == "argument" ]]; then > + curcontext=${curcontext%:*:*}:bluetoothctl-$line[1] > + case $line[1] in > + (${(~j.|.)simple_commands%%:*}) > + _message "no more arguments" > + ;; > + (${(~j.|.)toggle_commands%%:*}) > + compadd on off > + ;; > + (${(~j.|.)device_commands%%:*}) > + _bluezcomp_device > + ;; > + (${(~j.|.)controller_commands%%:*}) > + _bluezcomp_controller > + ;; > + *) > + if ! _call_function ret _bluetoothctl_$line[1]; then > + _message "Unknown bluetoothctl command: $line[1]" > + fi > + return ret > + ;; > + esac > + fi > +} > + > +_bluetoothctl > -- > 2.22.1 Id love to see this being generated by bt_shell automatically instead i.e ./bluetoothctl --zsh-complete/--bash-complete, that can then be used by the auto complete script generate the commands, which seems to be what you did with help that would print the arguments but done to the commands as well. -- Luiz Augusto von Dentz