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 14585 invoked from network); 24 Jun 2020 11:57:20 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 24 Jun 2020 11:57:20 -0000 Received: (qmail 25688 invoked by alias); 24 Jun 2020 11:57:13 -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: 46112 Received: (qmail 163 invoked by uid 1010); 24 Jun 2020 11:57:13 -0000 X-Qmail-Scanner-Diagnostics: from out2-smtp.messagingengine.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(66.111.4.26):SA:0(-2.6/5.0):. Processed in 4.865542 secs); 24 Jun 2020 11:57:13 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudekjedggedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtugfgjggfsehtkedttddtreejnecuhfhrohhmpeffrghn ihgvlhcuufhhrghhrghfuceougdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgvqe enucggtffrrghtthgvrhhnpeduudefleelgeffheevgeevfefghefhuefhheffleejuddu ueehtdffgeeivdfgheenucffohhmrghinhepghhithhhuhgsrdgtohhmnecukfhppeejle drudejiedrfeelrdeileenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Date: Wed, 24 Jun 2020 11:56:30 +0000 From: Daniel Shahaf To: Miroslav =?utf-8?B?S2/FoWvDoXI=?= Cc: zsh-workers@zsh.org Subject: Re: [PATCH] _git: Improve handling of aliases Message-ID: <20200624115630.GA25495@tarpaulin.shahaf.local2> References: <7f7706bd28646cf47d77a0e1b5f89cff40ed9ffe.1592995874.git.mk@mkoskar.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7f7706bd28646cf47d77a0e1b5f89cff40ed9ffe.1592995874.git.mk@mkoskar.com> User-Agent: Mutt/1.10.1 (2018-07-13) A couple of quick comments below. (This is not a full review.) Miroslav Koškár wrote on Wed, Jun 24, 2020 at 13:12:59 +0200: > --- > This handles all of the following aliases: > > # simple > lg = log --format=one --graph --color > > # nested > lga = lg --all > > # nested with preceding git options > push-upstream = -c push.default=upstream pushv > pushv = push -v > > # simple shell > l = !git -P lg -5 > > # shell pipeline (completion of last command) > conf = !git config -l --local | sort *nod* > +++ b/Completion/Unix/Command/_git > @@ -8082,35 +8082,8 @@ __git_color_attributes () { > > # Now, for the main drive... > _git() { > - if (( CURRENT > 2 )); then > - local -a aliases > - local -A git_aliases > - local a k v > - local endopt='!(-)--end-of-options' > - aliases=(${(0)"$(_call_program aliases git config -z --get-regexp '\^alias\.')"}) This (preëxisting) line is wrong. The arguments to _call_program are as to «eval»: 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.) 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. > + local git_alias=git_aliases[\$words[1]] > + if (( ${(P)+git_alias} && !$+commands[git-$words[1]] && !$+functions[_git-$words[1]] )); then > + git_alias=${(P)git_alias} > + local len=$#words > + if [[ $git_alias = \!* ]]; then > + local i > + local -a git_alias_tail > + for i in "${(z)git_alias##\!}"; do > + git_alias_tail+=("$i") > + [[ $i = \| ]] && git_alias_tail=() 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 «sh -c » does, i.e., _cmdstring. That would add support for comments and for a bunch of things other than «|» 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/91d2eeaf23c47341e8dc7ad66dbf85e38c2674de/highlighters/main/main-highlighter.zsh#L391-L416). Adding support for comments specifically could also be done by using the ${(Z)} flag, but I don't know how common that is. If «foo = bar # baz» lines in .gitconfig pass the «#» sign through to sh, then support for comments should probably be added, one way or another. Cheers, Daniel > + done > + words=("$git_alias_tail[@]" "${words[@]:1}") > + else > + words=("${allwords[@]:0:-$#words}" "${(z)git_alias}" "${words[@]:1}") > + fi > + (( CURRENT += $#words - len )) > + _normal -P && ret=0 > + else > + curcontext=${curcontext%:*:*}:git-$words[1]: > + (( $+opt_args[--git-dir] )) && local -x GIT_DIR=${(Q)${~opt_args[--git-dir]}} > + (( $+opt_args[--work-tree] )) && local -x GIT_WORK_TREE=${(Q)${~opt_args[--work-tree]}} > + if ! _call_function ret _git-$words[1]; then > + if zstyle -T :completion:$curcontext: use-fallback; then > + _default && ret=0 > + else > + _message "unknown sub-command: $words[1]" > + fi > + fi > fi > ;; > (configuration) > -- > 2.27.0 > >