forked from CedricGatay/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc
More file actions
328 lines (307 loc) · 10.8 KB
/
bashrc
File metadata and controls
328 lines (307 loc) · 10.8 KB
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
# Filename: custom_prompt.sh
# Maintainer: Dave Vehrs
# Last Modified: 12 Jul 2005 13:29:40 by Dave Vehrs
# Current Format: USER@HOST [dynamic section] { CURRENT DIRECTORY }$
# USER: (also sets the base color for the prompt)
# Red == Root(UID 0) Login shell (i.e. sudo bash)
# Light Red == Root(UID 0) Login shell (i.e. su -l or direct login)
# Yellow == Root(UID 0) priviledges in non-login shell (i.e. su)
# Brown == SU to user other than root(UID 0)
# Green == Normal user
# @:
# Light Red == http_proxy environmental variable undefined.
# Green == http_proxy environmental variable configured.
# HOST:
# Red == Insecure remote connection (unknown type)
# Yellow == Insecure remote connection (Telnet)
# Brown == Insecure remote connection (RSH)
# Cyan == Secure remote connection (i.e. SSH)
# Green == Local session
# DYNAMIC SECTION:
# (If count is zero for any of the following, it will not appear)
# [scr:#] ==== Number of detached screen sessions
# Yellow == 1-2
# Red == 3+
# [bg:#] ==== Number of backgrounded but still running jobs
# Yellow == 1-10
# Red == 11+
# [stp:#] ==== Number of stopped (backgrounded) jobs
# Yellow == 1-2
# Red == 3+
# CURRENT DIRECTORY: (truncated to 1/4 screen width)
# Red == Current user does not have write priviledges
# Green == Current user does have write priviledges
# NOTE:
# 1. Displays message on day change at midnight on the line above the
# prompt (Day changed to...).
# 2. Command is added to the history file each time you hit enter so its
# available to all shells.
# Configure Colors:
COLOR_WHITE='\033[1;37m'
COLOR_LIGHTGRAY='\033[0;37m'
COLOR_GRAY='\033[1;30m'
COLOR_BLACK='\033[0;30m'
COLOR_RED='\033[0;31m'
COLOR_LIGHTRED='\033[1;31m'
COLOR_GREEN='\033[1;32m'
COLOR_LIGHTGREEN='\033[1;32m'
COLOR_BROWN='\033[0;33m'
COLOR_YELLOW='\033[1;33m'
COLOR_BLUE='\033[0;34m'
COLOR_LIGHTBLUE='\033[1;34m'
COLOR_PURPLE='\033[0;35m'
COLOR_PINK='\033[1;35m'
COLOR_CYAN='\033[0;36m'
COLOR_LIGHTCYAN='\033[1;36m'
COLOR_DEFAULT='\033[0m'
#Dummy function to circumvent lack of git-completion
function __git_ps1 () {
echo -e "";
}
# Function to set prompt_command to.
function promptcmd () {
history -a
local SSH_FLAG=0
local TTY=$(tty | awk -F/dev/ '{print $2}')
if [[ ${TTY} ]]; then
local SESS_SRC=$(who | grep "$TTY " | awk '{print $6 }')
fi
# Titlebar
case ${TERM} in
screen* )
local TITLEBAR='\[\033k\w\033\134\]'
;;
xterm* )
local TITLEBAR='\[\033]0;\u@\h:\007\]'
;;
* )
local TITLEBAR=''
;;
esac
PS1="${TITLEBAR}"
# Test for day change.
if [ -z $DAY ] ; then
export DAY=$(date +%A)
else
local today=$(date +%A)
if [ "${DAY}" != "${today}" ]; then
PS1="${PS1}\n\[${COLOR_GREEN}\]Day changed to $(date '+%A, %d %B %Y').\n"
export DAY=$today
fi
fi
# User
if [ ${UID} -eq 0 ] ; then
if [ "${USER}" == "${LOGNAME}" ]; then
# if [[ ${SUDO_USER} ]]; then
# PS1="${PS1}\[${COLOR_RED}\]\u"
# else
PS1="${PS1}\[${COLOR_LIGHTRED}\]\u"
# fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]\u"
fi
else
if [ ${USER} == ${LOGNAME} ]; then
PS1="${PS1}\[${COLOR_GREEN}\]\u"
else
PS1="${PS1}\[${COLOR_BROWN}\]\u"
fi
fi
# HTTP Proxy var configured or not
# if [ -n "$http_proxy" ] ; then
# PS1="${PS1}\[${COLOR_GREEN}\]@"
# else
# PS1="${PS1}\[${COLOR_LIGHTRED}\]@"
# fi
PS1="${PS1}\[${COLOR_LIGHTGRAY}\]@"
# Host
if [[ ${SSH_CLIENT} ]] || [[ ${SSH2_CLIENT} ]]; then
SSH_FLAG=1
fi
if [ ${SSH_FLAG} -eq 1 ]; then
PS1="${PS1}\[${COLOR_LIGHTCYAN}\]\h"
elif [[ -n ${SESS_SRC} ]]; then
if [ "${SESS_SRC}" == "(:0.0)" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]local"
else
#local parent_process=`cat /proc/${PPID}/cmdline`
#if [[ "$parent_process" == "in.rlogind*" ]]; then
# PS1="${PS1}\[${COLOR_BROWN}\]\h "
#elif [[ "$parent_process" == "in.telnetd*" ]]; then
# PS1="${PS1}\[${COLOR_YELLOW}\]\h "
#else
PS1="${PS1}\[${COLOR_LIGHTRED}\]\h"
#fi
fi
elif [[ "${SESS_SRC}" == "" ]]; then
PS1="${PS1}\[${COLOR_GREEN}\]local"
else
PS1="${PS1}\[${COLOR_RED}\]\h"
fi
if [ -f /usr/bin/screen ]; then
# Detached Screen Sessions
local DTCHSCRN=$(screen -ls | grep -c Detach )
if [ ${DTCHSCRN} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\] [scr:${DTCHSCRN}] "
elif [ ${DTCHSCRN} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\] [scr:${DTCHSCRN}] "
fi
fi
# Backgrounded running jobs
local BKGJBS=$(jobs -r | wc -l )
if [ ${BKGJBS} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\] [bg:${BKGJBS}] "
elif [ ${BKGJBS} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\] [bg:${BKGJBS}] "
fi
# Stopped Jobs
local STPJBS=$(jobs -s | wc -l )
if [ ${STPJBS} -gt 2 ]; then
PS1="${PS1}\[${COLOR_RED}\] [stp:${STPJBS}] "
elif [ ${STPJBS} -gt 0 ]; then
PS1="${PS1}\[${COLOR_YELLOW}\] [stp:${STPJBS}] "
fi
# Bracket {
if [ ${UID} -eq 0 ]; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
PS1="${PS1}\[${COLOR_RED}\]"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]"
fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]"
fi
else
if [ "${USER}" == "${LOGNAME}" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]"
else
PS1="${PS1}\[${COLOR_BROWN}\]"
fi
fi
PS1="${PS1}:"
# Working directory
if [ -w "${PWD}" ]; then
PS1="${PS1}\[${COLOR_LIGHTBLUE}\]$(prompt_workingdir)"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]$(prompt_workingdir)"
fi
# Closing bracket } and $\#
if [ ${UID} -eq 0 ]; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
PS1="${PS1}\[${COLOR_RED}\]#"
else
PS1="${PS1}\[${COLOR_LIGHTRED}\]#"
fi
else
PS1="${PS1}\[${COLOR_YELLOW}\]#"
fi
else
if [ "${USER}" == "${LOGNAME}" ]; then
PS1="${PS1}\[${COLOR_GREEN}\]\$"
else
PS1="${PS1}\[${COLOR_BROWN}\]\$"
fi
fi
PS1="${PS1}\[${COLOR_DEFAULT}\] "
TIME=$(date +%H:%M)
PS1="\[${COLOR_LIGHTGRAY}\][${TIME}\[${COLOR_BROWN}\]$(__git_ps1 " > %s")\[${COLOR_LIGHTGRAY}\]]${PS1}"
}
# Trim working dir to 1/4 the screen width
function prompt_workingdir () {
# local pwdmaxlen=$(($COLUMNS/4))
local pwdmaxlen=25
local trunc_symbol="..."
if [ $BASHVER -lt 3 ]; then
newPWD=${PWD}
else
if [[ $PWD == $HOME* ]]; then
newPWD="~${PWD#$HOME}"
else
newPWD=${PWD}
fi
if [ ${#newPWD} -gt $pwdmaxlen ]; then
local pwdoffset=$(( ${#newPWD} - $pwdmaxlen + 3 ))
newPWD="${trunc_symbol}${newPWD:$pwdoffset:$pwdmaxlen}"
fi
fi
echo $newPWD
}
# Determine what prompt to display:
# 1. Display simple custom prompt for shell sessions started
# by script.
# 2. Display "bland" prompt for shell sessions within emacs or
# xemacs.
# 3 Display promptcmd for all other cases.
function load_prompt () {
# Get PIDs
#local parent_process=$(cat /proc/$PPID/cmdline | cut -d \. -f 1)
#local my_process=$(cat /proc/$$/cmdline | cut -d \. -f 1)
BASHVER=$(echo $BASH_VERSION | sed -r 's/([0-9]).*/\1/g')
if [ $BASHVER -lt 3 ]; then
PROMPT_COMMAND=""
PS1="\u@\h:\w\$ "
else
# if [[ $parent_process == script* ]]; then
# PROMPT_COMMAND=""
# PS1="\t - \# - \u@\H:\w\$ "
# elif [[ $parent_process == emacs* || $parent_process == xemacs* ]]; then
# PROMPT_COMMAND=""
# PS1="\u@\h:\w\$ "
# else
export DAY=$(date +%A)
PROMPT_COMMAND=promptcmd
# fi
fi
export PS1 PROMPT_COMMAND
}
PATH=/Users/cgatay/android-sdk-mac_86/1.4-liquid-superboot:/Users/cgatay/android-sdk-mac_86/tools:/Users/cgatay/android-sdk-mac_86/platform-tools:/Users/cgatay/bin:/Users/cgatay/Documents/SRMvision/scripts:/opt/subversion/bin:/usr/local/git/bin:/opt/glassfishv3/glassfish/bin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/usr/local/bin:/opt/apache-maven-3.0.2/bin:$PATH
export PATH
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
load_prompt
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
if [ -f /usr/bin/vim ]; then
alias vi='vim'
fi
if [ -f ~/.git-completion ]; then
source ~/.git-completion;
fi;
export HISTSIZE=10000
export EDITOR=vim
alias hist="history | grep "
shopt -s cdspell
shopt -s dotglob
export HISTCONTROL=ignoreboth
alias cd..="cd .."
alias ls="ls -G"
alias gfstart1='asadmin start-domain domain1 & log'
alias gfstart2='asadmin start-domain domain2 & log2'
alias gfstart3='asadmin start-domain domain3 & log3'
alias gfstop1='asadmin stop-domain domain1 & log'
alias gfstop2='asadmin stop-domain domain2 & log2'
alias gfstop3='asadmin stop-domain domain3 & log3'
alias gfkill='kill -9 `jps | grep ASMain | cut -d" " -f1`'
alias gfrestart1='asadmin stop-domain domain1 && asadmin start-domain domain1 & log'
alias log='tail -f /opt/glassfishv3/glassfish/domains/domain1/logs/server.log'
alias log2='tail -f /opt/glassfish/domains/domain2/logs/server.log'
alias log3='tail -f /opt/glassfish/domains/domain3/logs/server.log'
alias srm='cd /Volumes/workspace/srm-git/srmvision'
alias srmgit='cd /Volumes/workspace/srm-noLR'
alias work='cd /Volumes/workspace/'
alias mysql='mysql5'
alias mysqldump='mysqldump5'
alias gftools='python /Volumes/workspace/srm-git/srmvision/outils/src/main/python/gfTools.py'
alias nolrS='/opt/glassfishv3/bin/asadmin start-domain nolr'
function nolrL () {
tail -f /opt/glassfishv3/glassfish/domains/nolr/logs/server.log
}
MAVEN_OPTS="-Xmx1536m -Xms512m"
export MAVEN_OPTS
GRAILS_HOME=/opt/local/share/java/grails
export GRAILS_HOME
#THIS MUST BE AT THE END OF THE FILE FOR GVM TO WORK!!!
[[ -s "/Users/cgatay/.gvm/bin/gvm-init.sh" && -z $(which gvm-init.sh | grep '/gvm-init.sh') ]] && source "/Users/cgatay/.gvm/bin/gvm-init.sh"