Install

On macOS, install with Homebrew:

brew install zsh

On Ubuntu Linux:

sudo apt-get install zsh

Initial configuration

Type zsh and then follow the prompt to configuration zsh

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

--- Type one of the keys in parentheses --- 1
Attempting to extract information from manual pages...
Please pick one of the following options:

(1)  Configure settings for history, i.e. command lines remembered
     and saved by the shell.  (Recommended.)

(2)  Configure the new completion system.  (Recommended.)

(3)  Configure how keys behave when editing command lines.  (Recommended.)

(4)  Pick some of the more common shell options.  These are simple "on"
     or "off" switches controlling the shell's features.

(0)  Exit, creating a blank ~/.zshrc file.

(a)  Abort all settings and start from scratch.  Note this will overwrite
     any settings from zsh-newuser-install already in the startup file.
     It will not alter any of your other settings, however.

(q)  Quit and do nothing else.  The function will be run again next time.
--- Type one of the keys in parentheses ---

Install Prezto

Presto is a configuration framework for Zsh.

  1. Launch Zsh:

     zsh
    
    
  2. Clone the repository:

     git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
    
    

    If installing the 'paradox' prompt theme:

      git clone --recursive https://github.com/paradox460/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
    
    
  3. Create a new Zsh configuration by copying the Zsh configuration files provided:

     setopt EXTENDED_GLOB
     for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
       ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
     done
    
    

    If it gives any warnings, you may need to remove the previously existing configuration files .zsh* and .prezto*.

  4. Set Zsh as your default shell:

Use the "default" zsh:

    chsh -s /bin/zsh

If on macOS and if zsh was installed using Homebrew as /usr/local/bin/zsh:

    chsh -s /usr/local/bin/zsh

does not actually work. Use System Preferences > Users & Groups > unlock, select the user, right click and open "Advanced Options...", change shell to /usr/local/bin/zsh.

References: * http://superuser.com/questions/362372/change-the-login-shell-of-mac-os-x-lion-from-bash-to-zsh * http://osxdaily.com/2012/03/21/change-shell-mac-os-x/. * http://stackoverflow.com/questions/3327013/how-to-determine-the-current-shell-im-working-on

  1. Open a new Zsh terminal window or tab.

Customize command prompt

http://www.paradox.io/posts/9-my-new-zsh-prompt

Modularizing .bashrc and .zshrc

meng  ~  ls -la /home/meng/.bashrc*
-rw-r--r-- 1 meng 3823 Jan 27 19:05 /home/meng/.bashrc
lrwxrwxrwx 1 meng   85 Jan 27 19:13 /home/meng/.bashrc_meng -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Bash/.bashrc_meng*
lrwxrwxrwx 1 meng   84 Jan 27 19:13 /home/meng/.bashrc_all -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Bash/.bashrc_all
lrwxrwxrwx 1 meng   86 Jan 27 19:13 /home/meng/.bashrc_linux -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Bash/.bashrc_linux
lrwxrwxrwx 1 meng   93 May 10 22:53 /home/meng/.bashrc_mengmaclaplx -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Bash/.bashrc_mengmaclaplx
lrwxrwxrwx 1 meng   91 May 11 17:34 /home/meng/.bashrc-zshrc_main -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Bash/.bashrc-zshrc_main
 meng  ~  ls -la ~/.zshrc*
 lrwxrwxrwx 1 meng 35 May 10 16:45 /home/meng/.zshrc -> /home/meng/.zprezto/runcoms/zshrc
 lrwxrwxrwx 1 meng 83 May 10 18:47 /home/meng/.zshrc_meng -> /home/meng/Dropbox/WorkSpace/Computing/ConfigurationFiles/Zsh/.zshrc_meng

Depending on if Bash or Zsh is used, either .bashrc is loaded which in turn loads .bashrc_meng or .zshrc is loaded which in turn loads .zshrc_meng.

.bashrc_meng and .zshrc_meng loads the main entry file .bashrc-zshrc_main which loads other smaller OS-dependent and computer-dependent configuration files.

References

blog comments powered by Disqus