Skip to content

Instantly share code, notes, and snippets.

@frne
Last active May 7, 2021 17:06
Show Gist options
  • Save frne/8315313 to your computer and use it in GitHub Desktop.
Save frne/8315313 to your computer and use it in GitHub Desktop.
Fancy Colors for (OSX-) Bash

Fancy Colors for (OSX-) Bash

Fancy console screenshot

Prerequisites

Git contrib-scripts and grc

Run commands in install.sh

Usage

Copy and adapt .bash_profile

Note

This config should work on every OS/distro with a bash console. The configuration file name is maybe ~/.bashrc or ~/.profile.

Tested with:

  • Debian Squeeze
  • Debian Wheezy
  • OSX 10.6
  • OSX 10.7
  • OSX 10.8

License

The MIT License (MIT)

Copyright (c) 2013 Frank Neff

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

########################################
# Fancy Colors for (OSX-) Bash #
# #
# https://gist.github.com/frne/8315313 #
# #
# Licensed under MIT #
# http://opensource.org/licenses/MIT #
########################################
# Source dependencies (git contrib)
if [ -f ~/.git-prompt.sh ]; then
source ~/.git-prompt.sh
fi
if [ -f ~/.git-completion.sh ]; then
source ~/.git-completion.sh
fi
# Enables color in the terminal bash shell export
export CLICOLOR=1
# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
# Sets up the color scheme for list export
export LSCOLORS=GxFxCxDxBxegedabagaced
__has_parent_dir () {
# Utility function so we can test for things like .git/.hg without firing up a
# separate process
test -d "$1" && return 0;
current="."
while [ ! "$current" -ef "$current/.." ]; do
if [ -d "$current/$1" ]; then
return 0;
fi
current="$current/..";
done
return 1;
}
__vcs_name() {
if [ -d .svn ]; then
echo "-[svn]";
elif __has_parent_dir ".git"; then
echo "-[$(__git_ps1 'git %s')]";
elif __has_parent_dir ".hg"; then
echo "-[hg $(hg branch)]";
fi
}
black=$(tput -Txterm setaf 0)
red=$(tput -Txterm setaf 1)
green=$(tput -Txterm setaf 2)
yellow=$(tput -Txterm setaf 3)
dk_blue=$(tput -Txterm setaf 4)
pink=$(tput -Txterm setaf 5)
lt_blue=$(tput -Txterm setaf 6)
bold=$(tput -Txterm bold)
reset=$(tput -Txterm sgr0)
# Nicely formatted terminal prompt
export PS1='\n\[$bold\]\[$black\][\[$dk_blue\]\@\[$black\]]-[\[$green\]\u\[$yellow\]@\[$green\]\h\[$black\]]-[\[$pink\]\w\[$black\]]\[\033[0;33m\]$(__vcs_name) \[\033[00m\]\[$reset\]\n\[$reset\]\$ '
export TERM=xterm-color
#use grc colors
if [ -f "`brew --prefix grc`/etc/grc.bashrc" ]; then
source "`brew --prefix grc`/etc/grc.bashrc"
fi
#use aliases
if [ -f ~/.bash_aliases ]; then
source ~/.bash_aliases
fi
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
########################################
# Fancy Colors for (OSX-) Bash #
# #
# https://gist.github.com/frne/8315313 #
# #
# Licensed under MIT #
# http://opensource.org/licenses/MIT #
########################################
# THis installer only works for OSX.
# Try your linux package manager like yum or apt to install grc
# EXAMPLE: apt-get install grc
brew install grc
# get git prompt and autocompletion
curl -o ~/.git-prompt.sh https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh
curl -o ~/.git-completion.sh https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
# install new profile
cd ~
mv .bash_profile .bash_profile.bak
wget https://gist.github.com/frne/8315313/raw/.bash_profile
source ~/.bash_profile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment