Out of the box, using the Terminal in macOS leaves much to be desired. The built-in application can feel inflexible and quite plain, while the default shell, Bash, lacks several handy tools that become indispensable once you’ve experienced them.
Let’s explore how to transform your terminal experience into something that’s not just functional but enjoyable.
Homebrew: The Missing Package Manager
Homebrew is the essential package manager for macOS. It fills a significant gap for developers, allowing you to easily install and manage software packages.
To get started, run this command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Note: This command should automatically install Xcode if it’s not already present. If it doesn’t, you can manually install it with:
sudo xcode-select --install
Handy Brew Commands
Once you have Homebrew installed, here are some commands that will serve you well:
brew doctor- A self-check tool; run it if you encounter issues.brew search SOMETHING- Searches for a package namedSOMETHING. However, checking online might yield quicker results.brew list --versions- Lists all installed packages and their versions.brew install git/brew uninstall git/brew upgrade git- Manage Git easily.brew update/brew upgrade- Updates apps or all packages, respectively.brew outdated- Displays available upgrades.
Installing Non-Open Source Software
Forget about dragging icons around to install applications. With Homebrew, you can use brew cask to install macOS apps seamlessly:
brew install --cask firefox
You can browse a comprehensive list of available casks. Notable applications available this way include:
iTerm2: A More Powerful Terminal
For a more robust and customizable terminal experience, consider using iTerm2. It’s lightweight, efficient, and offers features that can significantly enhance your workflow. You can install it with:
brew install --cask iterm2
The Z Shell: A Step Up from Bash
The Z shell (or Zsh) is built on top of Bash and brings additional features to the table. To make the most of it, you’ll want to use a plugin framework. One of the most popular is Oh My Zsh.
To get started, run:
brew install zsh
brew install wget
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
To ensure you’re using Zsh, check your shell with:
echo $0
If it doesn’t return -zsh, you can set Zsh as your default shell with:
chsh -s $(which zsh)
All your Zsh configuration lives in ~/.zshrc. After you make changes, don’t forget to load them with:
source ~/.zshrc
Auto Suggestions: A Game Changer
One of the standout features for frequent terminal users is the Zsh Auto Suggestions plugin. It provides context-aware auto-completion based on your command history, making your workflow far more efficient.
To install this plugin, run:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
Then add zsh-autosuggestions to your plugins list in ~/.zshrc.
Spaceship Theme: Enhance Your Prompt
For those looking to refine the aesthetic and functionality of their terminal, the Spaceship Prompt is an excellent addition. It offers a visually appealing layout that displays your current git branch, command status, and more.
To install Spaceship, run:
git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt"
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
Finally, set the theme in your .zshrc:
ZSH_THEME="spaceship"
Recommended .zshrc Configuration
Here’s a suggested configuration to help you get started with the Spaceship theme and other useful settings:
ZSH_THEME="spaceship"
SPACESHIP_USER_SHOW="false"
SPACESHIP_HOST_SHOW="false"
SPACESHIP_PHP_SHOW="false"
SPACESHIP_PROMPT_ADD_NEWLINE="true"
SPACESHIP_DIR_TRUNC_PREFIX=".../"
SPACESHIP_DIR_TRUNC_REPO="false"
For plugins, consider:
plugins=(git colorize pip python brew zsh-autosuggestions)
You might also want to add some convenient aliases to your .zshrc:
alias ls='ls --color=auto -lhapG' # Prettier output of ls, includes directory slashes
alias gs='git status'
alias gaa='git add --all'
alias gcm='git commit -m '
From here, feel free to add any other aliases that suit your workflow!
Conclusion
By adopting these tools and configurations, you’ll not only enhance your terminal experience but also streamline your workflow. Embrace the power of Homebrew, iTerm2, and Zsh, and watch your productivity soar. After all, a well-optimized environment is a crucial step towards effective development and efficient problem-solving. Happy coding!