From patchwork Mon Jan 28 09:41:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Duy Nguyen X-Patchwork-Id: 10783465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A96616C2 for ; Mon, 28 Jan 2019 09:42:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E9EF2A61B for ; Mon, 28 Jan 2019 09:42:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82FEF2A602; Mon, 28 Jan 2019 09:42:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F32822A61B for ; Mon, 28 Jan 2019 09:42:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbfA1JmG (ORCPT ); Mon, 28 Jan 2019 04:42:06 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38101 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbfA1JmG (ORCPT ); Mon, 28 Jan 2019 04:42:06 -0500 Received: by mail-pl1-f195.google.com with SMTP id e5so7508409plb.5 for ; Mon, 28 Jan 2019 01:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tJVodi4wuBKE9ISqxzqIAaoKN/YbqMRC85zVrRMzUE0=; b=kPdHlX8HDcyQQO4BmFsjRduJIEjGnB3iWgVbiBAXOZxCYpeuYhuyna1VbzQHK8Yow/ N5TdSEhOAq9g3iV7fFQBY58m+m1dMwBlGFg3UcyVVcRU0tu2cPpB4MrreQNXz3WHjbQL bywLcmriCu14rg+UNwsqeZ9Bj6DX7oiwupz0b/r81u+85BOktAJnagh3+ksOS0QfQTmN AkvtAtVflzoFd5W+jmPVT6KKfNS3mawN/ME0oZ5Bq84dE1PrBc2LdF0zJMKMgTiMqXdk o+KVtbZUMu8TNop+cnQXl7ZMOz7NKu79TWVewaahMhcTXj0+SZUx7Msuv081etngAoCG CKSw== 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:mime-version :content-transfer-encoding; bh=tJVodi4wuBKE9ISqxzqIAaoKN/YbqMRC85zVrRMzUE0=; b=e5IISRLG+rVMYRuWePn0TcobX/Q4NmwXxQDbkWW4sChCvc2NT0GF5jTyKvtg+7HnvN AJ3i2iF3mQNurLVCI1O1znQPoOG65xkLB9VdPtZVB0Z4C+ntrXgXkLkuG2IPtHCLP7Un qfF5SQNiuEc4XoEMdo2RfDhi7XNPlzfmEf1qcyejGVPibv/fk4iAGQe55hR5gHxVS7jI 3+P9WfEFHIUTqTJyhMgbUvbDl/4nhYFas0i1aTHvt4X8m3N1z89uZ3LWu/aNfYLCCxVK 4eWnToX+ybhQo+NPOOeFFOEUafIYz1lyDfed4r34kJwLX2aevCHIcF16yL0T0HStINN1 pc8A== X-Gm-Message-State: AJcUukcexFSQRpfuKtj4x8jhoPSpM5B5l8tpfEd6htQDVqDt5LC4cJaG id72Y8cYvXuLPht3/8DXa48ps+qn X-Google-Smtp-Source: ALg8bN65iCd6imHSI5Q5Z1VcgQ7plsxUEWr/AdNHrL+LqkusDrKA37YXkbGZvRFghae/MP4jVaU9EQ== X-Received: by 2002:a17:902:4d46:: with SMTP id o6mr20210927plh.302.1548668525001; Mon, 28 Jan 2019 01:42:05 -0800 (PST) Received: from ash ([115.72.21.220]) by smtp.gmail.com with ESMTPSA id m67sm54725957pfb.25.2019.01.28.01.42.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 01:42:03 -0800 (PST) Received: by ash (sSMTP sendmail emulation); Mon, 28 Jan 2019 16:42:00 +0700 From: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= To: git@vger.kernel.org Cc: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= Subject: [PATCH/RFC] completion: complete refs in multiple steps Date: Mon, 28 Jan 2019 16:41:55 +0700 Message-Id: <20190128094155.2424-1-pclouds@gmail.com> X-Mailer: git-send-email 2.20.1.560.g70ca8b83ee MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is in the same spirit of f22f682695 (completion: complete general config vars in two steps - 2018-05-27). Instead of considering all full refs as completion candidates, it completes one "path" component at a time, e.g. $ git switch-branch -d j jch/ junio-gpg-pub $ git switch-branch -d jch/ Display all 154 possibilities? (y or n) jch/ab/ jch/fc/ .... $ git switch-branch -d jch/nd/ jch/nd/attr-pathspec-fix jch/nd/attr-pathspec-in-tree-walk ... For refs organized in multiple levels like this (and I've seen refs in 4 levels), especially when there a lot of refs, incremental completion this way makes it easier to get to what you want. The cost of course is more complicated completion and also slower on systems with slow process creation. So maybe there will be a switch to turn this on or off? Signed-off-by: Nguyễn Thái Ngọc Duy --- contrib/completion/git-completion.bash | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 499e56f83d..d74ee79866 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -742,6 +742,17 @@ __git_refs () esac } +__git_collapse_refs () +{ + local regex="$(echo "$1" | sed 's/[^/]\+/[^\/]*/g')" + case "$regex" in + '') regex='[^\/]*';; + */) regex="${regex}[^/]*";; + esac + regex="$(echo "$regex" | sed 's/\//\\\//g')" + sed -ne "s/\\($regex\\/\\?\\).*/\\1/p" +} + # Completes refs, short and long, local and remote, symbolic and pseudo. # # Usage: __git_complete_refs [