Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: git remote set-url completion
- X-seq: zsh-workers 43359
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: pseyfert <pseyfert.mathphys@xxxxxxxxx>
- Subject: Re: git remote set-url completion
- Date: Fri, 31 Aug 2018 22:54:51 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1535748894; bh=LPs/fNrDuH1Rtk0SXg73ED7O/bsU/Slp9VIkgm+ZsHg=; h=From:References:To:Subject:Date:From:Subject; b=TI5cp50PbNgMLhPS4XFeM6Lo41T81pZBOcC+8SL1hKUpLlNWMnp0EWaUilKgHEcWiRWk+IGXjZAcgnBT5a/DpNSG3EANrbBr9RJfwD98hmpzZqlLUCAIW5w7xHGu9+ot+iNr2G//kINMyCd6HhPzXoxeoDcCW1lapmgU+m4XCRzUhyd8pVzUVtk67pyPLezNWegAXgP2dWcsGrhZH2f+4Y03judsY8zkyFuAKgJ5VtLx+WmDrGmxYTLyocA7sRE2P3hBLKUkEz7lyYRL7/lVcYwDncE8MN1vgyqsQDorRuGwK7dogePFgigqQHgqz8btnXy76nXVx9sLsPCuXz4EnQ==
- In-reply-to: <20180521204513.GA26538@robusta>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20180521204513.GA26538@robusta>
On 21 May, pseyfert wrote:
> I was not happy with the completion of
> git remote set-url <some remote> TAB
...
> So I put the below patch together which uses __git_repositories (and _urls) instead of _urls.
The following patch is to be applied after Paul's original patch from
42810. It covers the things I mentioned in my reply to the original
message.
Oliver
diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index c9201bea2..2cae4c82f 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -3607,12 +3607,7 @@ _git-remote () {
'(-m --master)'{-m,--master=}'[set HEAD of remote to point to given master branch]: :__git_branch_names' \
'--mirror[do not use separate remotes]::mirror type:(fetch pull)' \
':name:__git_remotes' \
- ':repository:->repository' && ret=0
- case $state in
- (repository)
- __git_repositories_or_url && ret=0
- ;;
- esac
+ ':repository:__git_repositories_or_urls' && ret=0
;;
(get-url)
_arguments -S -s \
@@ -3641,17 +3636,13 @@ _git-remote () {
'*: :__git_branch_names' && ret=0
;;
(set-url)
- # 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:__git_repositories_or_url' \
- ':old url:__git_current_remote_url $line[1]' \
- && ret=0
+ _arguments -S \
+ '--push[manipulate push URLs instead of fetch URLs]' \
+ '(3)--add[add URL to those already defined]' \
+ '(2)--delete[delete all matching URLs]' \
+ '1: :__git_remotes' \
+ '2:new url:__git_repositories_or_urls' \
+ '3:old url: __git_current_remote_urls ${(k)opt_args[--push]} $line[1]' && ret=0
;;
(show)
_arguments -S \
@@ -6971,19 +6962,19 @@ __git_local_repositories () {
_wanted local-repositories expl 'local repositories' _directories
}
-(( $+functions[__git_repositories_or_url] )) ||
-__git_repositories_or_url () {
+(( $+functions[__git_repositories_or_urls] )) ||
+__git_repositories_or_urls () {
_alternative \
'repositories::__git_repositories' \
- 'url::_urls'
+ 'urls::_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 <new url> <TAB>` is completed
- _wanted remote-urls expl 'current urls' \
- compadd ${(@)*[1,4]} - ${${(0)"$(_call_program remote-urls git remote get-url $5)"}%%$'\n'*}
+(( $+functions[__git_current_remote_urls] )) ||
+__git_current_remote_urls () {
+ local expl
+ _description remote-urls expl 'current url'
+ compadd "$expl[@]" -M 'r:|/=* r:|=*' - ${(f)"$(_call_program remote-urls
+ git remote get-url "$@" --all)"}
}
(( $+functions[__git_any_repositories] )) ||
Messages sorted by:
Reverse Date,
Date,
Thread,
Author