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:
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
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.
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...
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.)
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.
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.
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 ...`)
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.
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.
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.
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.
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
Then just include ${ERRVAL} in your PS1.