ZSH

Install and set up zsh as default

  1. With the package manager of your choice, e.g. sudo apt install zsh or brew install zsh for macOS
  2. Verify installation by running zsh --version. Expected result: zsh 5.0.8 or more recent.
  3. Make it your default shell: chsh -s $(which zsh)
  4. Log out and log back in again to use your new default shell.
  5. Test that it worked with echo $SHELL. Expected result: /bin/zsh or similar.
  6. Test with $SHELL --version. Expected result: zsh 5.8 or similar

Adding an Oh-my-ZSH addon

While you’re at it, you can also install the most popular Zsh plugin, oh-my-zsh, that comes with many built-in plugins and themes using this install script:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Install Powerline fonts

$ git clone https://github.com/powerline/fonts.git
$ cd fonts
$ ./install.sh

Change the Theme to “agnoster”

$ nano ~/.zshrc
Set ZSH_THEME="agnoster" and save the file

Install zsh-autosuggestions

  1. Install the zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. Add plugin in ~/.zshrc
$ nano ~/.zshrc
...
plugins=(git)
plugins=(zsh-autosuggestions) # Add this line. under the "plugins"
$ source $ZSH/oh-my-zsh.sh
  1. Refresh the terminal.

Click the tiny refresh icon on the left side of the terminal tab.

  1. Enter ls

Then you can see that -al is automatically printed.

Add Syntax Highlighting Plugin

The Syntax Highlighting plugin adds beautiful colors to the commands you are typing as shown below.

  1. Clone the zsh-syntax-highlighting plugin’s repo and copy it to the “Oh My ZSH” plugins directory.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. Activate the plugin in ~/.zshrc by adding zsh-syntax-highlighting to the Plugins section as shown below.

Add a new plugin in a new line inside plugins section

  1. Re-read zshrc configuration
source ~/.zshrc

Useful zsh commands

  1. take — создать директорию и сразу в неё войти ( mkdir xxx | cd xxx )

  2. комманда, а затем стрелки вверх и вниз — история конкретной комманды

  3. ctrl+r — поиск по истории

  4. Необязательно писать cd, чтобы войти в директорию

  5. Mass rename files with zmv. To install zmv, run autoload zmv. I downloaded a lot of images for a machine learning model and wanted to rename them to be more consistent (ie. epcot-1.jpg, epcot-2.jpg, epcot-3.jpg… instead of 1.jpg, 2.jpg, 3.jpg…) The command to do so would be

    zmv '(*).(jpg|jpeg)' 'epcot-$1.$2'
    

To check what would happen before running the command, you can add -n, instead running

```
zmv -n '(*).(jpg|jpeg)' 'epcot-$1.$2'
```

What does that command mean? (*).(jpg|jpeg) finds each file in the directory that ends in either .jpg or .jpeg. Then epcot-$1.$2 says to edit each file name by prepending epcot- followed by the original file name (represented by $1) and then the original file type (with $2).

  1. zcalc — простой калькулятор командной строки