Created
April 30, 2019 02:10
-
-
Save kloudsamurai/26e3c7a115f72360d6907190ed79414d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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