
Zsh: The last shell you will ever need - r11t
http://friedcpu.wordpress.com/2007/07/24/zsh-the-last-shell-youll-ever-need/
======
keyist
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.

~~~
litewulf
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.

~~~
timf
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.

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

------
herdrick
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?

~~~
sandGorgon
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/>

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

~~~
likpok
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.

~~~
astine
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.

~~~
krakensden
it's also REALLY slow, especially on startup.

~~~
astine
Not in my experience.

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

~~~
jcsalterego
@bashtips is pretty excellent as well.

~~~
sundarurfriend
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>

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

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

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

~~~
tednaleid
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/>

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

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

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

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

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

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

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

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

~~~
oscardelben
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.

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

------
billswift
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?

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

------
10ren
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.

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

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

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

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

