Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tput color definitions for windows git shell

I'm trying to customize my git shell and I found this very interesting article but as you can see it use tput to set color definitions and I can't make it work on windows because tput wasn't native to windows, are there any alternatives to do th

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
LIME_YELLOW=$(tput setaf 190)
POWDER_BLUE=$(tput setaf 153)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
like image 827
Joey Hipolito Avatar asked Oct 31 '13 15:10

Joey Hipolito


1 Answers

you could use ANSI color escape codes, as in this script:

if tput setaf 1 &> /dev/null; then
    tput sgr0
    if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
      MAGENTA=$(tput setaf 9)
      ORANGE=$(tput setaf 172)
      GREEN=$(tput setaf 190)
      PURPLE=$(tput setaf 141)
      WHITE=$(tput setaf 256)
    else
      MAGENTA=$(tput setaf 5)
      ORANGE=$(tput setaf 4)
      GREEN=$(tput setaf 2)
      PURPLE=$(tput setaf 1)
      WHITE=$(tput setaf 7)
    fi
    BOLD=$(tput bold)
    RESET=$(tput sgr0)
else
    MAGENTA="\033[1;31m"
    ORANGE="\033[1;33m"
    GREEN="\033[1;32m"
    BLUE="\033[1;34m"
    PURPLE="\033[1;35m"
    WHITE="\033[1;37m"
    BOLD=""
    RESET="\033[m"
fi

You use it as:

PS1="\[$WHITE\]\[$BOLD\]\u\[$RESET\]@\[$WHITE\]\[$BOLD\]\h\[$RESET\]:\[\033[01;34m\]\[$BOLD\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" \[$RESET\]on \")\[$WHITE\]\[$BOLD\]\$(parse_git_branch)\[$RESET\]\n\$ \[$RESET\]"
like image 138
VonC Avatar answered Nov 09 '22 04:11

VonC