-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdevelopers-prompt.sh
79 lines (69 loc) · 2.19 KB
/
developers-prompt.sh
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
# ~/.bashrc file
#
# https://github.com/irfan/developers-prompt
# http://irfandurmus.com/projetcs/developers-prompt
#
# it shows pretty good terminal prompt
# writed couple of years ago but committed in April of 2012
# It shorter your prompt text but also make the prompt more understandable!
#
# Just copy to your home directory as .bashrc to installation.
#
# !!!! Attendion !!!!
# If you already have the ~/.bashrc file please backup it before use this file
#
# Examples:
# /opt/local/etc : /opt/local/etc
# /opt/local/etc/openssl/misc : /opt/../openssl/misc
#
# In home directory:
# /Users/irfan : ~
# ~/projects/javascript/jquery-plugins : ~/projects/javascript/jquery-plugins $
# ~/projects/javascript/jquery-plugins/star-rating/min : ~/projects/../star-rating/min $
#
#
# If the directory into an svn or git project, the branch name going to add your prompt like that;
#
# ~/projects/javascript/jquery-plugins : ~/projects/javascript/jquery-plugins [master] $
# ~/projects/javascript/jquery-plugins/star-rating/min : ~/projects/../star-rating/min [trunk] $
#
SUFFIX=".git"
BRANCH=""
function GET_GIT_BRANCH ()
{
ARG=$1
if [ ! ${#ARG} -lt 4 ]; then
if [ ! -d "$ARG$SUFFIX" ]; then
BRANCH=""
ARG=`echo $ARG | sed -e "s|[^\/]*\/$||g"`
GET_GIT_BRANCH "$ARG"
else
CMD=`git branch | grep \* | sed -e "s|\* ||"`
BRANCH=" [$CMD]"
fi
fi
}
function GET_SVN_BRANCH () {
if [ -d ".svn" ]; then
BRANCH=" [`svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'`]"
fi
if [ ${#BRANCH} -lt 4 ]; then
BRANCH=""
fi
}
function pretty_prompt () {
_IFS=$IFS;
DIR=`pwd|sed -e "s|$HOME|~|"`;
IFS="/" && S=($DIR);
L=${#S[@]};
IFS=$_IFS;
if [ $L -gt 4 ]; then
DIR="${S[0]:0:1}/${S[1]}/../${S[$L-2]}/${S[$L-1]}";
fi
# set $BRANCH variable as git branch name
GET_GIT_BRANCH `pwd`"/"
# set $BRANCH variable as svn branch name
GET_SVN_BRANCH
}
PROMPT_COMMAND=pretty_prompt;
export PS1="\[\e[32;1m\]\$DIR\[\e[33;1m\]\$BRANCH\[\e[0m\]\[\e[32;1m\] \$ \[\e[0m\]\[\e[0m\]"