Hao Chen | 陈浩     Posts     About Me

Setup Your Ideal Macbook Terminal in 5 Minutes

Chen Hao posted on 19 Aug 2016

The default setting of the terminal on Macbook acutally is a bit ugly and difficult to use. As shown below:

raw terminal look

No much useful prompt message, awkward white background, and won’t even close the window after you hit exit.

So here below is my recipe to craft your ideal terminal. In less than 5 minutes, make your terminal environment awesome and consistent accross different devices.

1. Install bash-it

The defualt shell of macbook terminal is zsh, there is a project oh-my-zsh to customize your zsh. But I just prefer bash, the bash-it is my choise to make the easy customisation.

## install bash-it
git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it
~/.bash_it/install.sh

2. Change Your default Shell to Bash

Under the preference of your terminal, change the shell open with command to /bin/bash:

change default shell

Now you terminal has shifted from zsh to bash, let’s update the theme under bash-it. open ~/.bash_profile with an editor, find and change the following line

export BASH_IT_THEME='nwinkler'

I have did some change on the nwinkler theme to make the prompt more of my preference:

prompt style

If you like my setting, you can open the file ~/.bash_it/themes/nwinkler/nwinkler.theme.bash and replace the content with the following codes.

#!/bin/bash

PROMPT_END_CLEAN="${green}>${reset_color}"
PROMPT_END_DIRTY="${red}>${reset_color}"

function prompt_end() {
  echo -e "$PROMPT_END"
}

prompt_setter() {
  local exit_status=$?
  if [[ $exit_status -eq 0 ]]; then PROMPT_END=$PROMPT_END_CLEAN
    else PROMPT_END=$PROMPT_END_DIRTY
  fi
  # Save history
  history -a
  history -c
  history -r
  PS1="(\t) $(scm_char) [${cyan}\u${reset_color}@${green}\H${reset_color}] ${yellow}\w${reset_color}$(scm_prompt_info) ${reset_color}\n$(prompt_end) "
  PS2='> '
  PS4='+ '
}

PROMPT_COMMAND=prompt_setter

SCM_THEME_PROMPT_DIRTY=" ${bold_red}${normal}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}${normal}"
SCM_THEME_PROMPT_PREFIX=" ("
SCM_THEME_PROMPT_SUFFIX=")"
RVM_THEME_PROMPT_PREFIX=" ("
RVM_THEME_PROMPT_SUFFIX=")"

3. Setup Terminal Theme

For coding, I like white text with dark blue background, font of Monaco 12pt, vertial bar blink cursor in green color. I have wrapped them into my own theme - Solarized Dark ansi. And you can download from here

Under preference of terminal, goes to profiles, you can load the downloaded theme and set it as default.

load a new theme

Now you are all done, your terminal should look like this below, enjoy it now.

final terminal look

comments powered by Disqus