-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
$_ (dollar underscore) is the last parameter from the previous line. I often (with autocd on) enter "$_" directly after a command to jump into the destination directory. However it's always highlighted red. Apologies if this is covered by another issue, I went through a number but couldn't find anything directly related. Thanks.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
danielshahaf commentedon Jun 24, 2019
Are literal directory names highlighted in green at command position when AUTO_CD is set? AFAICS they aren't [can't test this myself right now], so you're essentially asking for AUTO_CD support to be added. (Once literal directory names are handled, simple parameter expansions will DTRT too.)
Would you be interested in contributing this feature?
danielshahaf commentedon Jun 24, 2019
By the way,
M-.
(Alt+.) is equivalent and has fewer keystrokes.mxmilkiib commentedon Jun 24, 2019
Whoops, AUTO_CD paths are made purple (on my system) not green.
I'm afraid I don't have the understanding, time or energy to implement this.
Alt-. doesn't work for me, I guess either conflict with another zsh script or bad key binds. Thank you for the tip though.
phy1729 commentedon Jun 24, 2019
It's a bit more complicated than just supporting AUTO_CD. Currently
_
is not recognized as a parameter namezsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
Line 393 in d766243
_
properly. We'd need to save the value of_
and then special case the expansion code because_
will have changed many times over once we've gotten to herezsh-syntax-highlighting/highlighters/main/main-highlighter.zsh
Line 607 in d766243
danielshahaf commentedon Jun 25, 2019
That pattern would match
$_
's name, but if we areableunable to compute the correct expansion, we might have another use-case for the envisionedindeterminate
style — not just for$_
but for any[[ ${(t)foo} == *special* ]]
parameter at command position, unless whitelisted as an exception?danielshahaf commentedon Jun 25, 2019
See #617 for
indeterminate
(although that term isn't used there).danielshahaf commentedon Jun 25, 2019
My reading is two separate issues:
phy1729 commentedon Jun 25, 2019
Indeed it does match
$_
oops. I agree in general special parameters should use aindererminate
style; however, I think$_
is useful enough to special case. There may be a cleaner way, but worst case we could save${${(z)BUFFER}[-1]}
onzle-line-finish
.danielshahaf commentedon Jun 25, 2019
phy1729 commentedon Jun 25, 2019
Nothing. However, highlighting on the modified line would already be incorrect for those users (and we do document that we should be sourced last).
danielshahaf commentedon Jun 26, 2019
Fair enough. Re 'cleaner way', I thought we could have zle expose the REPL-level value of
$_
through a new preset variable (akin to BUFFER, WIDGET, &c). WDYT?danielshahaf commentedon Jan 16, 2020
For the record, AUTO_CD support is in #669 (PR for 0.8.0) and parameters in command position are #674 (has WIP PR). Support for
$_
specifically would require further work, as discussed in this issue.3 remaining items