-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
228 lines (191 loc) · 5.87 KB
/
bashrc
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
# .bashrc config file
# pescobar AT cipf DOT es
#
# "myprompt -l" or "myprompt -s" to show "long" or "short" path in the prompt
#
# unprivileged user shows blue prompt. root shows red prompt
#
# colored man pages - two different color schemes.
#
# improved bash_history to share same history in every shell and add date+time to every commmand in bash_history
#
if [ -e /etc/bashrc ]; then
. /etc/bashrc
fi
if [ -e /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
PATH=${PATH}:/usr/games:/usr/local/bin:/usr/local/sbin
export PATH
export EDITOR=vim
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
#print a fortune cookie
# requires fortune-mod , fortunes, fortunes-bofh-excuses packages
if [ -e /usr/games/fortune ]; then
if [ -z "$COLORTERM" ]; then
/usr/games/fortune bofh-excuses
else
echo -en "\033[0;36m"
/usr/games/fortune bofh-excuses
echo -en "\033[0;37m"
fi
fi
# ps aliases to see memory and cpu hogs - from http://www.billharlan.com/pub/papers/Debugging_GnuLinux.html
function psc {
ps --cols=1000 --sort='-%cpu,uid,pgid,ppid,pid' -e \
-o user,pid,ppid,pgid,stime,stat,wchan,time,pcpu,pmem,vsz,rss,sz,args |
sed 's/^/ /' | less
}
function psm {
ps --cols=1000 --sort='-vsz,uid,pgid,ppid,pid' -e \
-o user,pid,ppid,pgid,stime,stat,wchan,time,pcpu,pmem,vsz,rss,sz,args |
sed 's/^/ /' | less
}
# daily temp dir
# export TD="$HOME/temp/`date +'%Y-%m-%d'`"
# td(){
# td=$TD
# if [ ! -z "$1" ]; then
# td="$HOME/temp/`date -d "$1 days" +'%Y-%m-%d'`";
# fi
# mkdir -p $td; cd $td
# unset td
# }
function myprompt
{
local NONE='\[\033[0m\]'
local WHITE_1='\[\033[0;1m\]'
local BLACK='\[\033[0;30m\]'
local GRAY='\[\033[1;30m\]'
local RED='\[\033[0;31m\]'
local LIGHT_RED='\[\033[1;31m\]'
local GREEN='\[\033[0;32m\]'
local LIGHT_GREEN='\[\033[1;32m\]'
local BROWN='\[\033[0;33m\]'
local YELLOW='\[\033[1;33m\]'
local BLUE='\[\033[0;34m\]'
local LIGHT_BLUE='\[\033[1;34m\]'
local PURPLE='\[\033[0;35m\]'
local LIGHT_PURPLE='\[\033[1;35m\]'
local CYAN='\[\033[0;36m\]'
local LIGHT_CYAN='\[\033[0;1;36m\]'
local LIGHT_GRAY='\[\033[0;37m\]'
local WHITE='\[\033[1;37m\]'
local BRACE_COLOR=$NONE
local LBRACE=$BRACE_COLOR[$BRACE_COLOR
local RBRACE=$BRACE_COLOR]$BRACE_COLOR
local SYMBOL
local PWD="\W"
if [ `whoami` = root ]; then
#echo 'ROOT USER'
SYMBOL="#"
else
#echo 'NON-ROOT USER'
SYMBOL="\$"
fi
if [[ $1 = "-h" || $1 = "--help" || $1 = "-?" ]]; then
echo "USAGE:"
echo " myprompt [-s | -l]"
echo " "
echo "DESCRIPTION:"
echo " Format the PS1 prompt string to show full path or just local directory"
echo " "
echo " -s, --short"
echo " Default option shows the path as a truncated."
echo " "
echo " -l, --long"
echo " Show the full path in the prompt. Same as the pwd command"
echo " "
echo " -?, -h, --help"
echo " Display usage options"
echo " "
else
if [[ $1 = "--short" || $1 = "-s" ]]; then
PWD="\W"
fi
if [[ $1 = "--long" || $1 = "-l" ]]; then
PWD="\w"
fi
fi
## if load is high shows hostname in red
########################################
# I have dual-core. I get red prompt with load higher than 2
THRESHOLD_LOAD=200
ONE=$(uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\)/\1/" -e "s/ //g")
# Apparently, "scale" in bc doesn't apply to multiplication, but does
# apply to division.
ONEHUNDRED=$(echo -e "scale=0 \n $ONE/0.01 \nquit \n" | bc)
if [ $ONEHUNDRED -gt $THRESHOLD_LOAD ]
then
HOST_COLOUR=$YELLOW
else
HOST_COLOUR=$YELLOW
fi
# end load function
########################################
# if load function is removed we lose $HOSTCOLOUR so in PS1 we have to change $HOSTCOLOUR to $LIGHT_GREEN or $LIGHT_BLUE or something like that....
# root user > red prompt | unprivileged user > blue prompt
if [ `whoami` = root ]; then
PS1="$LBRACE\
$LIGHT_RED\u\
$RBRACE\
$LBRACE\
$HOST_COLOUR\h\
$RBRACE\
$LBRACE\
$LBUE$PWD\
$RBRACE\
$WHITE$SYMBOL$NONE "
else
PS1="$LBRACE\
$LIGHT_BLUE\u\
$RBRACE\
$LBRACE\
$HOST_COLOUR\h\
$RBRACE\
$LBRACE\
$LBUE$PWD\
$RBRACE\
$WHITE$SYMBOL$NONE "
fi
}
myprompt -l
# color man pages (red and green)
###########################################
#export LESS_TERMCAP_mb=$'\E[01;31m'
#export LESS_TERMCAP_md=$'\E[01;31m'
#export LESS_TERMCAP_me=$'\E[0m'
#export LESS_TERMCAP_se=$'\E[0m'
#export LESS_TERMCAP_so=$'\E[01;44;33m'
#export LESS_TERMCAP_ue=$'\E[0m'
#export LESS_TERMCAP_us=$'\E[01;32m'
###########################################
## color man pages (blue and green) - I prefer this for dark background
###########################################
export LESS_TERMCAP_mb=$'\E[00;36m'
export LESS_TERMCAP_md=$'\E[00;36m'
export LESS_TERMCAP_me=$'\E[0m'
export LESS_TERMCAP_se=$'\E[0m'
export LESS_TERMCAP_so=$'\E[00;33m'
export LESS_TERMCAP_ue=$'\E[0m'
export LESS_TERMCAP_us=$'\E[00;32m'
###########################################
# .bash_history
###########################################
#export HISTCONTROL=erasedups # no duplicate entries
export HISTSIZE=100000 # big big history
shopt -s histappend # append to history, don't overwrite it
HISTTIMEFORMAT="%m/%h - %H:%M:%S " # add date+time to commands in history
# Save and reload the history after each command finishes
# so we share same history on every shell
export PROMPT_COMMAND="history -a; history -r; $PROMPT_COMMAND"
#alias
###########################################
alias ll="ls -l -h --color=auto"
alias ls="ls --color=auto"
alias lt='ls -ltr'
alias grep='grep --color'
alias g='grep --color'