Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

zsh had me when I realized that

1) it's a drop in replacement for bash. All those scripts you have around have #!/bin/bash at the top, they will still work exactly as they always have.

2) You can selectively go back through your command history. You can arrow-up to go to previous commands just like in bash. But if you start a command (say, ssh) and then arrow-up you will then be cycling back through the last ways you entered that command. Super convenient.



> You can arrow-up to go to previous commands just like in bash. But if you start a command (say, ssh) and then arrow-up you will then be cycling back through the last ways you entered that command.

Or, if you'd like to do this in Bash, and any program that uses readline: In ~/.inputrc

    # Bind the up arrow to history search, instead of history step
    "\e[A": history-search-backward
    # And the reverse (down)
    "\e[B": history-search-forward


I find it easier to just hit ^R when I want to search my history. And since that's a default keybinding, it works on any machine I touch.


I recently moved from tcsh to zsh, and this is one thing that seems to be a bit weird in zsh. For example, given

    git clone
    git rebase master
    git log
in my history, if I typed

    git r<UP>
I get 'git log', not 'git rebase master' as I'd expect.


Try:

  bindkey "^[[A" history-beginning-search-backward


And that's why no one wants to bother switching.


Actually, that's exactly why I switched. (more precisely, this could be said why: http://www.cs.elte.hu/zsh-manual/zsh_14.html)

If you don't want to use it, I don't see how that is any of my business. I was just trying to help out somebody who does, so there's hardly any reason to be an ass.


To be honest, I tried it years back and liked it, but forgot about it and didn't miss it. I may try it again sometime.

All I'm saying is that most people won't like something that offers no immediate major benefit and has annoying defaults that they have to find an obscure setting to fix. This is probably why so few use emacs, even though it is awesome :)


Everything has annoying defaults until you either change them or get used to them.


Excuse the nitpick, but what you meant to say is "All those scripts having #!/bin/bash at the top, they will still work exactly as they always have if you change the line to read #!/bin/zsh"... and it's not quite clear why you would want to do that if the script is already working as intended, hence this clarification.

Of course, a script that has #!/bin/bash at the top will keep working regardless of which shell you execute it on anyway, even a shell with a completely different syntax such as tcsh, because that shebang line will tell the OS to always use bash to execute the script--no matter what shell you're using to invoke the script.

It's different when you source a script (usually done using the eponymous shell built-in) since then the shebang line will be treated as a comment and ignored, and all other lines in the script will be executed in the context of the current shell.


For number 2, this has been the default for tcsh for years now...


Me too; I actually use up arrow for history-search-backward and also bindkey -v, so ESC-k gives me a non-search history (like the default up arrow behaviour).


But if you start a command (say, ssh) and then arrow-up you will then be cycling back through the last ways you entered that command.

Like Ctrl+R?


Not exactly, but similar. If you want to see a demo, Ryan Bates highlights this feature (among others) with his ZSH screencast: http://railscasts.com/episodes/308-oh-my-zsh




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: