Skip to content

Instantly share code, notes, and snippets.

@ntamvl
Last active May 6, 2019 01:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ntamvl/c657ef61843baf61a9cc1f66cbaab317 to your computer and use it in GitHub Desktop.
Save ntamvl/c657ef61843baf61a9cc1f66cbaab317 to your computer and use it in GitHub Desktop.
OS X Terminal color prompt

OS X Terminal color prompt

Update .bash_profile with content:

export CLICOLOR=1
export PS1="\[\e[36m\]\w\[\e[0m\]$ "
alias ll='ls -GFhl' dir='ls -GFhl'
alias start=open
printf "\033]0;`date "+%a %d %b %Y %I:%M %p"`\007"
alias title='printf "\033]0;%s\007"'

Line 2 used to read "\e[0;36m\w$ \e[m" which is correct for other UNIX distributions but not OSX. In OSX the format is:

\[\e[36m\] PROMPT \[\e[0m\]

The first \[\e[36m\] turns on the color (cyan in this case), and the closing \[\e[0m\] turns it off. \e is just shorthand for the ASCII escape \033. You can also use the opening format \[\e[36;40m\] to set the background (cyan on white in this case).

Color Foreground Background
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Purple 35 45
Cyan 36 46
White 37 47

Check the bash man page, under the PROMPTING header for options for the PROMPT itself. Here's an excerpt (mine is just \w):

\d the date in "Weekday Month Date" format (e.g., "Tue May 26")
\h the hostname up to the first '.'
\H the hostname
\j the number of jobs currently managed by the shell
\l the basename of the shell's terminal device name
\s the name of the shell, the basename of $0 (the portion following the final slash)
\t the current time in 24-hour HH:MM:SS format
\T the current time in 12-hour HH:MM:SS format
\@ the current time in 12-hour am/pm format
\A the current time in 24-hour HH:MM format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patch level (e.g., 2.00.0)
\w the current working directory, with $HOME abbreviated with a tilde
\W the basename of the current working directory, with $HOME abbreviated with a tilde
! the history number of this command
# the command number of this command

My .bash_profile file

parse_git_branch() {
    # git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/'
}

# export PS1="\u@\h \[\033[32m\]\w - \$(parse_git_branch)\[\033[00m\] $ "
# export PS1="\w \$(parse_git_branch)\[\033[00m\] \$ "

# PS1='\n\[\033[0;35m\]\u\[\033[0;32m\]\w\[\033[0m\]$(__git_ps1)\n\$\[\033[0m\] '
# PS1='\[\033[0;35m\]\u\[\033[0;32m\]\w\[\033[0m\]$(__git_ps1)\n\$\[\033[0m\] '
# PS1='\[\033[0;34m\]\u@\h:\[\033[0;32m\]\W\[\033[0m\]$(__git_ps1) \$\[\033[0m\] '
# PS1='\[\033[0;34m\]\u@\h:\[\033[0;32m\]\W\[\033[0m\]$(parse_git_branch) \$\[\033[0m\] '

PS1='\[\033[0;34m\]\u@\h:\[\033[0;32m\]\W\[\033[0m\]$(parse_git_branch) \$\[\033[0m\] '

# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'

# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad

source: http://mybyways.com/blog/os-x-terminal-color-prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment