Skip to content

Instantly share code, notes, and snippets.

@vinicius5581
Created November 10, 2016 19:17
Show Gist options
  • Save vinicius5581/7ef7cb29832905d3b9f3d52ede09964f to your computer and use it in GitHub Desktop.
Save vinicius5581/7ef7cb29832905d3b9f3d52ede09964f to your computer and use it in GitHub Desktop.
My personal .bashrc
#PS1="$(tput setaf 166)\t - $(tput setaf 166)\u$(tput setaf 228)@\h $(tput setaf 71)\W -> $(tput sgr0)";
orange=$(tput setaf 166);
yellow=$(tput setaf 228);
green=$(tput setaf 71);
white=$(tput setaf 15);
bold=$(tput bold);
reset=$(tput sgr0);
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_GREEN="\033[0;32m"
COLOR_OCHRE="\033[38;5;95m"
COLOR_BLUE="\033[0;34m"
COLOR_WHITE="\033[0;37m"
COLOR_RESET="\033[0m"
function git_color {
local git_status="$(git status 2> /dev/null)"
if [[ $git_status =~ "working directory clean" ]]; then
echo -e $COLOR_RED
elif [[ $git_status =~ "Your branch is ahead of" ]]; then
echo -e $COLOR_YELLOW
elif [[ $git_status =~ "nothing to commit" ]]; then
echo -e $COLOR_GREEN
else
echo -e $COLOR_OCHRE;
fi
}
function git_branch {
local git_status="$(git status 2> /dev/null)"
local on_branch="On branch ([^${IFS}]*)"
local on_commit="HEAD detached at ([^${IFS}]*)"
if [[ $git_status =~ $on_branch ]]; then
local branch=${BASH_REMATCH[1]}
echo "($branch)"
elif [[ $git_status =~ $on_commit ]]; then
local commit=${BASH_REMATCH[1]}
echo "($commit)"
fi
}
PS1="\[${bold}\]\n";
PS1+="\[$(green)\]\t - "; # time
PS1+="\[${orange}\]\u"; # user
# PS1+="\[${yellow}\] at \h"; # hostname
PS1+="\[${white}\] in ";
PS1+="\[${green}\]\w"; # working directory
PS1+="\[\$(git_color)\]" # colors git status
PS1+="\[ \$(git_branch)\]" # prints current branch
PS1+="\n";
PS1+="\[${white}\]\$ \[$(reset)\]";
# PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
export PS1;
# Special Characters:
# \h the hostname up to the first .
# \n newline
# \s the name of the shell
# \t the current time in 24-hour format
# \u the username of the current user
# \w the current working directory
# \W the basename of the current working directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment