Zsh
Introduction
Z shell, zsh, is one of the modern UNIX command shells, used directly as an interactive shell or as a script interpreter.
Zsh is an advanced analogue and is also backward compatible with
bourne shell
, having a large number of improvements.
Installing Zsh
Check which shell is active at the moment
echo $SHELL
/bin/bash
sudo apt install -y zsh
chsh -s /usr/bin/zsh
Password:
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. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator and exit (you will need to edit the file by hand, if so desired). --- Type one of the keys in parentheses ---
2
/home/andrei/.zshrc:15: scalar parameter HISTFILE created globally in function zsh-newuser-install
Now you need to log in again
echo $SHELL
/usr/bin/zsh
Installing Oh My Zsh
https://ohmyz.sh/#install
https://github.com/ohmyzsh/ohmyzsh/wiki
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Cloning Oh My Zsh... remote: Enumerating objects: 1295, done. remote: Counting objects: 100% (1295/1295), done. remote: Compressing objects: 100% (1249/1249), done. remote: Total 1295 (delta 26), reused 1259 (delta 26), pack-reused 0 Receiving objects: 100% (1295/1295), 1.06 MiB | 9.07 MiB/s, done. Resolving deltas: 100% (26/26), done. From https://github.com/ohmyzsh/ohmyzsh * [new branch] master -> origin/master Branch 'master' set up to track remote branch 'master' from 'origin'. Already on 'master' /home/andrei Looking for an existing zsh config... Found ~/.zshrc. Backing up to /home/andrei/.zshrc.pre-oh-my-zsh Using the Oh My Zsh template file and adding it to ~/.zshrc. __ __ ____ / /_ ____ ___ __ __ ____ _____/ /_ / __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \ / /_/ / / / / / / / / / / /_/ / / /_(__ ) / / / \____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/ /____/ ....is now installed! Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options. • Follow us on Twitter: https://twitter.com/ohmyzsh • Join our Discord community: https://discord.gg/ohmyzsh • Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh
Oh-my-zsh themes
https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
https://github.com/ohmyzsh/ohmyzsh/tree/master/themes
vi ~/.zshrc
In this example I will replace the default robbyrussell theme with crunch and then customise it to my liking.
# ZSH_THEME="robbyrussell" ZSH_THEME="crunch"
Then you can edit the theme as you like.
In this example I commented out the original PROMPT line and added two new ones
vi ~/.oh-my-zsh/themes/crunch.zsh-theme
# Put it all together! # PROMPT="$CRUNCH_TIME_$CRUNCH_RVM_$CRUNCH_DIR_$CRUNCH_PROMPT%{$reset_color%}" prompt_newline=$'\n%{\r%}' PROMPT="%n@%m $CRUNCH_TIME_$CRUNCH_RVM_$CRUNCH_DIR_$prompt_newline$CRUNCH_PROMPT%{$reset_color%}"
Now the terminal looks like this
andrei@andrei-VirtualBox {12:11}~ ➭
And what I like especially is that it shows the current branch git
andrei@andrei-VirtualBox {12:12}~/sandbox:master ✓ ➭
zsh-syntax-highlighting
Not to be confused with code highlighting in a text editor
Syntax highlighting of the commands you type.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Cloning into '/home/andrei/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting'... remote: Enumerating objects: 7016, done. remote: Counting objects: 100% (103/103), done. remote: Compressing objects: 100% (51/51), done. remote: Total 7016 (delta 50), reused 80 (delta 46), pack-reused 6913 Receiving objects: 100% (7016/7016), 1.52 MiB | 2.81 MiB/s, done. Resolving deltas: 100% (4725/4725), done.
vi ~/.zshrc:
plugins=(zsh-syntax-highlighting)
If other plugins were used before, add zsh-syntax-highlighting at the end, separated by a comma
ls **/*(jpg|png)
c.jpg d.png
Article author: Andrei Olegovich