-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.bash_beautify
132 lines (115 loc) · 2.96 KB
/
.bash_beautify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
#
# File: .bash_beautify
# Author: Chris Albrecht, @ChrisAlbrecht
#
# Provides color and bash prompt customizations to integrate with SVN and GIT.
export DULL=0
export BRIGHT=1
export FG_BLACK=30
export FG_RED=31
export FG_GREEN=32
export FG_YELLOW=33
export FG_BLUE=34
export FG_VIOLET=35
export FG_CYAN=36
export FG_WHITE=37
export FG_NULL=00
export BG_BLACK=40
export BG_RED=41
export BG_GREEN=42
export BG_YELLOW=43
export BG_BLUE=44
export BG_VIOLET=45
export BG_CYAN=46
export BG_WHITE=47
export BG_NULL=00
##
# ANSI Escape Commands
##
export ESC="\033"
export NORMAL="$ESC[m"
export RESET="$ESC[${DULL};${FG_WHITE};${BG_NULL}m"
##
# Shortcuts for Colored Text ( Bright and FG Only )
##
# DULL TEXT
export BLACK="$ESC[${DULL};${FG_BLACK}m"
export RED="$ESC[${DULL};${FG_RED}m"
export GREEN="$ESC[${DULL};${FG_GREEN}m"
export YELLOW="$ESC[${DULL};${FG_YELLOW}m"
export BLUE="$ESC[${DULL};${FG_BLUE}m"
export VIOLET="$ESC[${DULL};${FG_VIOLET}m"
export CYAN="$ESC[${DULL};${FG_CYAN}m"
export WHITE="$ESC[${DULL};${FG_WHITE}m"
# BRIGHT TEXT
export BRIGHT_BLACK="$ESC[${BRIGHT};${FG_BLACK}m"
export BRIGHT_RED="$ESC[${BRIGHT};${FG_RED}m"
export BRIGHT_GREEN="$ESC[${BRIGHT};${FG_GREEN}m"
export BRIGHT_YELLOW="$ESC[${BRIGHT};${FG_YELLOW}m"
export BRIGHT_BLUE="$ESC[${BRIGHT};${FG_BLUE}m"
export BRIGHT_VIOLET="$ESC[${BRIGHT};${FG_VIOLET}m"
export BRIGHT_CYAN="$ESC[${BRIGHT};${FG_CYAN}m"
export BRIGHT_WHITE="$ESC[${BRIGHT};${FG_WHITE}m"
# REV TEXT as an example
export REV_CYAN="$ESC[${DULL};${BG_WHITE};${BG_CYAN}m"
export REV_RED="$ESC[${DULL};${FG_YELLOW}; ${BG_RED}m"
##
# Parse the GIT and SVN branches we may be on
##
function vcs_branch {
local GIT=$(git_branch)
local SVN=$(svn_branch)
if [ -n "$GIT" ]; then
local BRANCH="${GREEN}$GIT${WHITE}"
fi
if [ -n "$SVN" ]; then
if [ -n "$GIT" ]; then
BRANCH="$BRANCH|${YELLOW}$SVN${WHITE}"
else
BRANCH="${YELLOW}$SVN${WHITE}"
fi
fi
if [ -n "$BRANCH" ]; then
echo -e "($BRANCH${WHITE})"
fi
}
##
# Get the current GIT branch
##
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
##
# Get the current SVN branch
##
function svn_branch {
if [ ! -d .svn ]; then
exit 1
fi
# Get the current URL of the SVN repo
URL=`svn info --xml | fgrep "<url>"`
# Strip the tags
URL=${URL/<url>/}
URL=${URL/<\/url>/}
# Find the branches directory
if [[ "$URL" == */trunk ]]; then
DIR=${URL//\/trunk*/}
fi
if [[ "$URL" == */tags/* ]]; then
DIR=${URL//\/tags*/}
fi
if [[ "$URL" == */branches/* ]]; then
DIR=${URL//\/branches*\/*/}
fi
DIR="$DIR/branches"
# Return the branch name
if [[ "$URL" == */trunk* ]]; then
echo 'trunk'
elif [[ "$URL" == */branches/* ]]; then
echo $URL | sed -e 's#^'"$DIR/"'##g' | sed -e 's#/.*$##g' | awk '{print ""$1"" }'
fi
}
# Set the prompt pattern
export PS1="${BRIGHT_CYAN}[${CYAN}\u${BRIGHT_WHITE}@${CYAN}\h${WHITE}\$(vcs_branch)${WHITE}: \w${BRIGHT_CYAN}]${NORMAL}\$ ${RESET}"