Tune-up your terminal
Tags: linux, shell, zsh
Published: 2020-02-21 15:52:40

You spend in your terminal fair amount of time (others live on it). How about customize it to make your terminal more fun, or at least better looking?
I'll show you how I do it. I will use Fedora Linux for this example, but you can use any distribution or MacOS.

## Getting started

Install ZSH to replace Bash. In Fedora this can be achieved easily using dnf:

```bash
sudo dnf install -y zsh # Install
chsh -s $(which zsh)    # set as default
zsh                     # start zsh
```

install [oh-my-shell](https://ohmyz.sh/) plugin framework:

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

You should be in this state:
![oh-my-zsh](https://dev-to-uploads.s3.amazonaws.com/i/1w4y43livsipiqqimv01.png)

## Customizing


### [Powerlevel10k](https://github.com/romkatv/powerlevel10k)

```bash
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
```

You then need to select this theme in your ~/.zshrc:

```bash
ZSH_THEME="powerlevel10k/powerlevel10k"
```

Install nerd fonts to have special glyphs in your shell:

```bash
mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts
curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
```

Your shell should now look like this:
![PowerLevel9k](https://dev-to-uploads.s3.amazonaws.com/i/pc1o1j0jea9ffm2vv8jb.png)


I have additional settings in my Powerlevel9k configuration. I paste it here in case you like or you want to use it as a starting point.

```bash
# Prompt elements
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir dir_writable vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status command_execution_time background_jobs nvm rvm pyenv time)
## OS Icon
POWERLEVEL9K_OS_ICON_BACKGROUND="white"
POWERLEVEL9K_OS_ICON_FOREGROUND="blue"
## VCS
POWERLEVEL9K_VCS_CLEAN_FOREGROUND='black'
POWERLEVEL9K_VCS_CLEAN_BACKGROUND='119'
POWERLEVEL9K_VCS_UNTRACKED_FOREGROUND='black'
POWERLEVEL9K_VCS_UNTRACKED_BACKGROUND='202'
POWERLEVEL9K_VCS_MODIFIED_FOREGROUND='black'
POWERLEVEL9K_VCS_MODIFIED_BACKGROUND='214'

## Langs
POWERLEVEL9K_PYENV_FOREGROUND="blue"
POWERLEVEL9K_PYENV_BACKGROUND="black"
POWERLEVEL9K_RVM_FOREGROUND="red"
POWERLEVEL9K_RVM_BACKGROUND="black"
POWERLEVEL9K_NVM_FOREGROUND="green"
POWERLEVEL9K_NVM_BACKGROUND="black"
  # Use to visualize: get_icon_names
POWERLEVEL9K_PYTHON_ICON="\uf81f"
POWERLEVEL9K_RUBY_ICON="\uE791"
POWERLEVEL9K_NODE_ICON="\uE781"

# RIGHT
POWERLEVEL9K_STATUS_OK_BACKGROUND="clear"
POWERLEVEL9K_STATUS_OK_FOREGROUND="green"
POWERLEVEL9K_STATUS_ERROR_BACKGROUND="clear"
POWERLEVEL9K_STATUS_ERROR_FOREGROUND="red"

POWERLEVEL9K_COMMAND_EXECUTION_TIME_BACKGROUND="grey"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND="white"
POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=0

POWERLEVEL9K_BACKGROUND_JOBS_VERBOSE=true
POWERLEVEL9K_BACKGROUND_JOBS_FOREGROUND='black'
POWERLEVEL9K_BACKGROUND_JOBS_BACKGROUND='178'

POWERLEVEL9K_TIME_FOREGROUND="250"
POWERLEVEL9K_TIME_BACKGROUND="grey"
POWERLEVEL9K_TIME_ICON="\uf073"
POWERLEVEL9K_TIME_FORMAT="%D{%L:%M:%S \uf017  %d.%m.%y}"

# Dir
POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD=true
POWERLEVEL9K_DIR_PATH_SEPARATOR_FOREGROUND="white"
POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle"
POWERLEVEL9K_SHORTEN_DIR_LENGTH=3
POWERLEVEL9K_DIR_HOME_FOREGROUND="white"
POWERLEVEL9K_DIR_HOME_SUBFOLDER_FOREGROUND="white"
POWERLEVEL9K_DIR_DEFAULT_FOREGROUND="white"
POWERLEVEL9K_DIR_ETC_BACKGROUND="52"
POWERLEVEL9K_DIR_ETC_FOREGROUND="white"

POWERLEVEL9K_DIR_WRITABLE_FORBIDDEN_FOREGROUND="11"
```

Now it should look like this:
![My customizations](https://dev-to-uploads.s3.amazonaws.com/i/xi2z2dl4fisyg5lej97g.png)

We are almost done, we need to customize it further with plugins.

## Plugins

You need to add the plugin name to the variable `plugins` in your `~/.zshrc` file. Then restart the shell. Also, you can reload it with `source ~/.zshrc`.

### Colored Man Pages

#### Install
Just add `colored-man-pages` to your plugins variable list.

![colored-man-pages](https://dev-to-uploads.s3.amazonaws.com/i/cd9tekvi4djzf1zhyptf.png)

### zsh-syntax-highlighting

![zsh-syntax-highlighting](https://dev-to-uploads.s3.amazonaws.com/i/a6rvutn5kr5ijvywvr8b.png)

#### Install
```bash
git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
```
and add `zsh-syntax-highlighting` to your plugins variable list

#### Configure
```bash
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)
# override main colors:
ZSH_HIGHLIGHT_STYLES[default]='none'
ZSH_HIGHLIGHT_STYLES[unknown-token]='fg=red,bold'
ZSH_HIGHLIGHT_STYLES[reserved-word]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[assign]='fg=yellow,bold'
ZSH_HIGHLIGHT_STYLES[alias]='fg=26'
ZSH_HIGHLIGHT_STYLES[function]='fg=magenta,bold'
ZSH_HIGHLIGHT_STYLES[builtin]='fg=26'
ZSH_HIGHLIGHT_STYLES[command]='fg=26'
ZSH_HIGHLIGHT_STYLES[hashed-command]='fg=red,bold,standout'
ZSH_HIGHLIGHT_STYLES[commandseparator]='fg=190'
ZSH_HIGHLIGHT_STYLES[path]='fg=white,underline'
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=white,underline'
ZSH_HIGHLIGHT_STYLES[path_approx]='fg=green,bold'
ZSH_HIGHLIGHT_STYLES[globbing]='fg=yellow,bold'
ZSH_HIGHLIGHT_STYLES[history-expansion]='fg=yellow'
ZSH_HIGHLIGHT_STYLES[single-hyphen-option]='fg=39'
ZSH_HIGHLIGHT_STYLES[double-hyphen-option]='fg=39'
ZSH_HIGHLIGHT_STYLES[dollar-double-quoted-argument]='fg=cyan'
ZSH_HIGHLIGHT_STYLES[back-double-quoted-argument]='fg=blue'
ZSH_HIGHLIGHT_STYLES[single-quoted-argument]='fg=172'
ZSH_HIGHLIGHT_STYLES[double-quoted-argument]='fg=178'
ZSH_HIGHLIGHT_STYLES[rc-quote]='fg=177'
ZSH_HIGHLIGHT_STYLES[redirection]='fg=190'
ZSH_HIGHLIGHT_STYLES[arg0]='fg=45'

# override bracket colors:
ZSH_HIGHLIGHT_STYLES[bracket-error]='fg=red,bold'
# uniform / less distracting:
ZSH_HIGHLIGHT_STYLES[bracket-level-1]='fg=magenta,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-2]='fg=magenta'
ZSH_HIGHLIGHT_STYLES[bracket-level-3]='fg=magenta,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-4]='fg=magenta'
ZSH_HIGHLIGHT_STYLES[bracket-level-5]='fg=magenta,bold'
ZSH_HIGHLIGHT_STYLES[bracket-level-6]='fg=magenta'

# override pattern colors:
ZSH_HIGHLIGHT_PATTERNS+=('rm -[f,r] *' 'fg=red,bold,standout')
ZSH_HIGHLIGHT_PATTERNS+=('rm -[f,r][f,r] *' 'fg=red,bold,standout')
ZSH_HIGHLIGHT_PATTERNS+=('sudo dd *' 'fg=magenta,bold,standout')
ZSH_HIGHLIGHT_PATTERNS+=('sudo shred *' 'fg=magenta,bold,standout')
```

### Zsh AutoSuggestions

![zsh-autosuggestions](https://dev-to-uploads.s3.amazonaws.com/i/6fo16zfpgmu6klweay83.png)

#### Install
```bash
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
```
add `zsh-autosuggestions` to your plugins variable list

### history-substring-search

![history-substring-search](https://dev-to-uploads.s3.amazonaws.com/i/g7jva4kfkuhxwy422qdx.png)

When you type a command (curl in this example) and press up arrow you get a search in your history and get the complete command. The search string is highlighted in green.

#### Install
Just add `history-substring-search` to your plugins variable list.

#### Configure

```bash
# history-substring-search
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_FOUND='bg=green,fg=white,bold'
HISTORY_SUBSTRING_SEARCH_HIGHLIGHT_NOT_FOUND='bg=red,fg=white,bold'
HISTORY_SUBSTRING_SEARCH_GLOBBING_FLAGS='i'
```

## Conclusion

We have completely tuned our shell. These modifications can improve your productivity and make your terminal more pleasant to work with. From here you can customize it to make it your own and suit it to your specific needs.