Live data from Hacker News

Zsh Tricks to Blow Your Mind

twilio.com

201–210 of 218 posts

Re: Zsh Tricks to Blow Your Mind

#201
post #182
post #124

Earlier quoted context omitted.

As 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 re…

What's Yuck about using aliases? I use those extensively. Is that a bad practice?

One yuck about aliases, it doesn’t give you autocomplete. See abbr in fish shell for an alternative.

Re: Zsh Tricks to Blow Your Mind

#202
post #12

Earlier quoted context omitted.

Last time I checked it was slower than https://github.com/romkatv/powerlevel10k , because it doesn't decouple the rendering of the prompt from the background processes collecting status information. Ergo no instant prompt. Also, some other cool tricks w.r.t. prompt vs. backscroll. Has that changed?

It seems fast enough but once you enter an actual directory of code where it needs to get the version of node, kotlin, package, etc it slows down noticeably. I've ended up disabling most packages because it is absurd to (I assume) be running node --version every time a prompt is generated. It's a shame they can't do these things asyncronously or cache them.

Caching is a bit dangerous, and most shells don't support asynchronous prompt updates. And cross-shell support seems to be a prime feature. Spending probably a lot of effort just for improving zsh experience might just not have been important enough yet.

Re: Zsh Tricks to Blow Your Mind

#203
post #138

Knew most of those, not much interested in "shell plugins". One thing that many people miss are parameter expansions. Those are in Posix, so pretty much any bare shell should be able to use that, too. So dash/bash/zsh/ksh… echo Hello ${PLANET:-World} to have a default if you're not sure a variable is set. Replace "-" with "=" to actually set it, not just use it for this statement. Or removing suffixes: filename=/tmp/…

echo $filename:r is the shorter, Zsh way to strip a file extension. What am I missing from Ksh93?

Hmm, let me check, I think zsh does have associative arrays and floating point, two features that bash took quite a bit longer to get (and which aren't in the bash in OS X). So at least that's okay.

Compound and active variables are quite convenient in longer scripts. As are namerefs, but I think zsh might have something similar enough.

Re: Zsh Tricks to Blow Your Mind

#204
post #11

A lot of these can be easily done in Bash, too! 1. `mkcdir () { mkdir -- "$1" && cd -- "$1"; }` 2a. `bind '"\e[A":history-search-backward'; bind '"\e[B":history-search-forward'` 2b. Default behavior for Bash. 3. `shopt -s autocd` 4. `mmv`, `perl-rename` 5. `qalc` from libqalculate: https://github.com/Qalculate/libqalculate 8. Default behavior for Bash. 9. Default behavior for Bash.

7. alt-# to comment and accept the current line, alt-1 alt-# to uncomment and execute it

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash....

Re: Zsh Tricks to Blow Your Mind

#205
post #124

Earlier quoted context omitted.

As 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 re…

For your #8 a function might be helpful to remove the $[] characters. $ function c;{echo $[$*]} $ c 1234./56 22.035714285714285 $ a=33;c a / 3 11

If I did that & something for bash that used awk | python to do FP arithmetic I might be able to evolve to a more "portable habit/muscle memory" even if Bash never learns FP arithmetic. Solid suggestion, @tux1968. Thanks. { EDIT: 1 down, a dozen to go! lol :-) and I'll go with a(){..} for a)rithmetic not c since I use that for clear. }

Re: Zsh Tricks to Blow Your Mind

#206

Earlier quoted context omitted.

>Despite remaining in zsh while in a terminal, I still find myself writing only bash scripts when a script it needed. I do this too. I think it's good practice; zsh is amazing as an interactive shell, but bash is everywhere.

Bash is not everywhere, but /bin/sh is..! If portability is important, I'd recommend Bourne shell instead. Sometimes there's a justification for writing shell scripts in bash. E.g. if you only care about Linux forever. Frequently though, a simple script will unexpectedly grow, and start to require non-trivial data structures, etc. If there's no time for a rewrite in a more appropriate language (Python/Ruby/Perl), the…

>if you only care about Linux forever.

You caught me, and you're right: sh (not bash) is the portable option.

Re: Zsh Tricks to Blow Your Mind

#207

None of these blew my mind. If you like terminal productivity I recommend: fzf, Facebook path picker (aka fpp), fd, ripgrep, lf, tig. Some honorable mentions: tokei, hyperfine, lazydocker, ctop, ncspot.

Some other tools I use in case you liked the list above: bat, exa, percol, GNU dialog or zenity, xsv, ministat, gnuplot, tshark, mitmproxy.

Plus any project from sharkdp and burntsushi and any tools recommended by Brendan Gregg.

ht editor is a personal favorite too (press F6 and go to image to get started).

Re: Zsh Tricks to Blow Your Mind

#208
(YMMV for all the below...)

Having done this sort of thing for years, I've come to realize that the biggest barrier to getting more efficient on the command line isn't "sets of features," i.e. the space of the things the shell can do -- it's figuring out how to retrain myself?

A common thing: I see a new (to me) thing like fzf or fd and can immediately conceive of how adding it to my workflow would be phenomenal, but it takes so much more to make it a part of the day. I'm curious if anyone has come up with ways to teach/train themselves better? The best I've come up with so far is to just add something stupid to my .bashrc like

echo "hey, try out that fzf trick"

Re: Zsh Tricks to Blow Your Mind

#209
post #98

Earlier quoted context omitted.

Salty/sweet contrast is the core of Hawaiian pizza appeal, and flavour/texture contrasts are the foundation of some of the most interesting foods, for instance salted caramel, pork and apples, etc.

Pineapple, banana pepper, and jalapeño may be my favorite pizza.

Pineapple, mushroom, artichoke, caper.

Re: Zsh Tricks to Blow Your Mind

#210
post #192
post #10

zsh4humans is the most recent zsh “trick” I’ve discovered. zsh is a bit like emacs when first installed: it can do a lot of things but it’s not nearly as useful without a lot of manual configuration. I’m honestly surprised it doesn’t have more stars on GitHub. https://github.com/romkatv/zsh4humans

Is this similar to Oh My Zsh [1]? I personally have been using Oh My Zsh for years and I've always been a fan of it. I can quickly add themes and plugins and have my shell ready to go how I like it quite quickly on new systems. [1]: https://ohmyz.sh/

zsh4humans is like ohmyzsh but much better IMO because when you first install zsh4humans, it walks you through a setup wizard that walks you through choosing your fonts, prompt style, completion style, etc. and automatically installs the appropriate zsh plugins and things like powerline fonts according to your choices.
Post reply on HN