1) auto cd to any evar just from its name
e.g. lb=/usr/local/bin; lb
($lb works in bash, but I always forget
the $. I know I could do aliases...Yuck.)
2) auto cd does not seem to use $CDPATH
this is a real pain since I am used to
never typing "cd ".
3) **c instead of **/*c for a recursive glob
At 2 vs. 4 chars (or 3 vs. 6 keydowns) it
may not *look* much briefer, but it feels
much easier to type once you're used to it.
4) On the fly command line colorization along
the lines of zsh-syntax-highlighting.
Spot syntax errors/missing cmds *before*
you hit <ENTER>.
5) vared MyVar
Use the ZLE to easily modify any evar.
6) Zsh's REPORTTIME
*automatically* report time/memory of only
"expensive" programs/pipelines.
7) Zsh's extended history format that includes
both the time started as well as *duration*
of all my commands.
8) Floating point arithmetic and $[]
forget all this calculator jazz. I just
do `alias ec=echo` and go `ec $[1234./56]`
or even just : $[1234./56]<TAB>
9) glob qualifiers (forget `find` or `fd`)
My main use cases are *(.) *(@) & *(/),
sometimes with a ^ for "not" in there,
e.g. *(^/). The codes are mostly the
old ls -F codes to be easy to recall.
If anyone knows how to make Bash do any of those, I would appreciate the tip. Otherwise, maybe they count as "killer" features to someone.Also, I tend to use a global alias "/n" for "/dev/null". I know I could just use $n with n=/dev/null, but I enjoy having it look like a path in / that never actually exists.
Woah, how do I enable this? From what I can tell this information is not being stored in $HISTFILE:
...
: 1613659860:0;sleep 1
: 1613659863:0;sleep 3
: 1613659871:0;exec zsh
: 1613659880:0;vim $HISTFILEFrom the Zsh man page:
EXTENDED_HISTORY <C> Save each command's beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. The format of this prefixed data is: `: <beginning time>:<elapsed seconds>;<command>'.
(EDIT: My best guess explanation is some competing/conflicting setopt, but the Zsh mailing list could almost surely help you. Also, `history -fD` may show the correct answer even if the saved file has all 0s.)
[1] https://unix.stackexchange.com/questions/396809/zsh-share-hi...
It makes sense. It's preferring to add to history immediately so that it's available to other shells without having to wait for the command to finish.
From the manpage:
> INC_APPEND_HISTORY_TIME This option is a variant of INC_APPEND_HISTORY in which, where possible, the history entry is written out to the file after the command is finished, so that the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY for‐ mat. This means that the history entry will not be available immediately from other instances of the shell that are using the same history file. This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive.
It looks like either share_history or inc_append_history break recording duration in a fundamental way. The TL;DR is that the history line is written out before the command in question completes. I guess the thinking is that inc/shared history with some very long running command is not as useful if you wait until it ends and you have elapsed time data to append that line. I feel like that might be a personal issue - like if you almost only ever run commands 1-90 seconds then you are fine with the delay.
Anyway, this also explains why it is available from the `history -fD` command but not in the file.
TL;DR - Yuck = namespace squishing in this application only, but then again one man's "collapse of namespaces being yucky" is another's "yay, I do not have to remember 3..4 namespaces!".
EDIT: for what it's worth, I never intended my 9..11 items to be "in order of importance or persuasiveness". Mostly in order of personally driving me batty when I use Bash and just meant to actually be things Zsh could do that (present)Bash could not, to my knowledge due to @deadbunny's complaint. I do try to keep a side Bash config that is as close as possible to my Zsh config, because it's not always worth my time to compile/install Zsh on a system. But when I do that and start using Bash, I notice all these missing things. { That's why I would genuinely appreciate anyone who knows how to replicate them in Bash saying how. I'm not just "daring the Bash apologists to a challenge" or whatever. :-) }
10) =() expansion. It's like <() which both bash and zsh have, but instead of substituting with the path to a pipe, it substitutes with the path to a temporary regular file. Sometimes pipes don't suffice. For example, I can do `viewnior =(maim -s)` to select a region of the screen and see it in an image viewer immediately. `viewnior <(maim -s)` fails because viewnior can't display an image from a pipe.
11) short syntax for control structures. For example, you can do `for x in $(xs); foo $x` without bothering with `do` and `done`.
12) variable expansion in brace expansion. In bash, `x=5; echo {3..$x}` outputs `{3..5}`. zsh outputs `3 4 5`.
13) Command can be just redirection without any executable. `<<< foo` is equivalent to `cat <<< foo`, `> foo.txt` is equivalent to `cat > foo.txt`.
14) Able to convert numbers between any bases. To convert base-5 10 to base-4: `<<< $(( [#4] 5#10 ))` outputs `4#11` which means 11 in base-4.
15) Named directories. I have my project files organized under deep directories like ~/work-for/.../.../.../foo/, and have configured all those as named directories to be able to access them as `~foo`, for instance. Different from using simple variables for this, named directories are compacted when presented by the shell. So in my prompt, I see my current directory is e.g. `~foo/bar` instead of the whole thing from the home dir. Named directories come in 2 forms, static and dynamic. Static named dirs are when you set them up in a hash of name => directory. Dynamic named dirs are when you define a function that expands arbitrary names to paths and compacts arbitrary paths to names.
16) `=foo` expands to the full path of executable foo. So you can, e.g. see the source of `pass` with `less =pass`.
17) Variable expansion syntax, glob qualifiers, and history modifiers can be combined/nested quite nicely. For example, this outputs all the commands available from $PATH: `echo ${~${path/%/\/*(*N:t)}}`. `${~foo}` is to enable glob expansion on the result of foo. `${foo/%/bar}` substitutes the end of the result of foo to "bar" (i.e. it appends it); when foo is an array, it does it for each element. In `/*(*N:t)`, we're adding the slash and star to the paths from `$path`, then the parentheses are glob qualifiers. `*` inside means only match the executables, `N` is to activate NULL_GLOB for the match so that we don't get errors for globs that didn't match anything, `:t` is a history mod used for globs that returns just the "tail" of the result, i.e. the basename. IIRC, bash can't even nest multiple parameter expansions; you need to save each step separately.
18) Suffix aliases can be used to define how to open arbitrary files. `./foo.mp4` opens it up in with `mpv`, because I have `alias -s mp4=mpv`.
19) Global aliases are useful for expanding stuff anywhere. For example, I have `alias -g %LD='~/downloads/*(oc[1])'` so that `%LD` expands to the latest download as part of any argument to a command.
20) Globbing flags. There are various flags for globbing, that enable e.g. backreferences in globs, allow n-number of errors while matching (approximate matching), etc. The only one I've really used though is `i` which enables a glob to be case-insensitive. So `(#i)*.pdf` matches `foo.pdf` as well as `bar.PDF`.
21) Multios. You can use multiple files in individual redirections. For example, `foo > bar | baz` is equivalent to `foo | tee bar | baz`. That accepts globbing and brace expansion too: `foo > *.{c,h}` is the same as `foo | tee *.{c,h}`. Also works for reading: `foo < *.txt` is practically the same as `cat *.txt | foo`. I must admit that I haven't really used this, though.
$ function c;{echo $[$*]}
$ c 1234./56
22.035714285714285
$ a=33;c a / 3
11Do you know why "bash does [these things] natively"? Because zsh had them 20 years ago when bash was barebones and people were envious and over time bash started copying these features over. Sometimes poorly.
And for the "one line alias", in a bunch of cases it's with additional commands, which are not always available, the most famous example being rename.
Which rename? The binutils one (I think) or the Perl one (which has more features)?
Does your distro even package both?
Things can be a lot more complex than they seem.
While Bash has "caught up" some in the ensuing decades by copying features (some poorly as you note), I think it still misses quite a few nice "usability" features. I've listed some here [1] from memory, but I am probably forgetting other pretty nice ones. Like maybe ${(f)"$(mycmd)"} to split the output of `mycmd` strictly by newlines. (or ps:\0: for even stricter splitting).
auto_pushd
Replaces internally cd with pushd (plus a few more: to ignore dups, be silent about it).Global aliases (interpolated anywhere in the commandline)
alias -g G='| grep -i'
cat file G something
Replace on the fly long directory names with short paths /some/long/path $ export X=`pwd`
~X $
All the tweaks to ignore dups in the history, when saving/searching. repeat 10 echo hi
while {sleep 1} echo hi > rsync --e«TAB»
Completing file
some-file-with-extra-hyphens
Completing host
a-n-example.local
Completing option
--cvs-exclude -- auto-ignore files the same way CVS does
--delete-excluded -- also delete excluded files on the receiving side
--exclude -- exclude files matching pattern
--exclude-from -- read exclude patterns from specified file
--executability -- preserve executability
--ignore-existing -- ignore files that already exist on receiving side
--ignore-non-existing --existing -- ignore files that do not exist on receiving side
There are various ways to present the completion; I have the simple "keep typing letters" way, but Zsh can also present a table with an entry to highlight.The features need to be able to do useful things better somehow, and that's where articles demoing such applications come in.
"Better" also doesn't necessarily mean "more concise," otherwise APL would be one of the best programming languages. A language with a smaller number of accessible, comprehensible, memorable features can prove more useful in practice than one with a "dizzying assortment" that's hard to remember, difficult to read, etc.
I noted down the things I thought would be useful day-to-day, and started using them. A few months later, I skimmed through the manual again. I still do so, every year or two. My work gradually changes, and I find Zsh has features that are now useful to me.
This is the suggested manpage: https://linux.die.net/man/1/zshexpn
The issue is how to decide whether something is worth looking at.
An article which gives examples that can easily be achieved by some more mainstream system is unconvincing. That's what was being discussed here:
> This is always my complaint about posts like this. I read them looking for the killer feature to make me consider switching from bash and it's always stuff bash does natively or with a one line alias.
> This is the suggested manpage: https://linux.die.net/man/1/zshexpn
Yes, the comment I replied to already suggested that. You're not doing much to convince me that your judgment is worth respecting.
for el in `mycommand`; myothercmd $el
That's my killer feature at least. I usually write my scripts in bash, but for one liners in interactive mode, the simplified syntax is a god send.