From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13404 invoked by alias); 21 May 2018 20:45:20 -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: 42810 Received: (qmail 1033 invoked by uid 1010); 21 May 2018 20:45:20 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f54.google.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(74.125.82.54):SA:0(-1.9/5.0):. Processed in 2.160601 secs); 21 May 2018 20:45:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: pseyfert.mathphys@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=G5LenAcI8RuMve8VVfK1LhMe7kI7+cGigC5CaDhuRTw=; b=rPeyNuT+u+0Xwm1sI8XGDfskRDnX5/SluvfpNlYGerQvQPPjClD8LDhL/gre6iLKpS zq3ZddpICvDrkJfxm3p6FK1SBN7Ty2JzI/NIG6Gsy0HCVtUWFElTfEIcEm90yyzMSpm6 Wju3mbQgGKEHvxlKjikBhyPl4hBApJC6tHc60t95+wG+ljF5PvTYSMYxNEnxGk48qtd3 s0t5t0BZi2TmzJFEVZTA+7PtgL3QUHaZ5K0gpU9mrkGcIb8U6/+aTUJDum53ID/ML2Qn ThWI/HR0+8PJmNdtbOEugyQiyrq7IKqgjfPG/lfeqH3WWxqVN/d8LVxL7aecUNt7AzZX PL2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=G5LenAcI8RuMve8VVfK1LhMe7kI7+cGigC5CaDhuRTw=; b=eoQ/r8aPdOdqd6uTyC+qjfwcTayqoFYf3+oZBJfTvaEmxEw9FeVxLKOSUeOnDuk8/l FhHZopJnq2VKAfnvl2yaAMENdEIYPCvK6hzFSYQCP+1n2I4mFccGrLaqYfupdIV4KK3P AZ/FoLqg5B55F+KQU7G730W07BXAiZPYchZbwTQAKdGc80iydyRjTdbprhLQiv6Kj439 2BZQORGK3hRGh5Pp7L7Bq6a55S68uTkiGGvt0Wacbp1OPDZCHoDHUv6m4PgIgDjSD2m1 WmB6JW7isQSB0vjnB7IpZJqKYdp0Aq0JihqizFrhca4F0uqflfc6xaIpQkm2+ij7ZoE/ 9xOQ== X-Gm-Message-State: ALKqPwcm5PDPDfsb8NAKCz8Xv0jFoIufmi9DLrvbWCDepziB6oTN1iSB kwc5lEbhjiw9ipqaSQj3EEU= X-Google-Smtp-Source: AB8JxZow4GfBr/wT5Os1pKGxUHmYS/ghp1Ep86LdAq87IpLEbMMeAus1XJqBh7ww12JJel8djAcjyg== X-Received: by 2002:a1c:be0f:: with SMTP id o15-v6mr233643wmf.104.1526935514042; Mon, 21 May 2018 13:45:14 -0700 (PDT) Date: Mon, 21 May 2018 22:45:13 +0200 From: pseyfert To: zsh-workers@zsh.org Cc: pseyfert.mathphys@gmail.com Subject: git remote set-url completion Message-ID: <20180521204513.GA26538@robusta> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.0 (2018-05-17) Dear zsh-workers, I was not happy with the completion of git remote set-url TAB in my usage this should yield the same completions as `git clone TAB` (a url like https://gitlab.my_project.tld or git@github.com or some path to a local repository) So I put the below patch together which uses __git_repositories (and _urls) instead of _urls. I also saw there was a todo left in _git for doing git remote set-url which used to just use _urls for the completion of old url, here I get the output of `git remote get-url --all` Ideally I would like to also cover git remote set-url --push TAB which should then complete the output of `git remote get-url --push --all` But atm I don't understand what the current completion does, because git remote set-url --push TAB just suggests --add and --delete. Find my patch below. Thanks for consideration, Paul diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git index 21ba65724..e58340d8d 100644 --- a/Completion/Unix/Command/_git +++ b/Completion/Unix/Command/_git @@ -3600,10 +3600,7 @@ _git-remote () { ':repository:->repository' && ret=0 case $state in (repository) - _alternative \ - 'local-repositories::__git_local_repositories' \ - 'remote-repositories::__git_remote_repositories' \ - 'urls::_urls' && ret=0 + __git_repositories_or_url && ret=0 ;; esac ;; @@ -3634,14 +3631,17 @@ _git-remote () { '*: :__git_branch_names' && ret=0 ;; (set-url) - # TODO: Old URL should be one of those defined for the remote. + # TODO: Old URL does not get completed if --push, --add, or --delete are present + # TODO: assumes $line[1] is always the remote name + _message "the line is: $line" _arguments -S -s \ '(3)--push[manipulate push URLs instead of fetch URLs]' \ '--add[add URL to those already defined]' \ '(3)--delete[delete all matching URLs]' \ ': :__git_remotes' \ - ':new url:_urls' \ - ':old url:_urls' && ret=0 + ':new url:__git_repositories_or_url' \ + ':old url:__git_current_remote_url $line[1]' \ + && ret=0 ;; (show) _arguments -S \ @@ -6949,6 +6949,21 @@ __git_local_repositories () { _wanted local-repositories expl 'local repositories' _directories } +(( $+functions[__git_repositories_or_url] )) || +__git_repositories_or_url () { + _alternative \ + 'repositories::__git_repositories' \ + 'url::_urls' +} + +(( $+functions[__git_current_remote_url] )) || +__git_current_remote_url () { + # TODO: is ${(@)*[1,4]} a proper replacement for $* and passing extra arguments? + # TODO: add --push to the `git remote get-url` command in case `git remote set-url --push origin ` is completed + _wanted remote-urls expl 'current urls' \ + compadd ${(@)*[1,4]} - ${${(0)"$(_call_program remote-urls git remote get-url $5)"}%%$'\n'*} +} + (( $+functions[__git_any_repositories] )) || __git_any_repositories () { # TODO: should also be $GIT_DIR/remotes/origin