-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbashrc.sh
261 lines (212 loc) · 7.18 KB
/
bashrc.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env bash
# ~/.bashrc: executed by bash(1) for non-login shells.
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=200
HISTFILESIZE=400
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
# Bold
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
# Underline
UBlack='\e[4;30m' # Black
URed='\e[4;31m' # Red
UGreen='\e[4;32m' # Green
UYellow='\e[4;33m' # Yellow
UBlue='\e[4;34m' # Blue
UPurple='\e[4;35m' # Purple
UCyan='\e[4;36m' # Cyan
UWhite='\e[4;37m' # White
# Background
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
# High Intensity
IBlack='\e[0;90m' # Black
IRed='\e[0;91m' # Red
IGreen='\e[0;92m' # Green
IYellow='\e[0;93m' # Yellow
IBlue='\e[0;94m' # Blue
IPurple='\e[0;95m' # Purple
ICyan='\e[0;96m' # Cyan
IWhite='\e[0;97m' # White
# Bold High Intensity
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
# High Intensity backgrounds
On_IBlack='\e[0;100m' # Black
On_IRed='\e[0;101m' # Red
On_IGreen='\e[0;102m' # Green
On_IYellow='\e[0;103m' # Yellow
On_IBlue='\e[0;104m' # Blue
On_IPurple='\e[0;105m' # Purple
On_ICyan='\e[0;106m' # Cyan
On_IWhite='\e[0;107m' # White
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null
then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
#HOST_COLOR=${UGreen}
FQDN=`hostname -f`
function __makeTerminalTitle() {
local title=''
local CURRENT_DIR="${PWD/#$HOME/\~}"
if [ -n "${SSH_CONNECTION}" ]; then
title+="`hostname`:${CURRENT_DIR} [`whoami`@${FQDN}]"
else
title+="${CURRENT_DIR} [`whoami`]"
fi
echo -en '\033]2;'${title}'\007'
}
function __getMachineId() {
if [ -f /etc/machine-id ]; then
echo $((0x$(cat /etc/machine-id | head -c 15)))
else
echo $(( (${#HOSTNAME}+0x$(hostid))))
fi
}
function __makePS1() {
local EXIT="$?"
if [ ! -n "${HOST_COLOR}" ]; then
local H=$(__getMachineId)
HOST_COLOR=$(tput setaf $((H%5 + 2))) # foreground
#HOST_COLOR="\e[4$((H%5 + 2))m" # background
fi
PS1=''
PS1+="${debian_chroot:+($debian_chroot)}"
if [ -n "${VIRTUAL_ENV}" ]; then
local VENV=`basename $VIRTUAL_ENV`
PS1+="\[${BWhite}\](${VENV}) \[${Color_Off}\]" # show virtualenv if in it
fi
if [ ${USER} == root ]; then
PS1+="\[${Red}\]" # root
elif [ ${USER} != ${LOGNAME} ]; then
PS1+="\[${Blue}\]" # normal user
else
PS1+="\[${Green}\]" # normal user
fi
PS1+="\u\[${Color_Off}\]"
if [ -n "${SSH_CONNECTION}" ]; then
PS1+="\[${BWhite}\]@"
PS1+="\[${UWhite}${HOST_COLOR}\]\h\[${Color_Off}\]" # host displayed only if ssh connection
fi
PS1+=":\[${BYellow}\]\w" # working directory
# background jobs
local NO_JOBS=`jobs -p | wc -w`
if [ ${NO_JOBS} != 0 ]; then
PS1+=" \[${BGreen}\][j${NO_JOBS}]\[${Color_Off}\]"
fi
# screen sessions
local SCREEN_PATHS="/var/run/screens/S-`whoami` /var/run/screen/S-`whoami` /var/run/uscreens/S-`whoami`"
for screen_path in ${SCREEN_PATHS}; do
if [ -d ${screen_path} ]; then
SCREEN_JOBS=`ls ${screen_path} | wc -w`
if [ ${SCREEN_JOBS} != 0 ]; then
local current_screen="$(echo ${STY} | cut -d '.' -f 1)"
if [ -n "${current_screen}" ]; then
current_screen=":${current_screen}"
fi
PS1+=" \[${BGreen}\][s${SCREEN_JOBS}${current_screen}]\[${Color_Off}\]"
fi
break
fi
done
# git branch
if [ -x "`which git 2>&1`" ]; then
local branch="$(git name-rev --name-only HEAD 2>/dev/null)"
if [ -n "${branch}" ]; then
local git_status="$(git status --porcelain -b 2>/dev/null)"
local letters="$( echo "${git_status}" | grep --regexp=' \w ' | sed -e 's/^\s\?\(\w\)\s.*$/\1/' )"
local untracked="$( echo "${git_status}" | grep -F '?? ' | sed -e 's/^\?\(\?\)\s.*$/\1/' )"
local status_line="$( echo -e "${letters}\n${untracked}" | sort | uniq | tr -d '[:space:]' )"
PS1+=" \[${BBlue}\](${branch}"
if [ -n "${status_line}" ]; then
PS1+=" ${status_line}"
fi
PS1+=")\[${Color_Off}\]"
fi
fi
# exit code
if [ ${EXIT} != 0 ]; then
PS1+=" \[${BRed}\][!${EXIT}]\[${Color_Off}\]"
fi
PS1+=" \[${BPurple}\]\\$\[${Color_Off}\] " # prompt
__makeTerminalTitle
}
if [ "$color_prompt" = yes ]; then
PROMPT_COMMAND=__makePS1
PS2="\[${BPurple}\]>\[${Color_Off}\] " # continuation prompt
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
if [ -f ~/.bash_local ]; then
. ~/.bash_local
fi
umask 022
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi