Skip to content

Instantly share code, notes, and snippets.

@kloudsamurai
Created May 4, 2019 23:30
Show Gist options
  • Save kloudsamurai/3e6b29127553bebb0a7b309d8328c615 to your computer and use it in GitHub Desktop.
Save kloudsamurai/3e6b29127553bebb0a7b309d8328c615 to your computer and use it in GitHub Desktop.
bash_profile
# function to test for parent directories
__has_parent_dir () {
test -d "$1" && return 0;
current="."
while [ ! "$current" -ef "$current/.." ]; do
if [ -d "$current/$1" ]; then
return 0;
fi
current="$current/..";
done
return 1;
}
# print the git info for a directory
__git_branch() {
if __has_parent_dir ".git"; then
echo "-[$(git rev-parse --abbrev-ref HEAD)]";
fi
}
# print the directory name
# some custom logic to shorten certain paths for readability
__directory_name() {
directory="$(pwd)"
echo "$directory";
}
# print the host name or whatever you'd like to see there
# in my case i'm using a short abbreviation as my hostname is long and ugly
__hostname() {
echo "pegasus";
}
# COLOR SCHEME
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\]$(__hostname) \[$black\]]-[\[$pink\]$(__directory_name) \[$black\]]\[\033[0;33m\]$(__git_branch) \[\033[00m\]\[$reset\]\n\[$reset\]\$ '
# grep colors
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;35;40'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment