4 min read

Terminal Customization in Linux

We used AI while writing this content.

Supported Shells

Bash
Zsh
Fish

Setup

0. Ensure you are running bash

getent passwd <username>
sudo chsh -s /bin/bash <username>

1. Customize your Bash prompt

The Bash prompt is controlled by the PS1 environment variable. Add the following to your ~/.bashrc:

# Basic colored prompt with username, hostname, and current directory
export PS1="\[\e[32m\]\u@\h\[\e[0m\]:\[\e[34m\]\w\[\e[0m\]\$ "

The \e[32m sets green color, \u shows username, \h shows hostname, \w shows working directory, and \e[0m resets color.

Apply changes immediately:

source ~/.bashrc

2. Add useful aliases

Aliases are shortcuts for frequently used commands. Add these to ~/.bashrc:

# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ll='ls -lah'
alias la='ls -A'

# Safety nets
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Git shortcuts
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline --graph --decorate'

# System
alias update='sudo apt update && sudo apt upgrade -y'
alias ports='netstat -tulanp'

3. Enable better command history

Add these lines to ~/.bashrc for improved history management:

# Don't save duplicate commands
export HISTCONTROL=ignoredups:erasedups

# Larger history
export HISTSIZE=10000
export HISTFILESIZE=20000

# Append to history file, don't overwrite
shopt -s histappend

# Save multi-line commands as one entry
shopt -s cmdhist

4. Install and configure a modern prompt (optional)

For a more advanced prompt with Git integration, install Starship:

# Install Starship
curl -sS https://starship.rs/install.sh | sh

# Add to ~/.bashrc
echo 'eval "$(starship init bash)"' >> ~/.bashrc

Create a custom configuration at ~/.config/starship.toml:

[character]
success_symbol = "[➜](bold green)"
error_symbol = "[✗](bold red)"

[directory]
truncation_length = 3
truncate_to_repo = true

[git_branch]
symbol = "🌱 "

[git_status]
ahead = "⇡${count}"
diverged = "⇕⇡${ahead_count}⇣${behind_count}"
behind = "⇣${count}"

5. Configure terminal colors and fonts

Most modern terminals support 256 colors. Test support:

# Test 256-color support
curl -s https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw/ | bash

For better fonts, install a Nerd Font:

# Download and install FiraCode Nerd Font
mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts
curl -fLo "Fira Code Regular Nerd Font Complete.ttf" \
  https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/FiraCode/Regular/FiraCodeNerdFont-Regular.ttf
fc-cache -fv

Change your terminal emulator's font settings to use "FiraCode Nerd Font" for best icon support.

6. Enable syntax highlighting (optional)

Install bash-completion for better tab completion:

sudo apt install bash-completion

For command syntax highlighting as you type, consider switching to Zsh with Oh My Zsh, or install bash-preexec:

# Clone bash-preexec
git clone https://github.com/rcaloras/bash-preexec.git ~/.bash-preexec
echo '[[ -f ~/.bash-preexec/bash-preexec.sh ]] && source ~/.bash-preexec/bash-preexec.sh' >> ~/.bashrc

7. Create custom functions

Add useful functions to ~/.bashrc:

# Create directory and cd into it
mkcd() {
    mkdir -p "$1" && cd "$1"
}

# Extract any archive format
extract() {
    if [ -f "$1" ]; then
        case "$1" in
            *.tar.bz2)   tar xjf "$1"     ;;
            *.tar.gz)    tar xzf "$1"     ;;
            *.bz2)       bunzip2 "$1"     ;;
            *.rar)       unrar x "$1"     ;;
            *.gz)        gunzip "$1"      ;;
            *.tar)       tar xf "$1"      ;;
            *.tbz2)      tar xjf "$1"     ;;
            *.tgz)       tar xzf "$1"     ;;
            *.zip)       unzip "$1"       ;;
            *.Z)         uncompress "$1"  ;;
            *.7z)        7z x "$1"        ;;
            *)           echo "'$1' cannot be extracted via extract()" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Find files by name
ff() {
    find . -type f -iname "*$1*"
}

8. Advanced options

Organization and advanced customizations

• Split your configuration into multiple files (e.g., ~/.bash_aliases, ~/.bash_functions) and source them from ~/.bashrc.
• Use ~/.inputrc to customize readline behavior (e.g., case-insensitive tab completion).
• Install tmux for terminal multiplexing and session management.
• Consider terminal emulators like Alacritty, Kitty, or WezTerm for better performance and features.
• Use direnv for per-directory environment variables.

Example ~/.inputrc for better tab completion:

# Case-insensitive completion
set completion-ignore-case on

# Show all completions immediately
set show-all-if-ambiguous on

# Color completion
set colored-stats on

# Show file type indicator
set visible-stats on

Bash Reference Manual
Starship Prompt
Oh My Bash
Nerd Fonts
Bash Aliases Gist

Quick Reference

Common PS1 Escape Sequences

Sequence Description
\u Username
\h Hostname (short)
\H Hostname (full)
\w Current working directory
\W Basename of working directory
\$ # if root, $ otherwise
\t Time (24-hour HH:MM:SS)
\d Date (Weekday Month Date)
\n Newline

ANSI Color Codes

Color Code
Black \e[30m
Red \e[31m
Green \e[32m
Yellow \e[33m
Blue \e[34m
Magenta \e[35m
Cyan \e[36m
White \e[37m
Reset \e[0m

Copyleft Statement

Renoncé du droit d'auteur

Much of our content is freely available under the Creative Commons BY-NC-ND 4.0 licence, which allows free distribution and republishing of our content for non-commercial purposes, as long as Ronzz.org is appropriately credited and the content is not being modified materially to express a different meaning than it is originally intended for. It must be noted that some images on Ronzz.org are the intellectual property of third parties. Our permission to use those images may not cover your reproduction. This does not affect your statutory rights.

Nous mettons la plupart de nos contenus disponibles gratuitement sous la licence Creative Commons By-NC-ND 4.0, qui permet une distribution et une republication gratuites de notre contenu à des fins non commerciales, tant que Ronzz.org est correctement crédité et que le contenu n'est pas modifié matériellement pour exprimer un sens différent que prévu à l'origine.Il faut noter que certaines images sur Ronzz.org sont des propriétés intellectuelles de tiers. Notre autorisation d'utiliser ces images peut ne pas couvrir votre reproduction. Cela n'affecte pas vos droits statutaires.