Zsh

Содержание
Введение
Установка zsh
Установка Oh-my-zsh
Oh-my-zsh темы
zsh-syntax-highlighting: Подсветка

Введение

Z shell, zsh — одна из современных командных оболочек UNIX, использующаяся непосредственно как интерактивная оболочка, либо как скриптовый интерпретатор.

Zsh является расширенным аналогом, а также имеет обратную совместимость с bourne shell , имея большое количество улучшений.

Установка Zsh

Проверить какая оболочка активна в данный момент

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

Теперь нужно перелогиниться

echo $SHELL

/usr/bin/zsh

Установка 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

В этом примере я заменю дефолтную тему robbyrussell на crunch и затем настрою её под себя.

# ZSH_THEME="robbyrussell" ZSH_THEME="crunch"

Затем можно отредактировать тему по своему усмотрению.

В данном примере я закомментировал оригинальную строку PROMPT и добавил две новые

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%}"

Теперь терминал выглядит следующим образом

andrei@andrei-VirtualBox {12:11}~

И что мне особенно нравится - показывает текущую ветку git

andrei@andrei-VirtualBox {12:12}~/sandbox:master ✓

zsh-syntax-highlighting

Не путать с подсветкой кода в текстовом редакторе

Подсветка синтаксиса вводимых команд.

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)

Если до этого использовались другие плагины - добавьте zsh-syntax-highlighting в конец через запятую

ls **/*(jpg|png)

c.jpg d.png

Статьи про Zsh
Zsh
Bash
Linux
awk
grep
sed
Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@eth1.ru если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящуюю по тематике.
3. Хотите поддержать сайт материально
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......