Last active
June 7, 2019 04:42
-
-
Save rkhapov/c07ac4f5a8456a581f9b7821cf0b18b6 to your computer and use it in GitHub Desktop.
This is script for make bash prompt be similar to windows cmder style. Shows current git branch in dir in white if there is nothing to commit and working tree are clean. Better use with Twilight Dark color scheme
This file contains 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
# Pretty prompt in bash, cmder style | |
# better use with Twilight Dark terminal color scheme | |
GREEN=`tput setaf 2` | |
RED=`tput setaf 196` | |
GRAY=`tput setaf 239` | |
RESET=`tput sgr0` | |
BOLD=`tput bold` | |
WHITE=`tput setaf 15` | |
LAMBDA_8=`printf '\xce\xbb'` | |
function __get_git_status__ { | |
# check if git is available | |
which git 1>/dev/null 2>/dev/null | |
if [ "$?" != "0" ]; then | |
return | |
fi | |
# get current branch name | |
branch_name=`git branch 2>/dev/null | grep '^*' | colrm 1 2` | |
if [ "$branch_name" == "" ]; then | |
return | |
fi | |
# check if there are any changes in repository | |
wtc=`git status 2>/dev/null | grep 'nothing to commit, working tree clean'` | |
if [ "$wtc" == "" ]; then | |
printf "${RED}(${branch_name})" | |
else | |
printf "${WHITE}(${branch_name})" | |
fi | |
} | |
function __get_prompt_smb__ { | |
user=`whoami` | |
if [ "$user" == "root" ]; then | |
echo "#" | |
else | |
echo "$LAMBDA_8" | |
fi | |
} | |
export -f __get_git_status__ | |
export -f __get_prompt_smb__ | |
export PS1="\[${GREEN}\]\[${BOLD}\]\u@\h \w \$(__get_git_status__)\n\[${GRAY}\]\$(__get_prompt_smb__) \[${RESET}\]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment