Opinionated Terminal Essentials
I recently switched to the new M2 MacBook and as a common ritual, I have to set it up from scratch. My old MacBook that mounted an Intel i9 is in the corner crying at 80ΒΊC but it will be fine.
If you want to follow along with me, you can find all my dotfiles on my GitHub.
I spend 99% of my time in the terminal so as you can imagine I want it to feel fast and look good. The first thing that I usually setup is oh-my-zsh, it’s as easy as running this one-liner in the terminal
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
This is going to give your terminal a clean look with just the bare minimum
stuff that you actually need to see up-front. Next up is syntax-highlighting and
suggestions. These are super useful especially if you don’t want to type 50
chars commands every time. The plugins that I use are
zsh-syntax-highlighting,
zsh-autosuggestions,
zsh-completions. zsh has a
special folder in which you must put your plugins, and that folder is
.oh-my-zsh/custom/plugins
, and this is exactly where I put the three plugins
above
ZSH_CUSTOM=$HOME/.oh-my-zsh/custom
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions.git $ZSH_CUSTOM/plugins/zsh-completions
At this point zsh has almost reached perfection for what I need, as soon as you type something it’s going to show a dimmed suggestion based on your previous commands.
Another must-have tool is Homebrew. I have a script that is going to install pretty much every app, font and binary that I need on my new machine. This is super convenient because you just need to run a one-liner and when it finishes you’re going to have EVERYTHING that I usually install on every Mac that I have, without the need to visit 100 different websites, clicking a thousand different hyperlinks to download every application or binary that I use day-to-day.
#!/usr/bin/env bash
# Check for Homebrew
# Install if not present
if test ! $(which brew); then
echo "Installing Homebrew πΊ..."
echo | /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
tools=(
git
node
go
rust
openjdk
)
rust_bins=(
# a better `cat`
bat
# a better `ls`
exa
fd
# a better `diff`
git-delta
procs
tokei
ripgrep
)
other_bin=(
fzf
htop
jq
tree
tmux
wget
tldr
aria2
ack
grpcurl
)
gnu_tools=(
coreutils
moreutils
findutils
gnu-indent
gnu-getopt
gnu-sed
gnu-tar
gnutls
gawk
grep
stow
flex
bison
)
fonts=(
font-jetbrains-mono
font-fira-mono
font-fira-code
font-fira-mono-nerd-font
)
apps=(
alacritty
discord
jetbrains-toolbox
spotify
telegram
firefox
visual-studio-code
bartender
alfred
cyberduck
vlc
appcleaner
tor-browser
docker
sf-symbols
keka
transmission
)
brew install ${tools[@]}
brew install ${gnu_tools[@]}
brew install ${rust_bins[@]}
brew install ${other_bin[@]}
brew tap homebrew/cask-fonts
brew install --cask ${fonts[@]}
brew install --cask --appdir="/Applications" ${apps[@]}
brew cleanup
Homebrew takes a little bit of time at first to sync and install all the dependencies but it’s a great tool that everyone should have on their machine, I also use it on Linux and it’s super useful there too. Also, the script is pretty concise and readable, I just create a couple of arrays to better see what I want to install and expand those in the installation commands at the bottom.
If you read all the stuff that I installed with Homebrew you certainly noticed that I installed Alacritty, which is a super cool and fast terminal emulator (written is Rust, it’s a trend to point this out π ). Ditch the default terminal app, it’s crap.
I would like to point out just a thing I have going on with Alacritty, you can find the entire alacritty.yml config file on my GitHub.
shell:
program: /opt/homebrew/bin/tmux
args:
- new-session
- -A
- -D
- -s
- main
Hmmm, I canβt seem to find that folder on my system
Oh, forgot to tell that if you
are not using a M1/2 Mac then your homebrew folder is going to be /usr/local/
and not /opt/homebrew/
. Either way, if you want to be sure about it you can
just run brew --prefix
and it will output the correct folder under which brew
has been installed.
Cool! Indeed Iβm on an old Intel Mac and you are correct
With this you are basically telling Alacritty to open a tmux
session each time
you open the terminal emulator app, this way you don’t have to run it yourself
every single time you boot up your system.
At this point I’m almost done, I just need my config files in the right place. I
usually put all my config files in $HOME/.config
, and every binary that does
not parse config files in that folder does not deserve to be installed. Also, I
manage all my dotfiles with this little trick. I have
different branches for different systems, but for the moment I’m just assuming
that everything is on the master
branch.
$ git init --bare $HOME/.cfg
$ alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
$ config config status.showUntrackedFiles no
$ config pull -u origin master
And magically all my dotfiles are cloned in the right place, nothing is broken and everything is versioned so that if I need to make some changes I can always keep track of them and sync them with my remote repository.
$ tree .config
.config
βββ alacritty
β βββ alacritty.yml
βββ htop
β βββ htoprc
βββ nvim
β βββ after
β β βββ ftplugin
β β β βββ asciidoc.lua
β β β βββ gitcommit.lua
β β β βββ markdown.lua
β β βββ plugin
β β βββ fugitive.lua
β β βββ lsp.lua
β β βββ lualine.lua
β β βββ telescope.lua
β β βββ treesitter.lua
β β βββ undotree.lua
β βββ init.lua
β βββ legacy.vim
β βββ lua
β β βββ nvimcmp.lua
β β βββ options.lua
β β βββ plugins.lua
β β βββ remap.lua
β βββ plugin
β βββ packer_compiled.lua
βββ tmux
βββ tmux.conf
This is all that I usually do when I have to setup a Mac from scratch (and Linux too), it’s the easiest and fastest way possible to do it. Is there anything better than running approximately 10 commands to setup your machine entirely?
Now I can sit back and enjoy my fresh, minimal and fast terminal.
Enjoyed the read?
If you enjoy my writing, please check out my Patreon patreon.com/mattrighetti and become my supporter. Sharing the article is also greatly appreciated.