Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp255326ybl; Fri, 16 Aug 2019 23:41:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqyrqllmEYWSjEXrcYpYnteK9OgfpIMiPO4ZOFRuuf1l04m0su66N3AsowxTHygt7FqVwfh7 X-Received: by 2002:a63:2ec9:: with SMTP id u192mr10591737pgu.16.1566024089313; Fri, 16 Aug 2019 23:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566024089; cv=none; d=google.com; s=arc-20160816; b=na0IEOGy+rnOJnEbfjm2TBKM9bumYRc2MiL7zmfVGnPygNHoiDPg+/rUyag9nsvTWq uOY1ruKwgxRFwF8qMjfhLDhPK+7ZpE7npIkR4scc1w2ci5XPv9VXx/7Kod64Cqd3+Hvr +o2U700q+HHX885ztZBxrNCWSvatS0HdsV7xUC4vMDdNm/lwU/C53JoP7thGRaqE43YI z4nRyjiBaS4in2Ot0sQ2r71oEdXylTDbTqg1kSRZ3bYwEAEb/0GzNEySyrViXYjXqatQ OZkXvNaDYKJXoccSXjPxWu+P5niZ3T6kSABbjyA7sqwbAmmWum5TzcouC7s3PVhiSKUz VF5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=h7J78+yYEVX/qg68EjqNRm2MvZOEsuNNwozKTRzm5X8=; b=u5gaCyLx27vHEE8XKAfunPnm32GubKLG5p22H4GJyA8RktMHUXwQWbZc2TgWa7TDJg fFxQah2Ew/WpkkQ8LYJQ0QanAEvAp3xiNiFFNcnsHtMl/19SQaTU7xJkrC4+d0D7UEuC fO8J5TLydVCBm1ZXjMipfYKSyUvE/BV6crbKTywVGx/lQ549woMmUacTT/1Pa81EiZ8n hC50He9pl4om+IMshI0k0IET172gx6cFmGsmzCdpP8jmY/nFX+BEINjHOyXfK+NnkISu hcGtQEZUL0AW6ohO0pKsRlP7MiVe5W7SFp+w2rTbMvEm+L2LSymYxq6uor4LEn7VuTN5 54dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=coCdn2Ym; 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 j187si5208909pge.591.2019.08.16.23.41.15; Fri, 16 Aug 2019 23:41:29 -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=coCdn2Ym; 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 S1726208AbfHQGg1 (ORCPT + 99 others); Sat, 17 Aug 2019 02:36:27 -0400 Received: from mail-pl1-f179.google.com ([209.85.214.179]:36513 "EHLO mail-pl1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726128AbfHQGg1 (ORCPT ); Sat, 17 Aug 2019 02:36:27 -0400 Received: by mail-pl1-f179.google.com with SMTP id g4so3349602plo.3 for ; Fri, 16 Aug 2019 23:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h7J78+yYEVX/qg68EjqNRm2MvZOEsuNNwozKTRzm5X8=; b=coCdn2Ymo5DSO2nj1weeHEhO3gbTznKNJ/AuH80+AYXL+gm/dhru5i71Va5Iah6Un/ rxswtqWJ7L+aXXkhnnMD3yFXJPGzzav4wrOG9Fm+XwuIaEIvIoMl6Ys2xh0YSCxOg7Rt eYskSn5UXiPkDJM3Ss6axI2GO2n0O58H3j2dVR3L2s/QSCoC+4NS5GzZfhc88hHAARUm ngOttPqkMulXT4wyFmvpVbsdMmku6vnrDMrvoYhPOpZGmxG+f02otLsP2ygv+FbAWSiZ PE4T7zhmsaFUkH1V/UGs0S5U7FiaPER1H0fSLwZE60dNVLCqtql/4Eo1UBXP6OnT9P+f CNiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h7J78+yYEVX/qg68EjqNRm2MvZOEsuNNwozKTRzm5X8=; b=KzBGgj1h8sKuFsc6r1IxkIfSQQ1P0716+TaDJ6PbKuddssx5XC6YcYiwB1dG6OwNyv JttuY7ss13TkrrdZY5pqlJu2JKyG9RaDp/kELjXJfyR2tCDZ2PWNUTMeAEAIlOpA2ADE R7XGcdGi1DopykAkBrVMN9LhFQEbpFqjaHEpwOPteGYPhvFuoe7FO4zD7T2Br+VzniWQ yBJoNayJ46v7TkCdwHmnjrhVKXmclutL9sQ5DeyO0cvN44U89RDRW27y02yq6ZBLiWr7 XAAZTdf2JogkVqCGLodYTyMfvdb/XB8USypXkNwLQq91/rQ2Zy16isbFKxyLwf8XkPNR pKFQ== X-Gm-Message-State: APjAAAXsgMj0R/kGi0u77S5YFvCj1Gw9H8BD0ti1oGzKQMHfced04zl1 B+Q6nHGwk3oLRutMvnZO0n4D+3g= X-Received: by 2002:a17:902:760e:: with SMTP id k14mr12468091pll.161.1566023786267; Fri, 16 Aug 2019 23:36:26 -0700 (PDT) Received: from rxps.home ([2600:8800:1e00:242:3550:edee:2708:4ad0]) by smtp.gmail.com with ESMTPSA id y128sm6684095pgy.41.2019.08.16.23.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2019 23:36:25 -0700 (PDT) From: Ronan Pigott X-Google-Original-From: Ronan Pigott To: linux-bluetooth@vger.kernel.org Cc: Ronan Pigott Subject: [PATCH BlueZ v2 2/4] shared/shell: add --zsh-complete option Date: Fri, 16 Aug 2019 23:34:50 -0700 Message-Id: <20190817063452.23273-3-rpigott@berkeley.edu> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20190817063452.23273-1-rpigott@berkeley.edu> References: <20190817063452.23273-1-rpigott@berkeley.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Ronan Pigott This adds a new long form option --zsh-complete to provide all available commands in an output format suitable for parsing by zsh or other shell completion scripts. Invoke like: `bluetoothctl --zsh-complete help` There is no corresponding short form option. --- src/shared/shell.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/shared/shell.c b/src/shared/shell.c index eac654f40..bbf9f9e7a 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -79,6 +79,7 @@ static struct { int argc; char **argv; bool mode; + bool zsh; bool monitor; int timeout; struct io *input; @@ -98,6 +99,7 @@ static struct { } data; static void shell_print_menu(void); +static void shell_print_menu_zsh_complete(void); static void cmd_version(int argc, char *argv[]) { @@ -288,6 +290,11 @@ static void shell_print_menu(void) if (!data.menu) return; + if (data.zsh) { + shell_print_menu_zsh_complete(); + return; + } + print_text(COLOR_HIGHLIGHT, "Menu %s:", data.menu->name); print_text(COLOR_HIGHLIGHT, "Available commands:"); print_text(COLOR_HIGHLIGHT, "-------------------"); @@ -314,6 +321,22 @@ static void shell_print_menu(void) } } +static void shell_print_menu_zsh_complete(void) +{ + const struct bt_shell_menu_entry *entry; + + for (entry = data.menu->entries; entry->cmd; entry++) { + printf("%s:%s\n", entry->cmd, entry->desc ? : ""); + } + + for (entry = default_menu; entry->cmd; entry++) { + if (entry->exists && !entry->exists(data.menu)) + continue; + + printf("%s:%s\n", entry->cmd, entry->desc ? : ""); + } +} + static int parse_args(char *arg, wordexp_t *w, char *del, int flags) { char *str; @@ -1015,6 +1038,7 @@ static const struct option main_options[] = { { "help", no_argument, 0, 'h' }, { "timeout", required_argument, 0, 't' }, { "monitor", no_argument, 0, 'm' }, + { "zsh-complete", no_argument, 0, 'z' }, }; static void usage(int argc, char **argv, const struct bt_shell_opt *opt) @@ -1075,6 +1099,9 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt) case 't': data.timeout = atoi(optarg); break; + case 'z': + data.zsh = 1; + break; case 'm': data.monitor = true; if (bt_log_open() < 0) { -- 2.22.1