-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbsl_setter.sh
82 lines (70 loc) · 2.03 KB
/
bsl_setter.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
79
80
81
82
# displays only the last 25 characters of pwd
bsl_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 name of the git branch in the current directory
bsl_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"
fi
}
# revision of the svn repo in the current directory
bsl_set_svn_rev() {
unset SVN_REV
local rev=`svn info 2> /dev/null | grep "Revision" | sed 's/Revision: \(.*\)/r\1 /'`;
if test $rev
then
SVN_REV="${EMG}svn:${NONE}$rev"
fi
}
# the name of the activated virtual env
bsl_set_app_env_base() {
unset APP_ENV_BASE
local venv=`basename "$APP_ENV"`
if test $venv
then
APP_ENV_BASE="${EMG}env:${NONE}$venv "
fi
}
bsl_set_ruby_version() {
unset CURRENT_RVM_RUBY_VERSION
CURRENT_RVM_RUBY_VERSION="${EMG}rvm: ${NONE}$(~/.rvm/bin/rvm-prompt)"
}
bsl_set_status_line() {
local lines=`tput lines`
tput sc
non_scroll_line=$(($lines - 1))
scroll_region="0 $(($lines - 2))"
tput csr $scroll_region
# Clear out the status line
tput cup $non_scroll_line 0
printf "%${COLUMNS}s"
tput rc
# Reprint the status line
tput cup $non_scroll_line 0
echo -en "${EMB}[${NONE}${NEW_PWD}${EMB}] ${GIT_BRANCH}${SVN_REV}${CURRENT_RVM_RUBY_VERSION} ${APP_ENV_BASE}"
tput rc
}
bsl_update_status_line() {
bsl_set_new_pwd
bsl_set_git_branch
bsl_set_svn_rev
bsl_set_ruby_version
bsl_set_app_env_base
bsl_set_status_line
}