My Mac Terminal configuration

Mac Terminal is the Non Plus Ultra. Let me share my configuration, in particular I want to remember that font! R.I.P. Steve.

Mac

Appearance

Ok, let me get this straight: I use the Pro terminal profile. I always loved transparency effect in terminals.

Then I want a nice monospace font, possibly with ligatures. Go for FiraCode by tonsky. Font size, of course, is up to you: mine is 14 pt. Turn on Antialias text.

Another default configuration that I suggest to change is:

I often use CTRL D to close the shell, and I mean it so no confirmation is required.

Latest bash

Bash version provided by default on a Mac, at the time of this writing (with Mojave) is still 3.2. Let’s install latest! With brew do

brew install bash

Edit /etc/shells and add this line

/usr/local/bin/bash

For instance you can do something like

sudo echo /usr/local/bin/bash >> /etc/shells

Now set it as you default shell

chsh -s /usr/local/bin/bash $USER

Now quit Terminal and re-open it! Check if all ok?

echo $BASH_VERSION

Git Aware Prompt

Thanks to jimeh/git-aware-prompt you can

Display current Git branch name in your terminal prompt when in a Git working directory.

Install with the following commands

mkdir -p ~/.bash
cd ~/.bash
git clone git://github.com/jimeh/git-aware-prompt.git

Then configure it adding to your .bash_profile

export GITAWAREPROMPT=~/.bash/git-aware-prompt
source "${GITAWAREPROMPT}/main.sh"
export PS1="\u@\h \[$txtgrn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "

Aliases

Cannot live without these aliases

alias vi='nvim '

alias ls='ls -G'
alias ',,'='cd .. && pwd'
alias ','='ls -Galrth'

alias ga='git add .'
alias gd='git diff'
alias gc='git commit '
alias gl='git log --graph'
alias gpl='git pull '
alias gps='git push '
alias gs='git status'

alias ns='npm start'
alias nt='npm test'

Run also the following commands to set git aliases:

# Modify previous commit
git config --global alias.amend "commit -a --amend"
# List files with merge conflicts
git config --global alias.conflicts "diff --name-only --diff-filter=U"
# Reset previous commit, but keep all the changes from that commit in the working directory.
git config --global alias.undo "reset HEAD~1 --mixed"

Auto completion

Create a ~/.bash/completion folder and copy there files npm and git-completion.bash then add these lines to your .bash_profile.

source ~/.bash/completion/npm
source ~/.bash/completion/git-completion.bash

Locale

This tip can prevent many issues, add this to your .bash_profile to specify a locale or change it accordingly.

export LC_ALL=en_US.UTF-8

Other tips

Switch language shortcut

I often need to switch language since the US keyboard is the best layout in my opinion for programming, so it is useful to have a shortcut. Go to System Preferences > Keyboard > Input Sources and flag Select the previous input source.

switch language shortcut

This is a good solution if you needd to switch on two languages, in my case US an IT: the shortcut CTRL SPACE will do the trick.

Screen recording

When I discover it I said:

Yes, I ❤ Mac!

On Mojave you have a native screen recorder, invoke it with COMMAND SHIFT 5. It also manage screeshots.

Map Caps Lock to Escape

As a Vim user I cannot resist to Map Caps Lock to Escape. Open System Preferences > Keyboard, click on Modifier Keys. Then choose to map Caps Lock to Escape.

map caps lock to escake