Setting up a Linux terminal for productivity

Setting up a Linux terminal for productivity

·

10 min read

Introduction

Recently, I have installed my computer with Arch Linux. The decision to move to vanilla Arch from EndeavourOS (another Arch-based distro) was quite an organic one. I just thought of starting with a clean slate without any preinstalled apps.

During this process, there was a point when I had to set up my development environment from scratch. It involved setting up the terminal, installing all the required tools etc. While doing it, I thought of sharing the journey of how I configured a productive terminal environment for software development.

In this article, I'll take you through how to configure your terminal environment for maximum efficiency and productivity. We will go over the following:

  • WezTerm: A fully featured, modern terminal emulator.

  • Zsh: An advanced interactive shell.

  • TMUX: A terminal multiplexer for efficient handling of multiple terminal sessions.

  • Neovim: How to configure this immensely capable and extendable text editor as an IDE.

  • Some of the coolest terminal applications which will take your productivity to the next level.

Let's dive into creating a productivity-enhancing terminal setup and, at the same time, making it enjoyable to work in the terminal!

Pre-requisites

Before we proceed with configuring your terminal, please ensure you have the following installed. Since I am using Arch, I will be using pacman to install packages. You can install the same using the package manager in your distro.

Install and configure the necessities

1. Install Python (Only required for configuring Neovim)

sudo pacman -S python

2. Install Pip (Only required for configuring Neovim)

sudo pacman -S python-pip

3. Install Node.js (Only required for configuring Neovim)

sudo pacman -S nodejs

4. Install and Configure Git

sudo pacman -S git

Configure Git with your username and email:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

More details could be found here - https://docs.github.com/en/get-started/getting-started-with-git/set-up-git

5. Installing Hack Nerd Font

Nerd Fonts provide a wide range of glyphs from popular iconic fonts. The help in enhancing the look of your terminal. My favourite nerd font is Hack Nerd Font You can install any of the nerd fonts from here - https://www.nerdfonts.com/font-downloads and use it.

sudo pacman -S ttf-hack-nerd

6. Install Fuzzy Finder for terminal

sudo pacman -S fzf

Install and configure WezTerm

WezTerm is a wonderful open-source terminal emulator which is well known for its performance and customisation capabilities. The highlight of WezTerm is that we can configure it using Lua. I am quite sure WezTerm will take your terminal experience to the next level.

1. Install WezTerm

sudo pacman -S wezterm

2. Configure WezTerm

Once WezTerm is installed, you can try launching it. I admit that the default look and feel of WezTerm is not so appealing. It is now time to configure it and make it beautiful.

Create a new folder wezterm inside your .config folder and navigate inside it with the following commands.

cd ~/.config
mkdir wezterm
cd wezterm

Create a new file, .wezterm.lua

touch .wezterm.lua

Open this file in an editor of your choice. I used Neovim. You are free to use any editor of your choice.

Neovim (If you have it installed):

nvim .wezterm.lua

Following is the config I used. Please follow inline comments for more explanation. Uncomment lines if required. Add the contents to the config file we just created.

local wezterm = require("wezterm")

-- This Lua table will hold the WezTerm configuration.
local config = wezterm.config_builder()

config.font = wezterm.font("Hack Nerd Font Mono") -- Change this if you have a different Nerd Font installed.
config.font_size = 12 -- Change this to suit your need. A different screen resolution might need a change here

config.window_padding = {
    left = 0,
    right = 0,
    top = 0,
    bottom = 0,
}

-- Set the initial Terminal Size here
config.initial_cols = 140 -- Width
config.initial_rows = 65 -- Height

-- Set the terminal's opacity.
-- 1 = Opaque. 0 = Transparent.
-- Choose a value as per your need.
config.window_background_opacity = 0.96

-- Enable the following if you want to use an image as the background
-- config.window_background_image = "background.jpg" -- Select background image of your choice
-- config.window_background_image_hsb = {
--      -- Darken the background image by reducing it to 1/3rd
--      brightness = 0.1,
--
--      -- You can adjust the hue by scaling its value.
--      -- a multiplier of 1.0 leaves the value unchanged.
--      hue = 1.0,
--
--      -- You can adjust the saturation also.
--      saturation = 1.0,
-- }
-- End of background image configuration

-- Select a good theme
-- More themes could be found here - https://wezfurlong.org/wezterm/colorschemes/index.html
config.color_scheme = "Flatland"
-- Here are some of the themes I personally like
-- config.color_scheme = "Catppuccin Mocha"
-- config.color_scheme = "Ciapre (Gogh)"
-- config.color_scheme = "Dawn (terminal.sexy)" -- Brown tint
-- config.color_scheme = "Sandcastle (base16)"
-- config.color_scheme = "Afterglow (Gogh)"
-- config.color_scheme = "Apprentice (Gogh)"
-- config.color_scheme = "Chameleon (Gogh)"
-- config.color_scheme = "Ciapre (Gogh)"
-- config.color_scheme = "Dawn (terminal.sexy)"
-- config.color_scheme = "FishTank"

config.enable_tab_bar = false -- This will remove the top tab bar of the terminal window. If you wish to have it, Please comment this line.
config.window_decorations = "RESIZE" -- This will remove the title bar and borders of the terminal and make it floating. Comment this line if you wish to keep the default style.

return config

I have made the same publicly available in GitHub - https://github.com/febinjoy/wezterm-config/blob/main/.wezterm.lua. Any changes to the above based on my future workflow could be found there.

Now, launch WezTerm to see your configuration in action. You would be having WezTerm up and running with your custom configuration.

Install and configure Zsh

Zsh is a powerful shell that is highly customisable which and provides you with a better command line experience. It has plenty of features compared to the traditional Bash shell; which makes it a favourite choice of developers. I, personally, prefer Zsh over bash. Now, I will walk you through the installation and configuration of Zsh which will make your terminal both functional and more stylish.

1. Install Zsh

sudo pacman -S zsh

Even though we have installed Zsh, our current shell is still bash. Now, we will need to switch to using Zsh. Find the path where Zsh is installed (Usually, it will be /usr/bin/zsh).

Use the following command to change the shell.

sudo chsh <your username>

When prompted, provide the path to Zsh as the path to new shell. This will change it from /usr/bin/bash to /usr/bin/zsh

Run the following to confirm it is set properly.

echo $SHELL

If you ever feel like switching back to bash, use the same method and provide path to bash.

2. Configure Zsh

Now it is time to configure your shell.

Create a file .zshrc and .zsh_history in the home directory using the following

touch ~/.zshrc
touch ~/.zsh_history

Open the .zshrc file and add the following lines.

ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [ ! -d $ZINIT_HOME ]; then
  mkdir -p "$(dirname $ZINIT_HOME)"
  git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
source "${ZINIT_HOME}/zinit.zsh"

zinit ice depth=1; zinit light romkatv/powerlevel10k

#-----zsh-history-file-----
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=`$HISTSIZE`

# In Arch, the delete key was not properly mapped. Comment this if not required.
bindkey "^[[3~" delete-char

Save the file, exit WezTerm and launch again. Confirm everything is working correctly by running zinit zstatus

In the above configuration, You might have noticed that I have installed a package called Powerlevel10K. Powerlevel10k is probably one of the most popular Zsh themes, developed with a goal of having a very customisable and good-looking prompt in your terminal. It is fast, feature-rich, and offers a bunch of options for making your prompt show information like git status, command execution time, and many more. Powerlevel10k works out of the box with Nerd Fonts, making your terminal look beautiful and informative at the same time. Once you relaunch Wezterm, you will be greeted with a screen to configure Powerlevel10k. Follow the prompts and choose the style of your choice. Once it is done, It will add the following lines to your .zshrc file. Don’t remove it manually.

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. 
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

I went ahead and made extra refinements to my .zshrc file to suit my needs. Here is the final version for your reference.

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [ ! -d $ZINIT_HOME ]; then
  mkdir -p "$(dirname $ZINIT_HOME)"
  git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
source "${ZINIT_HOME}/zinit.zsh"

zinit ice depth=1; zinit light romkatv/powerlevel10k

# Add in zsh plugins
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light Aloxaf/fzf-tab

# Add in snippets
zinit snippet OMZP::git
zinit snippet OMZP::sudo
zinit snippet OMZP::archlinux
zinit snippet OMZP::extract


# Load zsh-completions
autoload -U compinit && compinit

# Key bindings
bindkey '^]' autosuggest-accept
bindkey '^p' history-search-backward
bindkey '^n' history-search-forward
bindkey "^[[3~" delete-char

# Setup zsh-history-file
export HISTFILE=~/.zsh_history
export HISTSIZE=10000
export SAVEHIST=$HISTSIZE
export HISTDUP=erase

# Options
setopt APPEND_HISTORY
setopt SHARE_HISTORY
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS
setopt HIST_IGNORE_DUPS
setopt HIST_FIND_NO_DUPS
setopt EXTENDED_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_VERIFY

# Aliases
alias ls='ls --color'
alias grep='grep --color'
alias fgrep='fgrep --color'
alias egrep='egrep --color'

# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'ls --color=always $realpath'
zstyle ':fzf-tab:complete:__zooxide_z:*' fzf-preview 'ls --color=always $realpath'

# Shell integrations
eval "$(fzf --zsh)"

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

I have installed plugins for auto suggestions, syntax highlighting, auto-completion etc. Few key bindings are also added. Please refer to inline comments for reference. You are welcome to change or add more.

Install and configure TMUX

TMUX or Terminal Multiplexer is one of the powerful utilities that enable you to manage multiple terminal sessions from within a single screen. It enhances productivity by enabling you to split your terminal into several panes, switching between them easily, and keep your sessions running even while you are disconnected.

1. Install TMUX

Use the following command to install tmux:

sudo pacman -S tmux

Configure TMUX

Here is a wonderful article which helps you customise and configure TMUX - https://hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/

Install and configure Neovim

Neovim is a modern and enhanced version of the very famous code editor Vim. It provides an improved configuration system using Lua (like WezTerm) that is more user-friendly and aims at improving performance and extensibility. It is by far one of my favourite code editors of choice. I use it to write Python, Go, C# and JavaScript code and have extended it to have Syntax highlighting, LSP support, debugging support, Automatic code completion etc. Please refer to https://github.com/febinjoy/febins-neovim-config for more details. I am not elaborating further on this, as this article is more focused on making your terminal more beautiful and productive. If required, I can write an article on Neovim, and it's configuration later.

Other terminal-based productivity tools that I use

Lazygit

Lazygit is a simple terminal-based UI for Git. It makes performing Git commands in a more easy and productive way. It exposes an intuitive, easy-to-use interface to navigate through repositories, stage changes, create commits, and manage branches-all without the need to memorise more complicated git commands. Install Lazygit with the following command:

sudo pacman -S lazygit

Ranger

Ranger is a powerful file manager for the terminal. It presents your file system in a nice-looking, navigable way and features previews of files, bookmarks for directories, and execution of shell commands. It does a lot more than classical ways of navigating through terminals. Install it using the following:

sudo pacman -S ranger

htop

htop is a process viewer which provides a comprehensive overview of the running system processes. Install it with the following:

sudo pacman -S htop

ncdu

It is a disk usage analyser which helps you to understand your disk space usage.

sudo pacman -S ncdu

bat

Bat is a clone of the popular Linux tool cat. Bat provides syntax highlighting on top of cat which helps to view and understand code in terminal easier.

sudo pacman -S bat

ripgrep

ripgrep is a fast search tool for large codebases. I use it in side my Neovim setup.

sudo pacman -S ripgrep

The final result

And here is the final result. You can see TMUX in action with Neovim on the left side and Ranger and Lazygit stacked vertically on the right side.

Shout-outs and courtesy notes

Big shout-out to all those wonderful developers who dedicated their efforts in creating and maintaining these wonderful applications and sharing it with the community.