Hacker News new | past | comments | ask | show | jobs | submit login
Zsh: The last shell you will ever need (friedcpu.wordpress.com)
113 points by r11t on Dec 12, 2009 | hide | past | favorite | 41 comments



TFA mentions shared history across sessions as a ZSH feature, but it is available in bash as well. For those who're staying with bash, stick this in your .bashrc:

  shopt -s histappend
  export PROMPT_COMMAND='history -a'
The histappend option appends to history instead of overwriting. PROMPT_COMMAND is run before bash displays a prompt -- this will save each command right after you issue it, instead of when you exit the session.

Now that your history is about to get a lot larger, you'd probably want to override the defaults for HISTSIZE and HISTFILESIZE.

Somewhat OT, but since I mentioned PROMPT_COMMAND: One very useful piece of info to have in your prompt is the exit status of your last command. You can do that with

  export PROMPT_COMMAND='ERRVAL=$?; history -a'
Then just include ${ERRVAL} in your PS1.


I believe that this will cause your history ordering to go a bit wonky. Hitting up to get the last item will almost always get the command you last typed into the current window (as it should be, imo), but if you hit enter a few times after you run a given command it will be something else (sucked in from the surroundings I guess)

Every so often this really bites me, but the usefulness far outstrips the quirks.


Considering the number of shells I have open, that would be very weird. A coherent "local" history is very useful not just for the up key but also for referring to history items by number (like "!123").

My solution for my laptop has helped me on countless occasions. I've been doing this for about three years.

1. Compile bash with the syslogger patch. Each command will generate one line with timestamp, username, terminal PID, and command.

2. Configure syslog to pipe all bash commands to a special file.

3. Run a cronjob every night that takes all the bash commands from the day and saves them off to a day specific file.

4. Need to find that command you ran 6 months ago to get package XYZ to work in way ABC? Use "grep -R" to find every single invocation you ever made to that program. If you actually needs a particular shell's local history, pipe grep through a grep for the PID (I find I almost never need that).

I work with so many different technologies for such brief times that this is just absolutely invaluable. It also helps you narrow down dates of events sometimes.

For installation, use google etc. but here: http://blog.rootshell.be/2009/02/28/bash-history-to-syslog/

Gentoo users can reinstall with the 'bashlogger' USE flag.


i think it would be supercool if the history function actually stored only the different commands that are being executed, rather than a timestamped version of the command...


Not sure about this in the context of that histappend stuff, but bash can do that normally: use HISTIGNORE and "&". Here is my HISTIGNORE:

  export HISTIGNORE="&:ls:ls -la"
That will ignore duplicates, "ls", and "ls -la"

That's for local shell history, I also record every command to a file based archive (see my other comment in this thread: http://news.ycombinator.com/item?id=992772 ).


I can see how a programmable shell was the best thing since sliced bread in the era before ubiquitous Perl, Ruby, etc, but I find myself using the shell for only three things. To set up common environment variables, to script one-liners that are too simple to bother with a more powerful language, and to start programs. (Additionally, the OS tends to use "sh" where it wants to guarantee code will run without dependencies outside /bin. But I don't write that myself.)

Honestly I'd like to see a shell with less programming features, not more. It should be hella tuned for command line usability, but I don't give a damn if it has a while loop.


Can you use your existing bash configuration files with zsh? It looks like zsh isn't picking up my .profile file on my OS X box, or that it doesn't care about what it found there.

The bigger question is, what is the switching cost?


Here is a zshrc with almost zero switching cost - especially with the esc-backspace behavior for path deletes, setenv declarations and integration with Ubuntu's command-not-found. Additionally, it displays the version-control information of a directory (works for svn, git, etc.)

http://sandeep.wordpress.com/zshrc/


I've been using zsh with my old 300 line bashrc for several months now.

If you haven't already, try copying your .profile to .zshrc (just to see if it works); only your login shell reads your .profile.


zsh uses .zprofile, .zshrc and so on, if you're going to use the same contents you could simply symlink them.


zsh can even tab-complete remote paths when typing your ssh command line. (You should have an ssh-agent running or else you might be prompted for the password when hitting tab)

zsh might not be the last shell you ever need. Have a look at the friendly interactive shell: http://fishshell.org/ It looks really nice. But I too, have not yet replaced my beloved zsh.


Bash can also auto-complete remote paths, if appropriate keys are set.


Fish is zsh, but with reasonable defaults and worse customization. If you want to build/find a good zshrc, zsh is a good choice. Otherwise, fish is probably a better choice.


Not really, Fish's command language breaks compatibility with other POSIX shells in order to be cleaner and more consistent. So, you can't run sh or bash scripts with it. This isn't a huge issue, but definitely sets it apart from Zsh.


it's also REALLY slow, especially on startup.


Not in my experience.


re: completion. Also useful for developers - it will auto-complete svn and other vcs links with information from the remote hosts. (no more `svn ls ...`)


On a related note I have decided to post zsh related links/tips that I discover on twitter via @zshtips http://twitter.com/zshtips


I think delicious would be a better place to share articles about ZSH. Like: http://delicious.com/tag/zsh+tips .

But I'm interested in the point of view of people thinking that twitter would be a better place to share that kind of stuff.


@bashtips is pretty excellent as well.


It is, but the frequency of tips has drastically come down these days. :( For the interested and lazy, here's the link: http://twitter.com/bashtips


For some very nice tools to extend your ZSH experience, I would recommend http://github.com/robbyrussell/oh-my-zsh. As a bonus, Oh My ZSH has some extra nice features for those who use Rails.


if you really want to migrate to zsh, you should try this out:

http://github.com/robbyrussell/oh-my-zsh


I did something similar a little while ago and shared my zshrc setup/config with a basic set of files that people can use as a default and override.

http://naleid.com/blog/2009/05/13/shared-zshrc-file/

The repo to clone is on bitbucket:

http://bitbucket.org/tednaleid/shared-zshrc/


Have any of the projects to make a language REPL/shell hybrid gotten to a useful point yet? For instance, I'd love to be able to type regular commands with tab completion et al, but have anything in parens be a lisp expression. I'm holding off on learning ZSH because that seems like such a better solution, yet a good one hasn't materialized as of yet.


Eshell(http://www.emacswiki.org/emacs/CategoryEshell) seems to come closest to your specs, though it doesn't do input redirection.


You can do some really neat prompts using z-shell:

http://aperiodic.net/phil/prompt/


Ok, You Convinced Me. I've started using zsh on my Mac. Thank you in advance for saving me a whole lot of typing and time.


Haha, same here. I was on the edge for a long time. There goes my Sunday now ;)


I just started playing with it on Mac and now I'm wondering why does GUI exist. Here goes my final...


I used bash on Linux for 8 years because it was the default on Debian. I wish I'd been persuaded to change to zsh 9 years ago! The 1 year that I have been using it, I've really appreciated it.


Is there an equivalent to history-search-backward in zsh? In Bash, this is the search that looks for commands that start with whatever is to the left of the cursor.


add this to your .zshrc:

bindkey '^r' history-incremental-search-backward

I suggest to look for a .zshrc file, the article has a good one linked.


This site (http://grml.org/zsh/zsh-lovers.html) contains loads of zsh tricks. Very useful.


Question: Can the automatic paging of output interfere with piping or redirecting output? Or does it maybe work only in output going to the screen?


I don't think that people would be using it if it interfered with piping.


my bash, GNU bash, version 3.1.17(1), does (3)(2) kill job-completion; and (3)(3) ls option-completion (but no description). So it's partway there.


I've been meaning to try zsh. Maybe now's the time. Thanks for sharing and reminding me about it!


I definitely, definitely, definitely can't recommend it enough. I really wish someone had said exactly that sentence to me ten years ago!


A zsh article from 2007? Come on! I even commented on it before realizing it's ancient stuff.


Shells are the web frameworks of 10 years ago. Good programmers will create them fairly easily, they're all pretty similar, most people learn one and get good with them. Also just like web frameworks, everyone's convinced that their shell is superior and that they couldn't get any work done if they used yours.




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

Search: