Terminal & Shell Setup for macOS
A well-configured terminal environment can significantly improve your productivity as a developer. This guide covers setting up and customizing your macOS terminal and shell.
Recommended Terminal Emulator
While macOS comes with a default Terminal app, we recommend using iTerm2 for its additional features:
brew install --cask iterm2
Shell Options
macOS comes with several shells, but these are the most popular:
Zsh (Default since macOS Catalina)
Zsh is now the default shell in macOS. To enhance it, install Oh My Zsh:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Fish Shell
Fish offers great features out of the box:
brew install fish
# To make fish your default shell
echo $(which fish) | sudo tee -a /etc/shells
chsh -s $(which fish)
Shell Frameworks & Plugins
For Zsh
- Oh My Zsh Plugins
Edit your ~/.zshrc
file to enable plugins:
plugins=(git docker npm macos brew)
- Powerlevel10k Theme
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
Then set ZSH_THEME="powerlevel10k/powerlevel10k"
in your ~/.zshrc
.
- Zsh Syntax Highlighting
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
Add zsh-syntax-highlighting
to your plugins list in ~/.zshrc
.
- Zsh Autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Add zsh-autosuggestions
to your plugins list in ~/.zshrc
.
Essential Terminal Utilities
# A modern alternative to 'ls'
brew install exa
# A modern alternative to 'cat'
brew install bat
# Fuzzy finder
brew install fzf
$(brew --prefix)/opt/fzf/install
# Directory navigation
brew install autojump
Configuring Your Shell
Add these to your ~/.zshrc
or equivalent:
# Aliases
alias ls="exa --icons --group-directories-first"
alias ll="exa -l -g --icons --group-directories-first"
alias la="exa -la --icons --group-directories-first"
alias cat="bat"
alias grep="grep --color=auto"
# Environment Variables
export EDITOR="code -w"
export PATH="$HOME/.local/bin:$PATH"
Font Installation
Programming fonts with ligatures can improve your coding experience:
brew tap homebrew/cask-fonts
brew install --cask font-fira-code
brew install --cask font-jetbrains-mono
brew install --cask font-hack-nerd-font
Then configure iTerm2 to use your preferred font.
iTerm2 Customization
- Color Schemes: Import themes like Dracula (opens in a new tab) or Solarized (opens in a new tab)
- Key Mappings: Configure Option+Left/Right to jump between words
- Split Panes: Use Cmd+D for vertical split and Cmd+Shift+D for horizontal split
Terminal Multiplexers
For managing multiple terminal sessions, consider using:
# Install tmux
brew install tmux
# Create a basic config
cat << EOF > ~/.tmux.conf
# Improve colors
set -g default-terminal "screen-256color"
# Set scrollback buffer to 10000
set -g history-limit 10000
# Enable mouse mode
set -g mouse on
# Don't rename windows automatically
set-option -g allow-rename off
EOF
Basic tmux Commands
Command | Description |
---|---|
tmux new -s name | Create a new session named "name" |
tmux attach -t name | Attach to session "name" |
tmux ls | List sessions |
Ctrl+b d | Detach from current session |
Ctrl+b c | Create a new window |
Ctrl+b , | Rename the current window |
Ctrl+b n | Move to the next window |
Ctrl+b p | Move to the previous window |
Ctrl+b % | Split pane vertically |
Ctrl+b " | Split pane horizontally |
Remember to reload your shell configuration after making changes:
source ~/.zshrc # For Zsh