I didn't know what it was doing until you asked. I've had it copy/pasted around my dot-files many times. I've just realized now that it does not work on BASH, only on ZSH, sorry :(
EDIT: I mean... I know I always use e to open my editor. What I didn't know was why was I using such a complex alias to do it.
TL;DR:
It uses $VISUAL or $EDITOR and makes sure that it properly handles any extra parameter given to it. So somehting line vim -a -b -c works.
What it does If I'm not mistaken is to alias e to either the value of $VISUAL or $EDITOR. But to only do that it would be enough with:
alias e='${VISUAL:-${EDITOR}}`
There's also this (z) that I just learned on ZSH is an expansion flag. Looking into ZSH manual it says:
z
Split the result of the expansion into words using shell parsing to find
the words, i.e. taking into account any quoting in the value. Comments are
not treated specially but as ordinary strings, similar to interactive
shells with the INTERACTIVE_COMMENTS option unset (however, see the Z flag
below for related options)
Note that this is done very late, even later than the ‘(s)’ flag. So to
access single words in the result use nested expansions as in
‘${${(z)foo}[2]}’. Likewise, to remove the quotes in the resulting words
use ‘${(Q)${(z)foo}}’.
but I still didn't know what it means... so I tried to do:
VISUAL='nvim -v'# This just writes the nvim versionalias e='${VISUAL:-${EDITOR}}'
If I then I've tried
$ e
zsh: command not found: nvim -v
That doesn't happen if I try with (z) flag on the expansion alias e='${(z)VISUAL:-${(z)EDITOR}}'.
I think that my 2 favortites and the 2 I use more are, no doubt:
Wait, what is that first one foist?
I didn't know what it was doing until you asked. I've had it copy/pasted around my dot-files many times. I've just realized now that it does not work on BASH, only on ZSH, sorry :(
EDIT: I mean... I know I always use
e
to open my editor. What I didn't know was why was I using such a complex alias to do it.TL;DR:
It uses
$VISUAL
or$EDITOR
and makes sure that it properly handles any extra parameter given to it. So somehting linevim -a -b -c
works.Detailed explanation
Got it from here github.com/sorin-ionescu/prezto/bl...
What it does If I'm not mistaken is to alias
e
to either the value of$VISUAL
or$EDITOR
. But to only do that it would be enough with:There's also this
(z)
that I just learned on ZSH is an expansion flag. Looking into ZSH manual it says:but I still didn't know what it means... so I tried to do:
If I then I've tried
That doesn't happen if I try with
(z)
flag on the expansionalias e='${(z)VISUAL:-${(z)EDITOR}}'
.PS: Thanks a lot for making me look it up :)
Please write this up into an article or I will, it’s great! And since OS X switched from Bash to zsh I Can actually use it!
Done! dev.to/nflamel/til-how-my-complica...
I'll try to see if I have more things like that around my dot-files to see which ones are worthy of some more articles.