Live data from Hacker News

Zsh Tricks to Blow Your Mind

twilio.com

51–60 of 218 posts

Re: Zsh Tricks to Blow Your Mind

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

Re: Zsh Tricks to Blow Your Mind

#52

My favorite alias, which is not really a zsh exclusive thing, is combining cd && ls : cl() { cd "$@" && ls; } It's wonderfully simple and saves me so much time by giving me an instant refresher of what's in the directory I just changed to.

Run mc, navigate to dir, press ^O to switch back to shell.

Re: Zsh Tricks to Blow Your Mind

#53

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.

If the dizzying assortment of shell parameter expansion features (see man zshexpn), isn't enough to convince you, then the cause is lost.

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

Re: Zsh Tricks to Blow Your Mind

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

[deleted]

Re: Zsh Tricks to Blow Your Mind

#56
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. in bash, I use the: [Esc], [#] combo, equivalent to: [Alt]-[Shift]-[3] (a.k.a.: "M-#" in the official docs).

This is a shortcut which basically prefixes the current line with '#' comment character and then simulates hitting Enter (pushing the commented-out line into history buffer).

Re: Zsh Tricks to Blow Your Mind

#57

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.

I am a happy Fish user, too. The first downside that comes to my head is that if you want to share a script you wrote that you have to translate it to bash first. Much less of an issue if you're using zsh.

Re: Zsh Tricks to Blow Your Mind

#58

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

Re: Zsh Tricks to Blow Your Mind

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

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

Re: Zsh Tricks to Blow Your Mind

#60
post #26
post #16

Earlier quoted context omitted.

Wow jog is tiny: grep -a "${PWD} " ~/.zsh_history_ext | cat | cut -f1 -d"|" | tail

Why does it pipe to cat?

Maybe instead of `grep --color=never`? (i.e. to force non-terminal behaviour)

Then again, cut would do the same thing anyway.

Post reply on HN