Live data from Hacker News

My favourite Zsh features

code.joejag.com

31–40 of 44 posts

Re: My favourite Zsh features

#31
Clever history doesn't really work for me when I use `sudo`

say I type

    $ sudo pacman -Syu 
    $ sudo chown blah blah
    $ sudo pa 
I just get `sudo chown blah blah` instead of `sudo pacman -Syu`

Does anybody know how to fix this? :)

Re: My favourite Zsh features

#34
post #11

Something I've noticed is that osx users believe bash to be less capable than it is because of the poor out of the box configuration of bash on that platform (in addition to the ancient version installed). Particularly the tab completion stuff. It doesn't pop up menus and all that, but the ubuntu install of bash has a ton of context-sensitive tab completion stuff in it, and the git package properly installs __git_ps1…

I guess "bad PR" like this is actually one downside for projects switching to GPL3.

Well, bad PR from Apple. But you don't get much good PR from Apple with GPLv2 either, which they're slowly purging from their OS as well.

Re: My favourite Zsh features

#35

Clever history doesn't really work for me when I use `sudo` say I type $ sudo pacman -Syu $ sudo chown blah blah $ sudo pa I just get `sudo chown blah blah` instead of `sudo pacman -Syu` Does anybody know how to fix this? :)

I don't see that behavior for me.

    $ sudo foo
    $ sudo bar
    $ sudo fo
gives me `sudo foo`.

I'm using zsh 5.0.7 (x86_64-apple-darwin14.0.0) on OS X 10.10 (with prezto[1]).

[1]: https://github.com/sorin-ionescu/prezto

Re: My favourite Zsh features

#36
post #26

Earlier quoted context omitted.

So what do you do when you want to ls a file called "L"?

I put L in 'single quotes' or I \escape it touch 'L' ls 'L' ls \L

Do not use global aliases. They are dangerous. It's too easy to accidentally use them without realizing it, with unpredictable consequences.

Much better is to use abbreviations which expand to the full command they abbreviate after you hit the space bar.[1]

This way you can see exactly what's going to be done before you hit ENTER. It does cost one extra keystroke, but the safety is worth it.

[1] - http://zshwiki.org/home/examples/zleiab

Re: My favourite Zsh features

#37
post #6

One of my favorites instead of aliasing ".."'s is this function: rationalise-dot() { if [[ $LBUFFER = *.. ]]; then LBUFFER+=/.. else LBUFFER+=. fi } zle -N rationalise-dot bindkey . rationalise-dot When you hit ... it will produce a slash and a ../ for each . you type after that.

Nice. But all you really need are:

  alias ..="cd .."
  alias ...="cd ../.."
After that, the more dots you type, the more error-prone it is, as you start to have to carefully count exactly how many directories you have to go up to get to where you want.

A better alternative is a script that shows a list of parent directories and lets you select them by typing the number or letter associated with them.

For example, if your current directory is "/a/b/c/d/e/f/g/h", then the script would display something like:

  List of parent directories:
  1 - a
  2 - b
  3 - c
  4 - d
  5 - e
  6 - f
  7 - g
  Please choose a directory: _
and you could type "3" to get to directory "c". That would be equivalent to typing "......", but much less error-prone and it'll save you the tedium of counting dots too.

Re: My favourite Zsh features

#38
post #4

The tab completion isn't limited to the beginning of file names either. Useful when many of your file names start with the same pattern but then diverge. ls something will complete to ls prefixSomething.sh if it's unique enough. This is probably my single favorite zsh feature.

Having gotten used to ido in emacs, I must say that I am now disappointed in most all autocompletes. Shame it doesn't work in the shell. (Quick, someone prove me wrong! Please! :) )

For emacs M-x completion, I prefer smex.[1][2]

It's like ido, but reorders the commands it presents to you in most-frequently-used order, which can be a real time-saver.

[1] - http://www.emacswiki.org/emacs/Smex

[2] - https://github.com/nonsequitur/smex/

Re: My favourite Zsh features

#39
post #6

One of my favorites instead of aliasing ".."'s is this function: rationalise-dot() { if [[ $LBUFFER = *.. ]]; then LBUFFER+=/.. else LBUFFER+=. fi } zle -N rationalise-dot bindkey . rationalise-dot When you hit ... it will produce a slash and a ../ for each . you type after that.

Nice. But all you really need are: alias ..="cd .." alias ...="cd ../.." After that, the more dots you type, the more error-prone it is, as you start to have to carefully count exactly how many directories you have to go up to get to where you want. A better alternative is a script that shows a list of parent directories and lets you select them by typing the number or letter associated with them. For example, if you…

Error prone isn't really that important in a shell when we're just talking about moving around. You type a bunch of dots which puts you in the region more or less -- plus I never really go from 8 directories deep to 2, (I doubt I even have an 8 directory deep section of my file tree) -- if I did I'd start from /, so it's more about 4 or 5 or so, in which case it's easy enough not to count but to know based on context. To each his own though.
Post reply on HN