Skip to content
shellhacks.dev
Command Line

How to Set Up a Productive Terminal From Scratch Properly

Build a productive terminal on a new machine: history, readline, prompt, fuzzy search, tmux and a dotfiles repository, with startup time kept low.

6 min read
Summarize in AI
Illustration for "How to Set Up a Productive Terminal From Scratch Properly": a terminal session, progress bars, environment variables.

The default terminal is usable, and a few settings change how much it costs you to find a command you ran last week, jump to a project or keep a session alive over a bad connection. The trap is the opposite one: pasting a stranger's two-hundred-line config, and ending with a shell that takes a second to open and breaks when something updates. This is a short, ordered setup, with the reasons, for Bash on Linux or macOS. It begins the developer terminal setup guide; the next posts cover fonts and themes and consistent script formatting.

The settings are for Bash 5.2 on Debian 13; the tools are the Debian packages fzf, ripgrep, bat, zoxide and tmux.

1. History that remembers

~/.bashrcShell
HISTSIZE=100000
HISTFILESIZE=200000
HISTCONTROL=ignoreboth:erasedups
shopt -s histappend
PROMPT_COMMAND='history -a'

A bigger history and histappend make terminals share one file instead of the last one closing overwriting the rest. history -a in PROMPT_COMMAND writes each command as it runs, so a crash does not lose it. ignoreboth skips duplicates and commands that start with a space. Be aware that a long history file also holds anything sensitive you typed, as keeping secrets out of shell history covers.

2. Readline: search by prefix

~/.inputrcText
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

With these, typing git and pressing the up arrow cycles through earlier commands starting with git, instead of everything. Completion lists matches on the first Tab and ignores case. These are read by every program that uses readline, not only Bash.

3. Tools that earn their place

Shell
sudo apt install fzf ripgrep bat zoxide tmux
ToolWhat it doesInitialize with
fzfFuzzy search for history (Ctrl+R), files (Ctrl+T), directories (Alt+C)eval "$(fzf --bash)" (fzf 0.48 and later)
zoxideJump to a frequently used directory with z nameeval "$(zoxide init bash)"
ripgrepFast recursive search that respects .gitignoreNothing; use rg
batcat with syntax highlighting; the binary is batcat on Debian and Ubuntualias bat=batcat
tmuxSessions that survive disconnects, panes, windows~/.tmux.conf

Do not add what you won't use. Each tool is a thing to install on every new machine and a line that runs at startup.

4. A prompt that tells you something

~/.bashrcShell
eval "$(starship init bash)"

Starship is one binary configured by ~/.config/starship.toml, showing the Git branch, the exit status of the last command and the duration of slow ones. A plain prompt works as well if it carries the last exit status: PS1='\u@\h:\w [$?]\$ '. The point is to see failure without running echo $?.

5. tmux in one paragraph

~/.tmux.confText
set -g mouse on
set -g history-limit 50000
set -g default-terminal "tmux-256color"
set -as terminal-features ',xterm-256color:RGB'

tmux new -As work attaches to a session named work, or creates it. Detach with Ctrl+B then D; the session and its processes keep running on the server, which is what protects long jobs from a dropped SSH connection. The last two lines turn on correct colors, for tmux 3.2 and later.

6. Keep it in a repository

Shell
mkdir -p ~/dotfiles && cd ~/dotfiles && git init
mv ~/.bashrc ~/.inputrc ~/.tmux.conf .
ln -s ~/dotfiles/.bashrc ~/.bashrc

Symbolic links point the usual locations into a Git repository, so a new machine is a clone and a few links. Write a small install script that links each file and refuses to overwrite a real one. Do not commit secrets: keep machine-specific values in a file such as ~/.bashrc.local that is ignored and sourced if it exists.

7. Measure startup

Shell
time bash -i -c exit

Each new terminal runs your config. Tools that initialize version managers (nvm, pyenv) are the usual cause of delay; load them on first use with a small function. See how Bash reads startup files for what runs where.

What the history settings do, tested

History is the cheapest productivity tool in the shell, and its settings are easy to get wrong. The variable HISTCONTROL decides what is saved: ignorespace skips lines that begin with a space, ignoredups skips a line identical to the previous one, and ignoreboth does both. Use the leading space for a command that contains a secret you do not want recorded, and test that it works in your shell before you rely on it. The run adds three entries by hand and then lists what was kept (Bash 5.2.37).

Shell
HISTCONTROL=ignoreboth
history -c
history -s "echo one"
history -s " echo secret"
history -s "echo one"
history | sed 's/^ *[0-9]* *//'
Text
echo one

Only one entry survived: the space-led line was dropped by ignorespace, and the second echo one was dropped as a duplicate of the line before it, once the first was recorded. If you want the history shared between terminals, add shopt -s histappend and PROMPT_COMMAND='history -a', which append each command to the file as it runs and not at exit. Then a crashed terminal loses nothing.

What startup costs, measured

Every line in your startup file runs each time a shell starts, and a slow tool initialization is paid on every new tab. Measure the cost before you add anything: time bash -i -c exit starts an interactive shell, runs the startup files and leaves. As a test of the method, a startup file that only sleeps for 0.3 seconds, run with the interactive flag, was compared with a shell started without any startup file.

Shell
time bash --rcfile slowrc -i -c exit
time bash --norc -i -c exit
Text
slow rc: 0.30s
no rc: 0.001s

The bare shell starts in about a millisecond. All the rest of what you wait for is your own configuration, so a prompt that takes a quarter of a second to appear has a quarter second of startup commands. Version managers, cloud CLIs' completion scripts and prompt frameworks are the usual cost. Defer them: load completion on first use, and initialize a version manager with its lazy mode. Check the time again after each change. A startup under 100 milliseconds feels instant, and over 300 starts to be noticed.

Prompts that cost a process

A prompt that runs git status on every redraw stalls in a large repository, since the command may take a second. If your prompt shows the branch, use a fast path: read .git/HEAD directly, or use the shell's built-in __git_ps1 helper with its status flags turned off, which reads files instead of walking the tree. Prompt frameworks such as starship compile to a fast binary and cache work, and still run once per prompt, so measure the delay with a large project open. The setting that matters is a timeout: configure the prompt to give up after a short time and show nothing rather than make you wait.

Limits

This is Bash-centric. Zsh and fish have their own equivalents and more built-in features. Treat the list as a base, not a destination: change one thing at a time and keep what you notice you miss. The tools are documented at fzf and Starship, and the readline syntax in the Readline user manual.

Taggedterminal
Share

Keep reading

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.