Tune-up your terminal

iax

Isaías Piña

Posted on February 21, 2020

Tune-up your terminal

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:

sudo dnf install -y zsh # Install
chsh -s $(which zsh)    # set as default
zsh                     # start zsh
Enter fullscreen mode Exit fullscreen mode

install oh-my-shell plugin framework:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

You should be in this state:
oh-my-zsh

Customizing

Powerlevel10k

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

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

ZSH_THEME="powerlevel10k/powerlevel10k"
Enter fullscreen mode Exit fullscreen mode

Install nerd fonts to have special glyphs in your shell:

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
Enter fullscreen mode Exit fullscreen mode

Your shell should now look like this:
PowerLevel9k

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.

# 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"
Enter fullscreen mode Exit fullscreen mode

Now it should look like this:
My customizations

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

zsh-syntax-highlighting

zsh-syntax-highlighting

Install

git clone https://github.com/zsh-users/zsh-syntax-highlighting ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
Enter fullscreen mode Exit fullscreen mode

and add zsh-syntax-highlighting to your plugins variable list

Configure

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')
Enter fullscreen mode Exit fullscreen mode

Zsh AutoSuggestions

zsh-autosuggestions

Install

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
Enter fullscreen mode Exit fullscreen mode

add zsh-autosuggestions to your plugins variable list

history-substring-search

history-substring-search

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

# 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'
Enter fullscreen mode Exit fullscreen mode

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.

💖 💪 🙅 🚩
iax
Isaías Piña

Posted on February 21, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Tune-up your terminal
linux Tune-up your terminal

February 21, 2020