From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 2908 invoked from network); 26 Jun 2020 10:18:13 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 26 Jun 2020 10:18:13 -0000 Received: (qmail 1377 invoked by alias); 26 Jun 2020 10:17:59 -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: Sender: zsh-workers@zsh.org X-Seq: 46117 Received: (qmail 1617 invoked by uid 1010); 26 Jun 2020 10:17:59 -0000 X-Qmail-Scanner-Diagnostics: from sender4-of-o56.zoho.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25850. spamassassin: 3.4.4. Clear:RC:0(136.143.188.56):SA:0(-2.0/5.0):. Processed in 1.419525 secs); 26 Jun 2020 10:17:59 -0000 X-Envelope-From: mk@mkoskar.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spf.zoho.com designates 136.143.188.56 as permitted sender) ARC-Seal: i=1; a=rsa-sha256; t=1593166635; cv=none; d=zohomail.com; s=zohoarc; b=HSy4XHZfhOMKchcIaFp1f6xEs23FSbCxys6VLA63vCBQH7b+qxs20Z6CDmAPDJfvhFeHCT9t/OPEuHPdta+OIioVqa9kaSbPpGDv36yNASm3fioCQzXnOCBT60g7cNZF0VmkR4eoX4XiVucj6wANXeS1z8kuXjRPgpeoVztbc6c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593166635; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=EAzuuG9aDlpEJN6ySSZZi6K4OQV+EhvWNlSILwlytNU=; b=ibpBWtWrZ5bT8MqDt6zrLkp/gH1szRy8bos94kIDKbiJ1+R8DtMJRXT5ytSKCBJc4XxYVbjbjl88T/+lzHbUdDrkSySFRZUqkAmvSVEGrMkukVA07mD/ex232EJ7c57+Na1gnXQLX3s3oxo6rzcG0lYWzo1Qodh2q+AzJzlISiY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=mkoskar.com; spf=pass smtp.mailfrom=mk@mkoskar.com; dmarc=pass header.from= header.from= Date: Fri, 26 Jun 2020 12:17:04 +0200 From: Miroslav =?utf-8?B?S2/FoWvDoXI=?= To: Daniel Shahaf Cc: zsh-workers@zsh.org Message-ID: <20200626101704.lhzsaqrdov5rhbr7@mkoskar.com> Subject: Re: _git: Improve handling of aliases References: <7f7706bd28646cf47d77a0e1b5f89cff40ed9ffe.1592995874.git.mk@mkoskar.com> <20200624115630.GA25495@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20200624115630.GA25495@tarpaulin.shahaf.local2> X-ZohoMailClient: External Hi Daniel, thanks for your feedback! > > - local -a aliases > > - local -A git_aliases > > - local a k v > > - local endopt=3D'!(-)--end-of-options' > > - aliases=3D(${(0)"$(_call_program aliases git config -z --get-regex= p '\^alias\.')"}) >=20 > This (pre=EBxisting) line is wrong. The arguments to _call_program are a= s > to =ABeval=BB: joined with spaces and then one layer of quoting removed. > That means the backslash that protects the dot doesn't make it through > to git. (If that weren't so, the backslash before the caret would have > caused the regexp to never match.) True. Noted. > You moved the surrounding block code further down the function > unchanged. I'd recommend to split the patch into two parts: one that > just moves the code without changing it, and one that adds new > functionality. That'll make it much easier to review. Hmm, ok how about this: 1) fixing up for nested aliases and preceding options 2) basic parsing of shell aliases for completing of last simple command (this would be the "new functionality" bit then) For 1) I'm thinking about this: a) keep it as is more/less (fixing the small _call_program issue above)= : ... local -A git_aliases local a for a in ${(0)"$(_call_program aliases git config -z --get-regexp \= ^alias\\.)"}; do git_aliases[${${a/$'\n'*}/alias.}]=3D${a#*$'\n'} done local git_alias=3Dgit_aliases[\$words[1]] if (( ${(P)+git_alias} && !$+commands[git-$words[1]] && !$+function= s[_git-$words[1]] )); then git_alias=3D${(P)git_alias} ... * I've got rid of "aliases", "k" and "v" to shorten it a bit b) much shorter and IMO cleaner: ... local git_alias if git_alias=3D${"$(git config -z --get alias.$words[1] 2>/dev/null= )"/$'\0'*} \ && (( !$+commands[git-$words[1]] && !$+functions[_git-$words[1]] = )); then ... * basically the difference is that we don't ask for all aliases but only for the one we're interested in * it loses configurability of _call_program, which IMO is rather pointless anyway > > + local git_alias=3Dgit_aliases[\$words[1]] > > + if (( ${(P)+git_alias} && !$+commands[git-$words[1]] && !$+fun= ctions[_git-$words[1]] )); then > > + git_alias=3D${(P)git_alias} > > + local len=3D$#words > > + if [[ $git_alias =3D \!* ]]; then > > + local i > > + local -a git_alias_tail > > + for i in "${(z)git_alias##\!}"; do > > + git_alias_tail+=3D("$i") > > + [[ $i =3D \| ]] && git_alias_tail=3D() >=20 > Would it be possible to add support to everything that could be used > there, in addition to pipes? I think you just need to call whatever =ABs= h > -c =BB does, i.e., _cmdstring. That would add support for comments > and for a bunch of things other than =AB|=BB that can be followed by the > start of a simple command (for example, the tokens and reserved words > in https://github.com/zsh-users/zsh-syntax-highlighting/blob/91d2eeaf23c4= 7341e8dc7ad66dbf85e38c2674de/highlighters/main/main-highlighter.zsh#L391-L4= 16). >=20 > Adding support for comments specifically could also be done by using > the ${(Z)} flag, but I don't know how common that is. If =ABfoo =3D bar = # baz=BB > lines in .gitconfig pass the =AB#=BB sign through to sh, then support for > comments should probably be added, one way or another. I agree, I've hastily put only split on '|' there. I've looked into _cmdstring and I don't believe this will be of any help here as it's completing single command argument only. It seems to me most sane here is to complete using _normal on last simple command contained in that alias. So something like this should work fine: local i local -a git_alias_tail for i in "${(z)git_alias##\!}"; do git_alias_tail+=3D("$i") case $i in ';' | $'\n' | '||' | '&&' | '|' | '|&' | '&' | '&!' | '&|'= ) git_alias_tail=3D() ;; esac done words=3D("$git_alias_tail[@]" "${words[@]:1}") Let me know what you think and I'll re-roll the patch/es. Regards, Miro