6 ms·
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
by deadbunny 6y ago
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.
- petepete 6y agoI'm happy in zsh or bash but the one thing I love in zsh is that completion options for program arguments. Having a list with a snippet of documentation to tab through is a huge benefit.
- caymanjim 6y agoBash supports completions as well.
- p_l 6y agoIIRC, bash doesn't support extended completion editor features of ZSH, which GP alluded to - like generating a table of options with help strings that can be selected by arrow keys and the like.
- Symbiote 6y agoA (slightly contrived) example: > 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.
- m1keil 6y agodefaults matter.
- meepmorp 6y agoIf the dizzying assortment of shell parameter expansion features (see man zshexpn), isn't enough to convince you, then the cause is lost.
- antonvs 6y agoA "dizzying assortment of features" is not automatically a good thing. 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.
- Symbiote 6y agoI've used Zsh for 15 years or more, and when I started I read the manual. (I realize this is unthinkable nowadays.) 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 https://linux.die.net/man/1/zshexpn
- antonvs 6y agoThere are an endless number of programs I could be using. There are an endless number of programs you could be using. 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 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.
- mhitza 6y agoHonestly you probably can do these with bash as well with some tweaking. But on a daily basis these are most used by me 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.
- cb321 6y agoShort form loops are also great. Someone mentioned short for loops already, but I don't think anyone has mentioned these beauties: repeat 10 echo hi while {sleep 1} echo hi
- wodenokoto 6y agofor 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.
- oblio 6y agoIt's because these posts are late. Do 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.
- cb321 6y agoI agree. I have been using Zsh since about early 1993. I went through a pretty thorough "first I'll convert to tcsh!" then "to Bash!" then "to Zsh!" evaluation back then and Zsh was absolutely the clear winner. 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). [1] https://news.ycombinator.com/item?id=26176897 https://news.ycombinator.com/item?id=26176897
- cb321 6y agoAs many others here have noted, terse syntax for things like `repeat` loops or normal `for`/`while` loops or shell var expansion can all be addictive, but some specific things I miss in Bash that are easy in Zsh are: 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.
- chrisshroba 6y ago> Zsh's extended history format that includes both the time started as well as duration of all my commands. 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 $HISTFILE
- cb321 6y agoNot sure why you are getting all zeros in your duration column. Should be setopt ExtendedHistory (Zsh setopts, like Nim identifiers, are "style insensitive"). From 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.)
- wtetzner 6y ago#7 is one of my favorite zsh features though, even though it doesn't seem like that big of a deal if you haven't used it.