Live data from Hacker News

Zsh Tricks to Blow Your Mind

twilio.com

91–100 of 218 posts

Re: Zsh Tricks to Blow Your Mind

#91
post #24

Earlier quoted context omitted.

Or a simple `=() { bc -l Just a little shortcut but REPLs like Python's take a while to spin up, so it's pretty convenient.

That's a nifty idea! Maybe without lower scale and with the semicolon: = () { bc -l "Stealing" the equals sign for this purpose feels a bit risky, but maybe it isn't.

I'd guess that xorcist added a space at the end of the function name because zsh uses =( to specify one type of process substitution. Without the space or an escape for = zsh will error on alpaca128's definition believing you wanted something else entirely.

To that point zsh has some excellent additions for process substitution beyond bash's <(list), but it also makes for yet more weird incompatibilities for when that matters. I only looked at this to start with because I assumed the space was because =() would have been treated as the full path modifier for a command called (), because it would mean that with any other character including other bracket types. TIL.

Re: Zsh Tricks to Blow Your Mind

#92
post #12
post #7

would like to chime in a faster theme written in rust: https://starship.rs/

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.

Re: Zsh Tricks to Blow Your Mind

#93
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.

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.

    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.

Re: Zsh Tricks to Blow Your Mind

#94
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

I like very much https://github.com/sorin-ionescu/prezto

Re: Zsh Tricks to Blow Your Mind

#95

If you’re on 10.15 (Catalina) there’s no need to install zsh, it is the default shell. If you’ve upgraded and are still using bash, just do ‘chsh -s /bin/zsh’ to set the default to zsh.

What was the reason for them doing this do you know? From my experience with it over the last year, zsh is slightly worse at autocomplete than bash, with no advantages. Is there something I'm missing, like a good default .zshrc?

Completion is one of the biggest reasons people switch to zsh. Did you initialize the completion system in your .zshrc?

https://wiki.archlinux.org/index.php/Zsh#Command_completion

Re: Zsh Tricks to Blow Your Mind

#98
post #78

... Why are all shell snippets in Comic Sans? Is that legal?

I'd also dare to bet the author's favourite pizza is Hawaiian/pineapple

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.

Re: Zsh Tricks to Blow Your Mind

#99
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.

> 5. `qalc` from libqalculate: https://github.com/Qalculate/libqalculate Or, you know, any REPL available.

It isn't shown in TFA, but the zcalc keymap is bindable in the line editor so not only can you use it like qalc/irb/luap/whatever you can also take advantage of any other functionality of zsh within it. Admittedly, you could do some of that with some magic $if/$endif guards in your ~/.inputrc if your REPL uses readline, but the integration is nice functionality if you're a heavy zsh user. I think of it more like the expression register in vim or eval-print-expression in emacs.

Re: Zsh Tricks to Blow Your Mind

#100

The #2 behavior (up-down arrow cycles through usages of command) doesn't work OOTB on macOS's zsh. Is it a new-ish feature or a plugin that I don't have?

'bindkey "${key[Up]}" up-line-or-search' is probably the incantation you're looking for if you don't want to use oh-my-zsh or whatever. The $key hashmap is generated by zsh's zkbd so that your config can be terminal independent, but you can insert the actual key if you prefer not to use zkbd or only use one terminal type.

There are a bunch of other search types available, zshzle(1) has all the gory details.

Post reply on HN