Tag Archives: zsh

Telling bash to step aside for zsh

So, let’s say that you want to change your shell to zsh, but fall back to bash if it isn’t available on whatever system you’re using. This is useful if you use something like NIS or LDAP with home directory NFS, since you’ll be sshing around and bringing your .bashrc with you everywhere. The solution is pretty simple – just add this to the bottom of your .bashrc:

hash zsh 2>&- && exec zsh

Update: This breaks X-windows. Need to figure out why…
Update: My esteemed colleague informed me that I should check for interactive shell, which is a dead give-away for X:

if [ ! -z $PS1 ]; then
  hash zsh 2>&- && exec zsh -l
fi


A zsh adventure

Oh yeah, zsh guys.  It’s awesome, and you should know that, but what makes one switch from good ol’ bash?  Generally, it’s prompt magic, but really there’s some other nice features that make it worth considering.  But first, prompt magic.  I had some trouble getting the prompt to respect the width of my terminal, but it was resolved by escaping some things I had in there.  I ended up with this:

To do that, you just need the following in your .zshrc in your home directory:

autoload -U colors && colors

# Prompt Customization
PS1="%{$fg[blue]%}%n%{$fg_bold[yellow]%}✯%{$fg[blue]%}%m%{$fg_bold[black]%}:%{$fg_no_bold[green]%}%~ %{$fg_bold[black]%}%#%{$reset_color%} "
RPS1="%{$fg_bold[black]%}%D{%Y%m%d %H:%M}%{$reset_color%}"

Yes, that’s a unicode character.  That’s perfectly legal, which is awesome.  Next, we have to get bash reverse history search functionality working in zsh, which is really easy with a simple keybinding for control-r:

## History search like bash
bindkey '\e[3~' delete-char
bindkey '^R' history-incremental-search-backward

And we’re off to the races.  So far, I really like it.  I recommend that you *nix nerds try it.