From patchwork Tue Sep 12 17:30:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13381973 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54511EE3F06 for ; Tue, 12 Sep 2023 17:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235336AbjILRah (ORCPT ); Tue, 12 Sep 2023 13:30:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233439AbjILRaf (ORCPT ); Tue, 12 Sep 2023 13:30:35 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB4010E9 for ; Tue, 12 Sep 2023 10:30:31 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-403061cdf2bso33678565e9.2 for ; Tue, 12 Sep 2023 10:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694539830; x=1695144630; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=iGLZDG45u80sd4JuCS1XmO732v/Nhixwl2/JhbF2oqQ=; b=W8iJDjmc1dDhmlBOwupjIJrrdiUaHykuvQWHn2BBOGvg/9wptQMQ96mYz5GCbjmT3O D19DXRpGJKwnBNrqDSpN4VWhgG7Yrc4AjCqvWZMNuTKF2C+XJBo5MUOdGG6MdbRyMfdB bxuU3klhANj6AoqMBsa/FlDr1mKZHemYG+Wqb9+7hOgpWWRdlfheZzlLP8GY1iI0x6wK lLBzIeBFSE+zC1BUb3TI3xL95NeE85uPnDIl/1ZAANfVCNYg8/dXlGcXrDGHGMOjgrX5 o5mzhkfiXAazsE8/413yTw3M5FkhEdzCpxYY5NRXbX2SkZu7RblySC0V5rfaQx3SXJMg hLGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694539830; x=1695144630; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iGLZDG45u80sd4JuCS1XmO732v/Nhixwl2/JhbF2oqQ=; b=GiO55PyT8z/8BO4aWf8+LjjCOJWTyjBCrXujAsQ4q/ReHXANAPQOrr5if4qjWs/qw8 DlzejhguuAzyngZOTGe9AAw6cM6RX6I9KIYufjb3d26iOkg/bjsdDmJpQJru8anQm0mS 59poaZZPXAjZxUPrU0aB+wEwtDDNL6YQcyo+pmunTO0Wus8FQd8liku70j8yR93TtDBD K5XiMA/R6TnDcTE+j5X0bcTr6Zfu1XW7BIX5QNsX/iONLt03z8xaQg0cETscDsFTQsMw T/G61XVtVrRR/V6Y/afgotzh35FYzdjTX1g7F18yL4r4hZGre1HPywTfMS8C+ZcOWW+k EUpg== X-Gm-Message-State: AOJu0Yz3wEhkBPSR7v6dSseC6Uyq0asZvC553kOz+6WfW44QwO7Fnphh 4dbUpe6cNNG1CpK266VnnR7HPTPDN7w= X-Google-Smtp-Source: AGHT+IHK0Cy6j5tK5hmtvOTW0jZpBOzz/+1xndrBVO63afvXYj9LRJgXB0Aim17wURJEPRGRbUtsoA== X-Received: by 2002:a7b:c846:0:b0:3fc:3e1:7105 with SMTP id c6-20020a7bc846000000b003fc03e17105mr100269wml.24.1694539829715; Tue, 12 Sep 2023 10:30:29 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n21-20020a1c7215000000b003fc16ee2864sm13330700wmc.48.2023.09.12.10.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 10:30:29 -0700 (PDT) Message-ID: In-Reply-To: References: Date: Tue, 12 Sep 2023 17:30:26 +0000 Subject: [PATCH v2 1/2] completion: commit: complete configured trailer tokens Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Martin =?utf-8?b?w4VncmVu?= , Philippe Blain , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git commit' can add trailers to commit messages. To make that feature more pleasant to use at the command line, update the Bash completion code to offer configured trailer tokens. Add a __git_trailer_tokens function to list the configured trailers tokens, and use it in _git_commit to suggest the configured tokens, suffixing the completion words with ':' so that the user only has to add the trailer value. Signed-off-by: Philippe Blain --- contrib/completion/git-completion.bash | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 133ec92bfae..b5eb75aadc5 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1677,6 +1677,11 @@ _git_clone () __git_untracked_file_modes="all no normal" +__git_trailer_tokens () +{ + git config --name-only --get-regexp trailer.\*.key | awk -F. '{print $2}' +} + _git_commit () { case "$prev" in @@ -1701,6 +1706,10 @@ _git_commit () __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" return ;; + --trailer=*) + __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":" + return + ;; --*) __gitcomp_builtin commit return From patchwork Tue Sep 12 17:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Blain X-Patchwork-Id: 13381975 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49518EE3F08 for ; Tue, 12 Sep 2023 17:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236614AbjILRaj (ORCPT ); Tue, 12 Sep 2023 13:30:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234884AbjILRah (ORCPT ); Tue, 12 Sep 2023 13:30:37 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E07CF10E9 for ; Tue, 12 Sep 2023 10:30:32 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-401b3ea0656so62607185e9.0 for ; Tue, 12 Sep 2023 10:30:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694539831; x=1695144631; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SCEE7bxn8DL/IYEyVMPx1uPofEtxbqkzxdOTcvbruZI=; b=Nrd0RT9RQ7q3Q7M7fr7YNFwU9mhOqeybjcfKC9dyekv8vXhmacDqa+v/HChrrCdYvt E/oX/2KoEETr7/+9W5PzHrmvKTLpd+h2JxmTBHOvvLM5YrnH2GzvVMGpvOh79aFJjoHC 4nUIgFkInFTT+2RCpu4GE4DhrYQ7vGOSL5Fj6KUFiejyojrlzteEqm269TLaZpfbSHeL u4IvU1TYeyQzc52lxqkKeKwRzPmify+PnAv5g9hLJPXlLCxnQrwitcOXcBVBN7KFs/ur yAko/jngFckxzBVAlLySaR/+318/kvp980ZT5tZGIEW3gc2HzIzgiBpaT9BZTQiSiOTa va3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694539831; x=1695144631; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SCEE7bxn8DL/IYEyVMPx1uPofEtxbqkzxdOTcvbruZI=; b=jsDYuWxQO/kb8/6OD1h1ioR1EUHrzlscXIvvyciXasYIGZKk7lc3zTal+baymjbi7E 4Z+tHFJVvKwt4oXdRiOHjPyEHw/IxCY2XFHx8AerN3pEvQRIy89cUaU2r9VL43nSD8+9 BmRDQHwsJ2Z9VEW9aJCzqKWootlux7pnVROi6jIqhboXRlagnCwZes07+U52OIbNm8+K vtpk0NLOnRRMptyWQo61ocbvzpK20KMIHR0huyk5dY6AFmU6PI94ccjfY4yrjdafTtRB RAvGAjW8Z1sROiVUSn9HZaQevTA5zZ/I9q61kbi6TkfFA22ZpitIq6liIN2kwwU6yuDa ipPA== X-Gm-Message-State: AOJu0YwKtv8Ews01hp4t4orUclmxvO3EZXnjEW/A5j9iOjCg88D5dS2P fUwyUUXssY/GLKOsMsEGHFmrkhiP0ZY= X-Google-Smtp-Source: AGHT+IH81WVZUgVHtWfQwT0SDDzp5AdVF0NvXpECXNKkd6rhbKMPDzi/NRL4fwliZqzF6eI4fhk1jA== X-Received: by 2002:a7b:cd1a:0:b0:402:f5c4:2e5a with SMTP id f26-20020a7bcd1a000000b00402f5c42e5amr68652wmj.37.1694539830722; Tue, 12 Sep 2023 10:30:30 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n17-20020a1c7211000000b003fe1630a8f0sm16550247wmc.24.2023.09.12.10.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 10:30:30 -0700 (PDT) Message-ID: <9cb33c20294e096f5345fb1ea9d80a23e899ae6f.1694539827.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Tue, 12 Sep 2023 17:30:27 +0000 Subject: [PATCH v2 2/2] completion: commit: complete trailers tokens more robustly Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: ZheNing Hu , Martin =?utf-8?b?w4VncmVu?= , Philippe Blain , Philippe Blain , Philippe Blain Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Philippe Blain From: Philippe Blain In the previous commit, we added support for completing configured trailer tokens in 'git commit --trailer'. Make the implementation more robust by: - using '__git' instead of plain 'git', as the rest of the completion script does - using a stricter pattern for --get-regexp to avoid false hits - using 'cut' and 'rev' instead of 'awk' to account for tokens including dots. Signed-off-by: Philippe Blain --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index b5eb75aadc5..c23465886e0 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1679,7 +1679,7 @@ __git_untracked_file_modes="all no normal" __git_trailer_tokens () { - git config --name-only --get-regexp trailer.\*.key | awk -F. '{print $2}' + __git config --name-only --get-regexp '^trailer\..*\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev } _git_commit ()