# Prompt Customizations # downside of using MSYS # LS_COLORS="di=01;36:" # export LS_COLORS # If not running interactively, don't do anything [ -z "$PS1" ] && return RED="\033[0;31m" YELLOW="\033[0;33m" GREEN="\033[0;32m" GRAY="\033[1;30m" EMPTY="\033[0;37m" LIGHTBLUE="\033[38;5;111m" LIGHTORANGE="\033[38;5;172m" LIGHTGREEN="\033[38;5;70m" LIGHTRED="\033[38;5;161m" LIGHTYELLOW="\033[38;5;229m" CONTINUE="\033[38;5;242m" DARKGRAY="\033[38;5;247m" colorize() { # $1 is foreground # $2 is background if [ $OSTYPE = 'msys' ]; then echo "\033[$2;$1m" else echo "$(tput setaf $1)$(tput setab $2)" fi } parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' } parse_git_tag () { git describe --tags 2> /dev/null } parse_git_branch_or_tag() { local OUT="$(parse_git_branch)" if [ "$OUT" == " ((no branch))" ]; then $OUT="($(parse_git_tag))" elif [ "$OUT" == " " ]; then $OUT="" fi echo "$OUT" } build_prompt_win(){ TIME="$(colorize 39 48)[$(date +%H:%M)]$(colorize 36 42)"; USER="$(colorize 39 42) \u@\h $(colorize 32 41)" GIT="$(colorize 39 42)$(parse_git_branch_or_tag) $(colorize 42 49)" DIR="$(colorize 33 49) \w" echo "$TIME$USER$GIT $DIR" } build_prompt_mac(){ TIME="$(colorize 15 33)[$(date +%H:%M)] $(colorize 33 34)"; USER="$(colorize 15 34) \u@\h $(colorize 34 124)" GIT="$(colorize 252 124) $(parse_git_branch_or_tag) $(colorize 124 0)" DIR="$(colorize 11 0) \w" echo "$TIME$USER$GIT $DIR" } # [hh:mm] username@host (git branch || svn revision) ~/working/directory # $ # [hh:mm] username@host (git branch || svn revision) ~/working/directory # $ # Pretty ugly hack for msys... need to figure out how to determine if my # console is 256 color capable if [ $OSTYPE = 'msys' ]; then PROMPT_COMMAND='PS1="$(build_prompt_win) \n$EMPTY\$ $GRAY" PS2="$CONTINUE> "' else PROMPT_COMMAND='PS1="$(build_prompt_mac) \n$EMPTY\$ $LIGHTGRAY" PS2="$CONTINUE> "' fi print_map(){ if [ $OSTYPE = 'msys' ]; then #Background for clbg in {40..47} {100..107} 49 ; do #Foreground for clfg in {30..37} {90..97} 39 ; do #Formatting for attr in 0 1 2 4 5 7 ; do #Print the result echo -en "\e[${attr};${clbg};${clfg}m ^[${attr};${clbg};${clfg}m \e[0m" done echo #Newline done done else for fgbg in 38 48 ; do #Foreground/Background for color in {0..256} ; do #Colors #Display the color echo -en "\033[${fgbg};5;${color}m ${color}\t\e[0m" #Display 10 colors per lines if [ $((($color + 1) % 10)) == 0 ] ; then echo #New line fi done echo #New line done fi } banner() { for i in {16..21} {23..27} {27..23} {21..16} ; do echo -en "\033[38;5;${i}m#" ; done ; echo echo -e "$LIGHTBLUE $1" for i in {16..21} {23..27} {27..23} {21..16} ; do echo -en "\033[38;5;${i}m#" ; done ; echo }