From patchwork Thu Apr 22 10:00:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12218135 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07DFFC433B4 for ; Thu, 22 Apr 2021 10:01:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C080E6144D for ; Thu, 22 Apr 2021 10:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235637AbhDVKBm (ORCPT ); Thu, 22 Apr 2021 06:01:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235583AbhDVKBl (ORCPT ); Thu, 22 Apr 2021 06:01:41 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE22C06138B for ; Thu, 22 Apr 2021 03:01:05 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id gq23-20020a17090b1057b0290151869af68bso678012pjb.4 for ; Thu, 22 Apr 2021 03:01:05 -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=6l9/19H8W1JSYN3ievg870oMVAzs3a48rcQq0CQclTk=; b=VVx22evVHX6EzjMSHcyQCYcGRrLksrgqPPCk+3qehH8Q0RUvoj9GnWUc6tKQUfWyHz dn8ETYmaTpnvbwT3Q8Et+Yba+XH+niqJPYX1hwH/avAgQEnS+U/ngxjBA0fUl35UYy0B lt2Lf9AD/16kxN/iUW/k0X3VEhfJ1i8KHYFDNp5GOi+gnuFE71lO0/15XXxZs44dTluR RIHle335t/oiVYr2ogImr2HDDflm5m7xMo7xkJhf/6WGl2+GsDCgeez7Lu1ufczff7yf Bp6ZHMNj4FC6DhWNLfuwDD+zPAPC008RUfmm44TXkXHKR2lqTyjkqpmQY2arXNbYESwm KmmQ== 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=6l9/19H8W1JSYN3ievg870oMVAzs3a48rcQq0CQclTk=; b=Pm/LTGy+Nnbb336vJbRCKKkwp0lmGAoyCzCmKnWVxqhrMUPA4Il8sXOdISdEOQIbaH hUAAAO/v78Bc7iMGQWqWxxdwZ1vCn/DSh8usuKNKNq5Lp+eqMoxs1sBLgy7lp7b7vute tSiKpjMe8dZ0NE7IBZikjjmrJaSW9Ak0DC0BVVZrYOkfZw8NlwUjqgRA7l9snCOYu8K6 9bRok2Ebo4SpTEo9ta0zaZTvo/EXbdmQnJwRNsBv+3jif+0nOdRJXBhW9JQ9oBhXiny8 sENsN2SHRcKMKRcZAIk9bFI/FlzdkLRk2bNcUguXvyNhmKG8g1xpiZjPVtK12kBVAg50 bf7A== X-Gm-Message-State: AOAM530ZzVet6jeuvdO+cAWrUxHFj9eZvwh5vSD9nP0vcQe7X1XMCt/K uL6RB39KB0elhc2VSr3YG80t181kZXg= X-Google-Smtp-Source: ABdhPJxQ3seQmv/ofvdK5k0GankPwW+ySYZffmSCp9pLkgqurfGgGTq4k9rKOo+IC+/svzN2ylBJRw== X-Received: by 2002:a17:90a:6282:: with SMTP id d2mr15738219pjj.168.1619085664731; Thu, 22 Apr 2021 03:01:04 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id r3sm1741314pfl.159.2021.04.22.03.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 03:01:04 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH v2 1/4] git-completion.bash: separate some commands onto their own line Date: Thu, 22 Apr 2021 03:00:49 -0700 Message-Id: <65c485ea0c1726c96d292d7d7385def8d2f19f25.1619085387.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.499.g90b4fd31cd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), a line was introduced which contained multiple statements. This is difficult to read so break it into multiple lines. While we're at it, follow this convention for the rest of the __git_main() and break up lines that contain multiple statements. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c926ca26c6..1dedb14b47 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3400,17 +3400,35 @@ __git_main () while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in - --git-dir=*) __git_dir="${i#--git-dir=}" ;; - --git-dir) ((c++)) ; __git_dir="${words[c]}" ;; - --bare) __git_dir="." ;; - --help) command="help"; break ;; - -c|--work-tree|--namespace) ((c++)) ;; - -C) __git_C_args[C_args_count++]=-C + --git-dir=*) + __git_dir="${i#--git-dir=}" + ;; + --git-dir) + ((c++)) + __git_dir="${words[c]}" + ;; + --bare) + __git_dir="." + ;; + --help) + command="help" + break + ;; + -c|--work-tree|--namespace) + ((c++)) + ;; + -C) + __git_C_args[C_args_count++]=-C ((c++)) __git_C_args[C_args_count++]="${words[c]}" ;; - -*) ;; - *) command="$i"; __git_subcommand_idx="$c"; break ;; + -*) + ;; + *) + command="$i" + __git_subcommand_idx="$c" + break + ;; esac ((c++)) done @@ -3432,7 +3450,8 @@ __git_main () ;; esac case "$cur" in - --*) __gitcomp " + --*) + __gitcomp " --paginate --no-pager --git-dir= From patchwork Thu Apr 22 10:00:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12218137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE5DCC433B4 for ; Thu, 22 Apr 2021 10:01:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 878CE6144D for ; Thu, 22 Apr 2021 10:01:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235742AbhDVKBp (ORCPT ); Thu, 22 Apr 2021 06:01:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235583AbhDVKBn (ORCPT ); Thu, 22 Apr 2021 06:01:43 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D7AC06174A for ; Thu, 22 Apr 2021 03:01:07 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id u15so14712698plf.10 for ; Thu, 22 Apr 2021 03:01:07 -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=kx+fJVZamUGpAY5sKjS7VYX+PeEwWphyhbnMBpr/DAQ=; b=TMsRkpja3TG75jIM1IOa9pY7kBRBUl1yqd6/yUdk9/WOpjv3s/pOM6xuFmfEYD8jA/ L+2Wlo7IwcSenPSFLaUiF1MAxvYvxwlJk3+ZyvDp1FDWpXK2E9RfG7H2hHxdlr2g4BNj 1ppYIVVHM5Ve/hHeRtcvpxp6v778F+iusbJNZWflDFSYIv8MdCj7WZBg3XsCkQepkXPM X7Rrk5SADGlLNc7NLnoMU44iODJDWcvq/x/smPIzvJoCNrf1+4ceVtCpBdDuPBdzHPPs DvfGj1x4X5tyyMj4m3nrn72+0mxyRaVq7z/R5f8CATRUeykMWEt6Z+F30EL8RXrka9Jd BaHg== 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=kx+fJVZamUGpAY5sKjS7VYX+PeEwWphyhbnMBpr/DAQ=; b=mDt5/j7lkmkMH3pc2hsH3W7D1GVH4WJSwtPwip3VCnW5jm2v1Qw/kVJ/YrS6uvEtbt gylkUyPUmsEvGWUeIykHt7b6I353sJ4A3jGU9nNVvI0MQ5zmgcUaK7qsoxaT7cQc3e9I hJOQ1LLzsOI2hFDbBi2z2dqGLER4AE2LOC/ACFCeRKK9UbDmOP/ro/OIqZb/kSOsUu+6 a729SzRPktnBIFfqsfwl/RxJKhNnhdGoGr2aqgp7CmD7P1Xbe0rMCbiveQ6uEATB5Ai3 p+qTh+BSctS3tU2lYWqMreWQ7vJxfWObDPCn+mfaQyRylzD+K+ftoG0lXlPVsS1HwJdp FR2A== X-Gm-Message-State: AOAM5307C+9w93PI9OxEtX0185nIcGtGW/e/0OfhQE0wDhKNxWrXA64p ybdCjcNZ57RFnQaUgOCHxurFwbkGz9k= X-Google-Smtp-Source: ABdhPJwFmPjFHGjO5hTbxvKlgWwnOhol6wywcMPdsB2UKNye04RudZEipPqOr233CMZdVwabsYC8xQ== X-Received: by 2002:a17:90b:813:: with SMTP id bk19mr16218645pjb.108.1619085666877; Thu, 22 Apr 2021 03:01:06 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id r3sm1741314pfl.159.2021.04.22.03.01.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 03:01:05 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH v2 2/4] git-completion.bash: rename to $__git_cmd_idx Date: Thu, 22 Apr 2021 03:00:50 -0700 Message-Id: <76328e3123bd670435632244cbdd0e68db815804.1619085387.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.499.g90b4fd31cd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), the $__git_subcommand_idx variable was introduced. Naming it after the index of the subcommand is needlessly confusing as, when this variable is used, it is in the completion functions for commands (e.g. _git_remote()) where for `git remote add`, the `remote` is referred to as the command and `add` is referred to as the subcommand. Rename this variable so that it's obvious it's about git commands. While we're at it, shorten up its name so that it's still readable without being a handful to type. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 1dedb14b47..c29c129f87 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1474,12 +1474,12 @@ _git_branch () _git_bundle () { - local cmd="${words[__git_subcommand_idx+1]}" + local cmd="${words[__git_cmd_idx+1]}" case "$cword" in - $((__git_subcommand_idx+1))) + $((__git_cmd_idx+1))) __gitcomp "create list-heads verify unbundle" ;; - $((__git_subcommand_idx+2))) + $((__git_cmd_idx+2))) # looking for a file ;; *) @@ -1894,7 +1894,7 @@ _git_grep () esac case "$cword,$prev" in - $((__git_subcommand_idx+1)),*|*,-*) + $((__git_cmd_idx+1)),*|*,-*) __git_complete_symbol && return ;; esac @@ -3017,7 +3017,7 @@ _git_stash () local subcommand="$(__git_find_on_cmdline "$subcommands save")" if [ -z "$subcommand" ]; then - case "$((cword - __git_subcommand_idx)),$cur" in + case "$((cword - __git_cmd_idx)),$cur" in *,--*) __gitcomp_builtin stash_push ;; @@ -3058,7 +3058,7 @@ _git_stash () __gitcomp_builtin stash_branch ;; branch,*) - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then __git_complete_refs else __gitcomp_nl "$(__git stash list \ @@ -3303,7 +3303,7 @@ _git_worktree () # be either the 'add' subcommand, the unstuck # argument of an option (e.g. branch for -b|-B), or # the path for the new worktree. - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then # Right after the 'add' subcommand: have to # complete the path, so fall back to Bash # filename completion. @@ -3327,7 +3327,7 @@ _git_worktree () __git_complete_worktree_paths ;; move,*) - if [ $cword -eq $((__git_subcommand_idx+2)) ]; then + if [ $cword -eq $((__git_cmd_idx+2)) ]; then # The first parameter must be an existing working # tree to be moved. __git_complete_worktree_paths @@ -3395,7 +3395,7 @@ __git_main () { local i c=1 command __git_dir __git_repo_path local __git_C_args C_args_count=0 - local __git_subcommand_idx + local __git_cmd_idx while [ $c -lt $cword ]; do i="${words[c]}" @@ -3426,7 +3426,7 @@ __git_main () ;; *) command="$i" - __git_subcommand_idx="$c" + __git_cmd_idx="$c" break ;; esac From patchwork Thu Apr 22 10:00:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12218141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80D60C433B4 for ; Thu, 22 Apr 2021 10:01:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E6ED6145C for ; Thu, 22 Apr 2021 10:01:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235750AbhDVKBs (ORCPT ); Thu, 22 Apr 2021 06:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235735AbhDVKBp (ORCPT ); Thu, 22 Apr 2021 06:01:45 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFC73C06138B for ; Thu, 22 Apr 2021 03:01:08 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id g1-20020a17090adac1b0290150d07f9402so678349pjx.5 for ; Thu, 22 Apr 2021 03:01:08 -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=4AjfO5qTjdDZZ61yrdxNL4RoAuDFhMXQ7me7ET0YY3I=; b=q7on7goYq1rGfhBMDL6XMDzs1Ec0WN0aOQAYrQG1GFXwS6kT9U/tx4BAB54x/l9P+H 5Z18Z8VzfOeyV9w52AFoVedYaRWryez59PVECb/lUix92qvXTJs6oYGJqyPEfo49jzqM 8Ugszq1KRrhf+uO4hKqL/4eXDMmvnNO+6c2wZh4JMjcDk9weWWwnK5rWevObh7qPEkqd 8qEdv3bCssc6JqCGhz/WRQk91/TepJgOFNlVFDT5E+FHP6URsBDzgo7Uxvoe0r8KZMV2 NX2Xx5jMkGo07ZfbP/265NoDNr4maxzFdbgN5moRG4PtvtZ1OU8YB/IU0kYPtbCFofUd f8ZQ== 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=4AjfO5qTjdDZZ61yrdxNL4RoAuDFhMXQ7me7ET0YY3I=; b=QnfFnKTxS4tM19NGP7xueAO1ABglvQmtfe2v0YsHXwlhcDQjf3Lpu7b1yIOwsL0tk5 pQHtaO6DXn3XKWzVnc43CNGhCfwwnKz8j2dQbcrSnXXd3NyxEljY1tQcHrqoB11BIwRi /woRuntun+M0920Ek3O29vPjRiNeSWAUNV/iWxBfdh86NWG/TgThL0aW4RVvmVw6U2+K Nb2bFDpaUPBTzIkQQ6L4BzVw6TT/5PApY9MUZe7cA2HHPtaCq6o1G0AvHRngJ+iCAaX3 OCrxfubmmLXaCe4Dy5mJbKlMRAz22wVZi7HltH5YlHM3vsM7tX2y6tOyhyEeVpRyW0k1 qFvg== X-Gm-Message-State: AOAM533jZciHfTEhCyaAVTR0xdfoZwLFxWz2ygGb21T8sTeGH6YUn69Y MP2piQUOU3xgAlJrY3wwkQoQJy1H/mI= X-Google-Smtp-Source: ABdhPJwM1+JuZB9rSr1rirpvolucUwkLEBoAlB+bg2XPKz+2xnErFQmFO9S4nWo247kzn5uzqeWx4w== X-Received: by 2002:a17:90a:dc13:: with SMTP id i19mr16449580pjv.194.1619085668112; Thu, 22 Apr 2021 03:01:08 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id r3sm1741314pfl.159.2021.04.22.03.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 03:01:07 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH v2 3/4] git-completion.bash: use $__git_cmd_idx in more places Date: Thu, 22 Apr 2021 03:00:51 -0700 Message-Id: <70fda62db198ad4a25702861565a47ee8f1dd62e.1619085387.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.499.g90b4fd31cd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org With the introduction of the $__git_cmd_idx variable in e94fb44042 (git-completion.bash: pass $__git_subcommand_idx from __git_main(), 2021-03-24), completion functions were able to know the index at which the git command is listed, allowing them to skip options that are given to the underlying git itself, not the corresponding command (e.g. `-C asdf` in `git -C asdf branch`). While most of the changes here are self-explanatory, some bear further explanation. For the __git_find_on_cmdline() and __git_find_last_on_cmdline() pair of functions, these functions are only ever called in the context of a git command completion function. These functions will only care about words after the command so we can safely ignore the words before this. For _git_worktree(), this change is technically a no-op (once the __git_find_last_on_cmdline change is also applied). It was in poor style to have hard-coded on the index right after `worktree`. In case `git worktree` were to ever learn to accept options, the current situation would be inflexible. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 26 ++++++++++++++------------ t/t9902-completion.sh | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index c29c129f87..30c9a97616 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1006,8 +1006,8 @@ __git_complete_revlist () __git_complete_remote_or_refspec () { - local cur_="$cur" cmd="${words[1]}" - local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 + local cur_="$cur" cmd="${words[__git_cmd_idx]}" + local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0 if [ "$cmd" = "remote" ]; then ((c++)) fi @@ -1176,7 +1176,7 @@ __git_aliased_command () # --show-idx: Optionally show the index of the found word in the $words array. __git_find_on_cmdline () { - local word c=1 show_idx + local word c="$__git_cmd_idx" show_idx while test $# -gt 1; do case "$1" in @@ -1221,7 +1221,7 @@ __git_find_last_on_cmdline () done local wordlist="$1" - while [ $c -gt 1 ]; do + while [ $c -gt "$__git_cmd_idx" ]; do ((c--)) for word in $wordlist; do if [ "$word" = "${words[c]}" ]; then @@ -1306,7 +1306,7 @@ __git_count_arguments () local word i c=0 # Skip "git" (first argument) - for ((i=1; i < ${#words[@]}; i++)); do + for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do word="${words[i]}" case "$word" in @@ -1442,7 +1442,7 @@ __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD _git_branch () { - local i c=1 only_local_ref="n" has_r="n" + local i c="$__git_cmd_idx" only_local_ref="n" has_r="n" while [ $c -lt $cword ]; do i="${words[c]}" @@ -2474,7 +2474,7 @@ _git_switch () __git_config_get_set_variables () { local prevword word config_file= c=$cword - while [ $c -gt 1 ]; do + while [ $c -gt "$__git_cmd_idx" ]; do word="${words[c]}" case "$word" in --system|--global|--local|--file=*) @@ -3224,7 +3224,7 @@ _git_svn () _git_tag () { - local i c=1 f=0 + local i c="$__git_cmd_idx" f=0 while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in @@ -3276,9 +3276,11 @@ __git_complete_worktree_paths () _git_worktree () { local subcommands="add list lock move prune remove unlock" - local subcommand + local subcommand subcommand_idx - subcommand="$(__git_find_on_cmdline "$subcommands")" + subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")" + subcommand_idx="${subcommand% *}" + subcommand="${subcommand#* }" case "$subcommand,$cur" in ,*) @@ -3303,7 +3305,7 @@ _git_worktree () # be either the 'add' subcommand, the unstuck # argument of an option (e.g. branch for -b|-B), or # the path for the new worktree. - if [ $cword -eq $((__git_cmd_idx+2)) ]; then + if [ $cword -eq $((subcommand_idx+1)) ]; then # Right after the 'add' subcommand: have to # complete the path, so fall back to Bash # filename completion. @@ -3327,7 +3329,7 @@ _git_worktree () __git_complete_worktree_paths ;; move,*) - if [ $cword -eq $((__git_cmd_idx+2)) ]; then + if [ $cword -eq $((subcommand_idx+1)) ]; then # The first parameter must be an existing working # tree to be moved. __git_complete_worktree_paths diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 04ce884ef5..9439fec8f0 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1879,6 +1879,7 @@ test_expect_success '__git_find_on_cmdline - single match' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1889,6 +1890,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1898,6 +1900,7 @@ test_expect_success '__git_find_on_cmdline - no match' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_must_be_empty actual @@ -1908,6 +1911,7 @@ test_expect_success '__git_find_on_cmdline - single match with index' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1918,6 +1922,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches with index' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1927,11 +1932,23 @@ test_expect_success '__git_find_on_cmdline - no match with index' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_must_be_empty actual ' +test_expect_success '__git_find_on_cmdline - ignores matches before command with index' ' + echo "6 remove" >expect && + ( + words=(git -C remove command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=3 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' + test_expect_success '__git_get_config_variables' ' cat >expect <<-EOF && name-1 @@ -2275,6 +2292,7 @@ do ( words=(git push '$flag' other ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && @@ -2288,6 +2306,7 @@ do ( words=(git push other '$flag' ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && From patchwork Thu Apr 22 10:00:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 12218139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 998C0C433ED for ; Thu, 22 Apr 2021 10:01:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 59C486145B for ; Thu, 22 Apr 2021 10:01:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235754AbhDVKBr (ORCPT ); Thu, 22 Apr 2021 06:01:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235729AbhDVKBp (ORCPT ); Thu, 22 Apr 2021 06:01:45 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A8CEC06174A for ; Thu, 22 Apr 2021 03:01:10 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id u15so14712786plf.10 for ; Thu, 22 Apr 2021 03:01:10 -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=GQHcTnOm+lMh6jNj1vqZGtq66tcB/Q1K3XMjEcn6/eo=; b=k0FBadVQpkeV8BIrZ8PK+/YctOd5RlklRtfTbLgEPKmH+EP5DZNwQL7wKxMDyfrpVD sJgpFuM8uuYFjUhF4LmkJWJjpJk0l8NaLKDjbVXu8QadCLe+8+1iIOiRNX6Fd5mE0mGt iADewqBQ5RnkQx63+AxOzA/Ue4CvGqUCSOMQoA8GURh9Qjx+qp5oWsJckw58oHSok1ni EF07DmhJFaGoK8g2CwfyoZ1KgWEj1ghNyteWLu1l3eCIulHA76CgfUqr1fjn32HXOKWn TQNhuDZECeRBslEaHIx2EF9ROo2RTdeD9UsRbpZCoRl0T7dPzkNLSoUjwuO4cs/9V/t9 1nSA== 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=GQHcTnOm+lMh6jNj1vqZGtq66tcB/Q1K3XMjEcn6/eo=; b=qh8Vt6+C5dTrnqsdWwFk0kK7NuM5ekkD+tmqQ1pHcm8OAD8kp07ySrWudo85GTNKBv 9AzxaJNklVCrJBaBWCV4k744cXFPpZtuZAGiO85kRGoIqxowxZmrXX+RQJwii/TeQDXL Tp45TmXJNPYHy+/KZyyEnZp+zfaDoRXSrlQiVohPejb4vyTzMgmDqsC8eoyZpIGdSHCr YT7OOlDSUc0+2vbSa0mN4tAPj9wjjI7olfwd9Z+PiVtoWPqKJdY9CVD+bLFCqvv+iv1Y x5WdVsVgO2GcYddECCgh0H1HSsFxe4Te/1d1ASLzOzj324ggsxbPZmRTy+oWiTAXnjpC m9Rg== X-Gm-Message-State: AOAM532utHkIm+B+FmWZtFVoDsjJn4Ww8oT1965TbbhdJzN4eUqNyvh7 uUqJYH0WNXoz/UhBdFeD4UTNnd24uWM= X-Google-Smtp-Source: ABdhPJz0T5MqrpQRnCJV48lqDGP9J8R3dIJur8noRs+104mNjIItTs0cuDYTH92qbXy+Zr15cp553w== X-Received: by 2002:a17:90a:ce8d:: with SMTP id g13mr3076922pju.85.1619085669422; Thu, 22 Apr 2021 03:01:09 -0700 (PDT) Received: from archbookpro.localdomain ([172.92.165.181]) by smtp.gmail.com with ESMTPSA id r3sm1741314pfl.159.2021.04.22.03.01.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Apr 2021 03:01:08 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: =?utf-8?q?SZEDER_G=C3=A1bor?= , Junio C Hamano Subject: [PATCH v2 4/4] git-completion.bash: consolidate cases in _git_stash() Date: Thu, 22 Apr 2021 03:00:52 -0700 Message-Id: <103d38e29394d7e4d1bf01817795aed5be568673.1619085387.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.31.1.499.g90b4fd31cd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The $subcommand case statement in _git_stash() is quite repetitive. Consolidate the cases together into one catch-all case to reduce the repetition. Signed-off-by: Denton Liu --- contrib/completion/git-completion.bash | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 30c9a97616..7bce9a0112 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -3032,21 +3032,6 @@ _git_stash () fi case "$subcommand,$cur" in - push,--*) - __gitcomp_builtin stash_push - ;; - save,--*) - __gitcomp_builtin stash_save - ;; - pop,--*) - __gitcomp_builtin stash_pop - ;; - apply,--*) - __gitcomp_builtin stash_apply - ;; - drop,--*) - __gitcomp_builtin stash_drop - ;; list,--*) # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show() __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options" @@ -3054,8 +3039,8 @@ _git_stash () show,--*) __gitcomp_builtin stash_show "$__git_diff_common_options" ;; - branch,--*) - __gitcomp_builtin stash_branch + *,--*) + __gitcomp_builtin "stash_$subcommand" ;; branch,*) if [ $cword -eq $((__git_cmd_idx+2)) ]; then @@ -3069,8 +3054,6 @@ _git_stash () __gitcomp_nl "$(__git stash list \ | sed -n -e 's/:.*//p')" ;; - *) - ;; esac }