From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43443-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.1 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id ac6f0c8b for ; Tue, 11 Sep 2018 13:25:16 +0000 (UTC) Received: (qmail 5859 invoked by alias); 11 Sep 2018 13:24:35 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43443 Received: (qmail 18968 invoked by uid 1010); 11 Sep 2018 13:24:34 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-2.6/5.0):. Processed in 5.037226 secs); 11 Sep 2018 13:24:34 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=BjBnpN WHPXgVuDhcHBoJ2STQKfX+pBwmlNkm5IJoUo4=; b=CcYJ//AJ6LepSGHNtl9MUq dTYchNbuI0w8Oc1HfbQGQ3ctJCqsGyi3MBsFWWSMX1MuVqqTsO7VDowmt/zyuh1w RVQ0FJZFm/38vOCHCOZyHzrD9nJnHRK6urmzMLBnVfBj2uY9QrGLTG9WfkZjNBEb 9W5FRvEtY8/r6QSP9pR+0jQgii/RuEkZfh/YmT3DJVn5gNDz2VDL1wnyLMZ8Glps jE6bvtPtxY2BwSTKxVjLxtvbhFSRtW9ciSgxf48ybtFN1RwqOlZsee0wcCE2FBB3 bxR0RZPH3pa3CRo0D24DCgl4eOsuyNweNgPBImZTW2+0vRhVJLtDWw/XpD7qz8qA == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=BjBnpN WHPXgVuDhcHBoJ2STQKfX+pBwmlNkm5IJoUo4=; b=dGU5Kziyu9EIJmIMlc+Yd9 zl3LL4NghOGh2iINBT7hidMaTfsT6K5JTst8V9h4bYXEW1qUJbhbi0QWZrUucLmO tu5XHR1Iq7LLhJJGozFZXQh4tsT6T/j0gK88qT5cHGQvSDidUnd1L371LCNUAZi5 QylqwoZF5fsbxnB+ryhDTMjhUyxb4TD2hXyJ6sPWEa71BygSbTDZEZLYq7H6A3U+ ziEBvP6+/THNLLdcjwUBgvd0WKZZQp7YQeVQhz90Hh16d/sKwMxKdsv7ZmhwewCn pTxxTzXoNTBYIUMGWz/9yaJJGQNpHAf8T/uH7FcMTJImr/7o58wedtBCcJNK1/Xg == X-ME-Proxy: X-ME-Sender: From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 2/2] _git: When completing worktrees, show the ref and hash of each worktree. Date: Tue, 11 Sep 2018 13:24:21 +0000 Message-Id: <20180911132421.13932-2-danielsh@tarpaulin.shahaf.local2> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180911132421.13932-1-danielsh@tarpaulin.shahaf.local2> References: <20180911132421.13932-1-danielsh@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- This part is independently useful. The hash is truncated to 9 nibbles; should that be changed? Mikael, interesting idea. I think I'll try this: _git-cd() { (( ${+functions[_git]} )) || { autoload +X -U _git && _git } __git_worktrees "$@" || ${_comps[cd]} "$@" } git() { if [[ $1 == cd ]]; then shift ; builtin cd "$@" ; return $? fi ⋮ } Cheers, Daniel Completion/Unix/Command/_git | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index b2f93ff0f..32e5566e9 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -7561,8 +7561,25 @@ __git_browsers () { } __git_worktrees () { - _wanted directories expl 'working tree' compadd -S ' ' -f -M 'r:|/=* r:|=*' \ - ${${(M)${(f)"$(_call_program directories git worktree list --porcelain)"}:#worktree*}#* } + local -a records=( ${(ps.\n\n.)"$(_call_program directories git worktree list --porcelain)"} ) + local -a directories descriptions + local i hash branch + for i in $records; do + directories+=( ${${i%%$'\n'*}#worktree } ) + hash=${${${"${(f)i}"[2]}#HEAD }[1,9]} + branch=${${"${(f)i}"[3]}#branch refs/heads/} + + # Simulate the non-porcelain output + if [[ $branch == detached ]]; then + # TODO: show a ref that points at $hash here, like vcs_info does? + branch="(detached HEAD)" + else + branch="[$branch]" + fi + + descriptions+=( "${directories[-1]}"$'\t'"$hash $branch" ) + done + _wanted directories expl 'working tree' compadd -ld descriptions -S ' ' -f -M 'r:|/=* r:|=*' -a directories } (( $+functions[__git_difftools] )) ||