Created
February 1, 2014 12:22
-
-
Save saulopaiva/8751615 to your computer and use it in GitHub Desktop.
Configuração de bash
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
############################################################################################################## | |
# Configuração bash | |
# | |
# Adaptadas de: | |
# https://plus.google.com/u/0/114896277363762090056/posts/SiB4um66RtL | |
# http://pastebin.com/MzYSzLGy | |
############################################################################################################## | |
if [ -f /etc/bash_completion ]; then | |
source /etc/bash_completion | |
fi | |
bold=$(tput -Txterm bold) | |
reset=$(tput -Txterm sgr0) | |
black=$(tput -Txterm setaf 0) | |
white=$(tput -Txterm setaf 7) | |
yellow=$(tput -Txterm setaf 3) | |
green=$(tput -Txterm setaf 2) | |
red=$(tput -Txterm setaf 1) | |
lt_blue=$(tput -Txterm setaf 6) | |
__has_parent_dir () { | |
# Utility function so we can test for things like .git/.hg without firing up a separate process | |
test -d "$1" && return 0; | |
current="." | |
while [ ! "$current" -ef "$current/.." ]; do | |
if [ -d "$current/$1" ]; then | |
return 0; | |
fi | |
current="$current/.."; | |
done | |
return 1; | |
} | |
__vcs_name() { | |
if [ -d .svn ]; then | |
echo "$white($yellow svn $white)"; | |
elif __has_parent_dir ".git"; then | |
echo "$white($yellow$(__git_ps1 '%s')$(__git_state)$bold$white)"; | |
elif __has_parent_dir ".hg"; then | |
echo "$white($yellow$(hg branch)$white)" | |
fi | |
} | |
__git_state() { | |
local git_status= | |
local git_status_exit=255 | |
git_status=$(git -c color.status=false status --short --branch 2>/dev/null) | |
git_status_exit=$? | |
if [ $git_status_exit -eq 0 ] ; then | |
local bits='' | |
bits="${bits}$(__git_state_by_type "$git_status" '^ ?M' '±')" # modified files | |
bits="${bits}$(__git_state_by_type "$git_status" '^ ?\?' ' ?')" # untracked files | |
bits="${bits}$(__git_state_by_type "$git_status" '^ ?A' ' *')" # new/added files | |
bits="${bits}$(__git_state_by_type "$git_status" '^ ?R' ' >')" # renamed files | |
bits="${bits}$(__git_state_by_type "$git_status" '^ ?D' ' ⚡')" # deleted files | |
bits="${bits}$(__git_state_by_type "$git_status" ' \[ahead ' ' +')" # ahead of origin | |
local glutter='' | |
if [ -n "$bits" ] ; then | |
glutter="$reset$red|$reset" | |
fi | |
case "$TERM" in | |
*term | xterm-* | rxvt | screen | screen-*) | |
bits="$lt_blue$bold$bits$reset" | |
;; | |
esac | |
printf "%b" "${glutter}${bits}$reset" | |
fi | |
} | |
__git_state_by_type() { | |
local git_status=$1 #git_status | |
local exp=$2 #regex | |
local symbol=$3 #symbol | |
local ret | |
local count_files | |
count_files=$(echo -n "$git_status" | egrep -c "${exp}") | |
printf "$git_status" | egrep -q "${exp}" && ret="${symbol}${count_files}" | |
printf "%b" "${ret}" | |
} | |
PS1='\342\224\214\[$bold\]\[$black\] \[$green\]\u\[$black\]@\[$green\]\h\[$white\] \342\236\236 \[$lt_blue\]\w\[$black\] \[$yellow\]$(__vcs_name) \[\033[00m\]\[$reset\]\n\342\206\263\[$reset\] ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment