Skip to content

Instantly share code, notes, and snippets.

@itotallyrock
Last active July 15, 2017 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itotallyrock/4668e0a9ef46648adcd14000959856e6 to your computer and use it in GitHub Desktop.
Save itotallyrock/4668e0a9ef46648adcd14000959856e6 to your computer and use it in GitHub Desktop.
My main modified .bashrc for custom ps1
#
# export __COLOR_DEFAULT="\e[39m"
# export __COLOR_RESET="$(tput sgr0)"
# export __COLOR_BLACK="\e[30m"
# export __COLOR_RED="\e[31m"
# export __COLOR_GREEN="\e[32m"
# export __COLOR_YELLOW="\e[33m"
# export __COLOR_BLUE="\e[34m"
# export __COLOR_MAGENTA="\e[35m"
# export __COLOR_CYAN="\e[36m"
# export __COLOR_LIGHT_GRAY="\e[37m"
# export __COLOR_DARK_GRAY="\e[90m"
# export __COLOR_LIGHT_RED="\e[91m"
# export __COLOR_LIGHT_GREEN="\e[92m"
# export __COLOR_LIGHT_YELLOW="\e[93m"
# export __COLOR_LIGHT_BLUE="\e[94m"
# export __COLOR_LIGHT_MAGENTA="\e[95m"
# export __COLOR_LIGHT_CYAN="\e[96m"
# export __COLOR_WHITE="\e[9"
get_256_foreground() {
echo ""
}
get_256_background() {
echo ""
}
# check if stdout is a terminal...
if test -t 1; then
# see if it supports colors...
ncolors=$(tput colors)
if test -n "$ncolors" && test $ncolors -ge 8; then
__color_reset="$(tput sgr0)"
__color_bold="$(tput bold)"
__color_underline="$(tput smul)"
__color_standout="$(tput smso)"
__color_normal="$(tput sgr0)"
__color_black="$(tput setaf 0)"
__color_red="$(tput setaf 1)"
__color_green="$(tput setaf 2)"
__color_yellow="$(tput setaf 3)"
__color_blue="$(tput setaf 4)"
__color_magenta="$(tput setaf 5)"
__color_cyan="$(tput setaf 6)"
__color_white="$(tput setaf 7)"
get_256_foreground() {
echo "\e[38;5;$1m"
}
get_256_background() {
echo "\e[48;5;$1m"
}
fi
fi
# Execute .bashrc in local directories
PROMPT_COMMAND+='if [[ "$bashrc" != "$PWD" && "$PWD" != "$HOME" && -e .bashrc ]]; then bashrc="$PWD"; . .bashrc; fi;'
parse_git_branch() {
## old method
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
## Newer but easily brok
# git rev-parse --abbrev-ref HEAD
echo $(__git_ps1 | sed 's/[() ]//g')
# ' reset bad syntax highlighting
}
parse_git_hash() {
if [[ $(git rev-parse --short HEAD 2>/dev/null) == "" ]]; then
echo "-------"
else
git rev-parse --short HEAD
fi
}
prompt_git_dirty() {
git diff --exit-code --quiet &>/dev/null
retval=$?
if [ $retval -ne 0 ]; then
echo -en "$(get_256_foreground 1)(*)"
fi
}
get_machine_user() {
if [[ -n $SSH_CONNECTION ]]; then
echo -en "${__color_green}\\u${__color_reset}@${__color_cyan}\\h${__color_reset}:"
else
if [[ $(whoami) != "Jeffrey" ]]; then
echo -en "${__color_green}\\u${__color_reset}:"
fi
fi
}
MOD1_PS1="\e[0;32m\u\e[0m@\e[1;36m\h\e[0m:\e[0;33m\w \e[0;36m$(parse_git_branch)\e[0m\n\$ "
set_ps1() {
if ! git ls-files >& /dev/null; then
PS1="${__color_reset}$(get_256_background 0)\t $(get_machine_user)${__color_yellow}\w${__color_reset} \
${__color_reset}\n\$ "
else
PS1="${__color_reset}$(get_machine_user)${__color_yellow}\w${__color_reset} \
$(get_256_foreground 28)$(parse_git_branch)${__color_reset} \
$(get_256_foreground 245)[$(get_256_foreground 221)$(parse_git_hash)$(get_256_foreground 245)]${__color_reset} \
$(prompt_git_dirty)${__color_reset}\n\$ "
fi
}
PROMPT_COMMAND+='set_ps1;';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment