Live data from Hacker News

Zsh Tricks to Blow Your Mind

twilio.com

121–130 of 218 posts

Re: Zsh Tricks to Blow Your Mind

#121
post #51

I've been using Fish instead and it's much much simpler than configuring ZSH to my liking. It's already good out of the box, without having to carry around any kind of configuration. The only stuff I usually do is to setup `powerline-go` as prompt, and voilà, that's pretty much it.

The main drawback for fish is that is not compatible with bash scripting. If you need help with something specific, you can throw out almost all help available online.

I can never understand this complaint. I'm frequently on Windows and use Cygwin.

Do you know what I do?

I use zsh. Let's say I need bash. "bash". I'm in bash :-) I need cmd (yup, that can happen). "cmd".

I need to run just one command with bash: "bash command".

I need to run just one command with cmd: "cmd /c command".

These problems are trivially solvable :-)

Re: Zsh Tricks to Blow Your Mind

#122
post #32

Do people... actually use this font in their terminal? I would go absolutely nuts looking at the spacing and color scheme.

> Do people... actually use this font in their terminal?

seems so. recently discussed: https://news.ycombinator.com/item?id=25520510 https://dtinth.github.io/comic-mono-font/

http://www.comicneue.com/

Re: Zsh Tricks to Blow Your Mind

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

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

    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]

    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.

Re: Zsh Tricks to Blow Your Mind

#125

My company is fond of putting source code under very deep directory structures, so I quite like Z: https://github.com/agkozak/zsh-z Not ZSH specific, but it's also handy to load project-specific environment variables automatically on entering directories: https://direnv.net/ .

I very much agree on z. Also fzf [0]. It is super fast and makes a huge difference when working in code bases with code 12 levels deep. [0] https://github.com/junegunn/fzf

Also recommend the fzf vim extension. I use it to navigate my Vimwiki Zettelkasten.

Re: Zsh Tricks to Blow Your Mind

#126
post #119

Earlier quoted context omitted.

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.

It'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 binutil…

I 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

Re: Zsh Tricks to Blow Your Mind

#128
post #66

I'm more amazed how that page is unreadable, starting from typography up to color scheme.

I personally don't think the typography in the page itself is bad, it's the screenshots (and indeed their color schemes and types) and the lack of vertical rhythm of the whole thing that pose the biggest problems.

Re: Zsh Tricks to Blow Your Mind

#129
Been using zsh for years and many of these were new to me. I love #3 and use it daily. I find it most helpful to use this trick to type ".." or "..." and quickly navigate back a dir or two. Of course you can do this in bash (and other shells) with aliases, it does not come out of the box like so many niceties in zsh.

Re: Zsh Tricks to Blow Your Mind

#130

My company is fond of putting source code under very deep directory structures, so I quite like Z: https://github.com/agkozak/zsh-z Not ZSH specific, but it's also handy to load project-specific environment variables automatically on entering directories: https://direnv.net/ .

I very much agree on z. Also fzf [0]. It is super fast and makes a huge difference when working in code bases with code 12 levels deep. [0] https://github.com/junegunn/fzf

Using fzf and ctrl+r for fuzzy finding commands is a godsend.

Basically all snippets of code that I ever run are straight from this.

Forget how to exactly reset a committed local file that you want to place into another commit? Not something I do everyday, so may require some Googling if I can't remember exactly.

What I do know, is that I use something with `git reset`.

I ctrl+r and type `git reset` and here is what comes up:

> 9488 git reset HEAD^

> 10535* git reset --hard

> 10555* git reset HEAD file

> 10999* git reset --soft HEAD

Oh right, I need to reset the commits and then remove that file from the commit and I can recommit.

It is a complete gamechanger.

Post reply on HN