-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile
98 lines (83 loc) · 2.2 KB
/
profile
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
#### PS1 customization ####
NONE="\[\033[0m\]" # unsets color to term fg color
# regular colors
K="\[\033[0;30m\]" # black
R="\[\033[0;31m\]" # red
G="\[\033[0;32m\]" # green
Y="\[\033[0;33m\]" # yellow
B="\[\033[0;34m\]" # blue
M="\[\033[0;35m\]" # magenta
C="\[\033[0;36m\]" # cyan
W="\[\033[0;37m\]" # white
# emphasized (bolded) colors
EMK="\[\033[1;30m\]"
EMR="\[\033[1;31m\]"
EMG="\[\033[1;32m\]"
EMY="\[\033[1;33m\]"
EMB="\[\033[1;34m\]"
EMM="\[\033[1;35m\]"
EMC="\[\033[1;36m\]"
EMW="\[\033[1;37m\]"
# background colors
BGK="\[\033[40m\]"
BGR="\[\033[41m\]"
BGG="\[\033[42m\]"
BGY="\[\033[43m\]"
BGB="\[\033[44m\]"
BGM="\[\033[45m\]"
BGC="\[\033[46m\]"
BGW="\[\033[47m\]"
# displays only the last 25 characters of pwd
set_new_pwd() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
}
# the dirty status of the git repository
parse_git_dirty() {
git diff --quiet || echo "´"
}
# the name of the git branch in the current directory
set_git_branch() {
unset GIT_BRANCH
local branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`;
if test $branch
then
GIT_BRANCH="${EMG}git:${NONE}$branch${EMR}$(parse_git_dirty) "
fi
}
# the name of the activated virtual env
set_virtual_env_base() {
unset VIRTUAL_ENV_BASE
local venv=`basename "$VIRTUAL_ENV"`
if test $venv
then
VIRTUAL_ENV_BASE="${EMG}env:${NONE}$venv "
fi
}
update_prompt() {
set_new_pwd
set_git_branch
set_virtual_env_base
PS1="${EMB}[${NONE}$(id -un)@${EMM}$(hostname) ${NONE}${NEW_PWD}${EMB}] ${GIT_BRANCH}${VIRTUAL_ENV_BASE}${B}\$ ${NONE}"
}
PROMPT_COMMAND=update_prompt
# Poor man's pipe :(
function subdiff()
{
#"$@" > ~/$$.diff
git diff > /tmp/$$.diff
subl /tmp/$$.diff &
sleep 1
rm /tmp/$$.diff
}