This is my collection of zsh configurations. And since dozens of my friends are not familiar with the shell. So I make many newbie tips along this document.
Many great shell key bindings are inheritant from Emacs and hence the Meta key is of good use. To enbale this, configure your iTerm2 at:
- iTerm > Preferences > Profile > Keys
- both options to
+Esc
. Now option keys act like Meta keys.
In the .zsh
directory, call the ./INSTALL.sh
to install it. The best practice is
install .zsh
folder under your home directory. Here is an example:
cd ~
git clone https://github.com/robturtle/.zsh.git
cd .zsh
chmod +x INSTALL.sh
./INSTALL.sh
NOTE: If you haven’t install oh-my-zsh
, the oh-my-zsh
installer will run a new
zsh shell after the installation finished. Please press Ctrl-D
to quit this shell to
make the INSTALL.sh
continue.
This is based on Oh-my-zsh, if you didn’t installed it or ~/.oh-my-zsh/
is not found,
the install script will install it automatically.
After the installation, you can simply restart your terminal to see the changes.
By default, you can store your custom configs in ~/.zsh.my.sh
. Typically
there are few variable you may be interested to change:
- DEFAULT_USER
- tell zsh your default user’s name so that you can log in without prompting current username
- INSTALLER
- the default is “brew install” for Mac users. If you’re a Linux user you must change this to your own package install command to make sure the auto-install facility works.
- my_zsh_mod
- specify plugins you want to load. You can view all available plugins in
plugins
folder. - MY_JAVA_CP
- used in java plugin. indicates where you preferred to store downloaded jar files. default value is “~/include/java/”
- ZSH_THEME
- my favorite is “agnoster” but it need fonts installed. read the Powerline Theme below for details.
The examples are:
#!/bin/zsh
# file: ~/.zsh.my.sh
DEFAULT_USER=jack
INSTALLER='sudo apt-get install'
my_zsh_mod=(python java)
MY_JAVA_CP='~/include/java/'
ZSH_THEME="agnoster" # make sure you've installed the specail fonts before setting it
During the installation process, the script will ask you some common settings. You can type in the value, or, just press enter to apply the default value.
I’ve collects several good functions from the web. Amount them I think there are 2 functions totally changed my life in the shell.
The first one is ranger – a file system manager in command line. Its key bindings are
simulating the vim. Its common used keys are listed at the ranger
section.
The second one is a shell history searching utility which make benifits from an interactive querying lib
– percol. With this you type some partial contents, separates keywords with whitespaces. And then the
percol
will filter the results for you.
name | function | rank |
---|---|---|
Ctrl+R | search shell history | Killer |
Ctrl-S | file manager | Killer |
ff | file partial searching | Helper |
pclip | stdin into clipboard | Helper |
The special fonts is to support the pertty display of powerline theme like:
Install the powerline fonts following instructions below:
- iTerm > Preferences > Profile > Text
- change both
Regular Font
andNon-ASCII Font
.
Now you can switch your theme into this pretty powrline theme. In your ~/.zsh.my.rc
, add
this line:
# file: ~/.zsh.my.sh
... # all other variables
ZSH_THEME="agnoster"
Then restart your shell.
I use solarized-light
and solarized-dark
theme in the iTerm2. They are automatically
downloaded into your ~/Download/
directory when you run the INSTALL.sh
. Double click
them you can import this color theme into the iTerm2.
To switch to this theme, go to iTerm2’s preference:
- iTerm > Preferences > Profile > Colors > Load Presets
- And choose “Solarized Light” or “Solarized Dark”
As an advise, I suggest you only use the dark color theme when the environment is dark or you have a monitor with bad quality.
Most of the shell supports Emacs key bindings by default.
Let ‘C’ stands for Ctrl, ‘M’ stands for ‘Meta’.
key | function | mutation | function |
---|---|---|---|
C-A | beginning of line | ||
C-E | E-nd of line | ||
C-K | K-ill to end of line | ||
C-U | U-ntype words | ||
C-D | D-elete forward | M-D | one word |
BACKSPACE/C-H | delete backward | M-BACKSPACE | one word |
C-F | move F-orward one char | M-F | one word |
C-B | move B-ackward one char | M-B | one word |
C-P | P-revious command | ||
C-N | N-ext command | ||
C-L | clear screen |
Being familiar with the Meta shortcuts will makes your shell using more effective.
in man
, less
, these vim style key bindings are also usable.
key | function |
---|---|
j | down |
k | up |
h | left |
l | right |
C-D | page D-own |
C-U | page U-p |
gg | first line |
G | last line |
slash | search |
key | function |
---|---|
SPACE | mark/unmark |
m | add bookmark |
` | goto bookmark |
j/k/h/l | navigates |
yy | copy marked files |
dd | cut marked files |
pp | paste |
:delete | delete marked files |
:mkdir | make directory |
zh | toggle show hidden files |
q | quit |
name | function | rank |
---|---|---|
gitkall | show all branches in gitk | Helper |
In my js mod file I prefer use npm install -g
without sudo
. Hence you may probably either remove “js” from my_zsh_mod
in ~/.zsh.my.sh
or fix the permission of the installation destination.
For Mac users, you may fix it by the command like chown -R ${USER} /usr/local
regarding to brew
’s convention.
I use `python -c “import ${package}”` to check if the package is installed. If you encounter this situtation, that means you didn’t configure your Python import path properly. Please remove “python” from my_zsh_mod
in ~/.zsh.my.sh
until you read about the Python’s sys.path
and configure it right.