-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
346 lines (292 loc) · 9.38 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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#// ██ ██
#// ░██ ░██
#// ░██ ██████ ██████░██
#// ░██████ ░░░░░░██ ██░░░░ ░██████
#// ░██░░░██ ███████ ░░█████ ░██░░░██
#// ░██ ░██ ██░░░░██ ░░░░░██░██ ░██
#// ░██████ ░░████████ ██████ ░██ ░██
#// ░░░░░ ░░░░░░░░ ░░░░░░ ░░ ░░
#//-------------------------------------------------
#// global definitions
#//-------------------------------------------------
#// 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
export HISTCONTROL=ignoredups:ignorespace
#// append to the history file, don't overwrite it
shopt -s histappend
#// save multi-line commands as one command
shopt -s cmdhist
#// record each line as it gets issued
PROMPT_COMMAND='history -a'
#// huge history. doesn't appear to slow things down, so why not?
HISTSIZE=500000
HISTFILESIZE=100000
#// avoid duplicate entries
HISTCONTROL="erasedups:ignoreboth"
#// don't record some commands
export HISTIGNORE="&:[ ]*:exit:ls:bg:fg:history"
#// useful timestamp format
HISTTIMEFORMAT='%F %T '
#// check the window size after each command and, if necessary,
#// update the valyes of LINES and COLUMNS
shopt -s checkwinsize
#// correct spelling errors during tab-completion
shopt -s dirspell
#// correct spelling errors in arguments supplied to cd
shopt -s cdspell
#// make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
#//-------------------------------------------------
#// greetings, motd, et al..
#//-------------------------------------------------
#// define colors
BLACK='\e[0;30m\]'
gray='\e[0;37m\]'
GRAY='\e[1;30m\]'
red='\[\e[0;31m\]'
RED='\[\e[1;31m\]'
green='\[\e[0;32m\]'
GREEN='\[\e[1;32m\]'
blue='\[\e[0;34m\]'
BLUE='\[\e[1;34m\]'
magenta='\[\e[0;35m\]'
MAGENTA='\[\e[1;35m\]'
cyan='\[\e[0;36m\]'
CYAN='\[\e[1;36m\]'
NC='\[\e[0m\]' #// no color
#// variables you might want
T12h="\T"
T12a="\@"
PathS="\w"
PathF="\W"
NewL="\n"
Jobs="\j"
#// bash motd
clear
echo -e "\033[1;36mThis is BASH \033[1;31m$BASH_VERSION\033[m \n"
echo -en ;date
echo -en ;uptime
echo -e " "
#// run upon exit of shell
function _exit() {
echo -e "\n\n\033[0;32m[ exiting shell ]\033[m\n"
}
trap _exit EXIT
#// dir colors
export CLICOLOR=1
export LSCOLORS='ExGxFxDxCxDxDxhbhdacEc'
#// export LSCOLORS='gxfxcxdxbxegedabagacad'
#//-------------------------------------------------
#// shell prompt
#//-------------------------------------------------
source $HOME/Scripts/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=true
twolevelprompt='$([ "$PWD" != "${PWD%/*/*/*}" ] && echo "/...${PWD##${PWD%/*/*}}" || echo "$PWD")'
gitprompt='$(__git_ps1 "[%s]")'
#arrow=$'\xe2\x86\x92'
#// if command returns zero, user is root
if [ $(id -u) -eq 0 ]; then
#// you are root, red prompt
PS1="${RED}\u@\h ${NC}[$twolevelprompt] #// "
else
#// standard
PS1="${GREEN}\u@\h ${NC}[${BLUE}$twolevelprompt${NC}]${CYAN}$gitprompt${NC} $ "
fi
#// This one isn't required for bash prompt and is a small bonus
#// which gives you git-specific auto-completion. Sometimes this can slow
#// things down. Feel free to disable it if you are experiencing latency.
source $HOME/Scripts/git-completion.sh
#//-------------------------------------------------
#// settings
#//-------------------------------------------------
set -o notify
set -o noclobber
set -o ignoreeof
#set -o nounset
#set -o xtrace #// for debugging
#// enable:
#// shopt -s cdspell
#// disable:
#// shopt -u mailwarn
unset MAILCHECK #// shell warning of new mail
export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
export HITSTIMEFORMAT="%H:%M"
export HISTIGNORE="&bg:fg:11:h"
export HOSTFILE=$HOME/.hosts #// list of remote hosts
export ARCHFLAGS="-arch x86_64"
export CC=/usr/bin/gcc #// correct this for osx, do not use homebrew version
#//-------------------------------------------------
#// aliases and functions
#//-------------------------------------------------
#// general system aliases
alias cls='clear'
alias h='history'
alias ls='ls -h'
alias la='ls -A'
alias ll='ls -alF'
alias l='ls -CF'
alias trash='mv --target-directory=$HOME/.Trash/' #// osx only
alias empty='rm -rf $HOME/.Trash/*' #// osx only
alias rm='rm -iv'
alias cp='cp -iv'
alias mv='mv -iv'
alias root='sudo su -l'
alias runlevel='sudo /sbin/init'
alias grep='grep --color=always'
alias egrep='egrep --color=always'
alias dfh='df -h'
alias nano='nano -wc'
alias irc='irssi'
alias bashrc='nano ~/.bashrc'
alias profile='nano ~/.profile'
#// enable programmable completion features (you don't need to enable
#// this, if it's already enabled in /etc/bash.bashrc and /etc/profile
#// sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
#// system info
#// TODO: fix this for osx
alias cpuu="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'"
alias memu='ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS'
alias pg='ps aux | grep' #// requires an argument
#// list terminal colors
colors () {
for i in {0..255} ; do
printf "\x1b[38;5;${i}mcolour${i}\n"
done
}
#// extract - extraction of all file types
extract () {
if [ -f $1 ]; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) rar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
#ziprm - extract and delete zipfile
ziprm () {
if [ -f $1 ] ; then
unzip $1
rm $1
else
echo "Need a valid zipfile"
fi
}
#psgrep - advanced grep feature
psgrep() {
if [! -z $1 ]; then
echo "Grepping for processes matching $1..."
ps aux | grep $1 | grep -v grep
else
echo "Need name to grep for"
fi
}
#// grab - take ownership of file
grab() {
sudo chown -R ${USER} ${1:-.}
}
#// network
#// TODO: fix these
alias me='ipconfig getifaddr en0' #// osx only
alias ping='ping -c 10'
alias whois='whois -H'
alias netaudit='sudo nmap -sT -O localhost'
alias net1='watch --interval=2 "sudo netstat -apn -l -A inet"'
alias net2='watch --interval=2 "sudo netstat -anp --inet --inet6"'
alias net3='sudo lsof -i'
alias net4='watch --interval=2 "sudo netstat -p -e --inet --numeric-hosts"'
alias net5='watch --interval=2 "sudo netstat -tulpan"'
alias net6='sudo netstat -tulpan'
alias net7='watch --interval=2 "sudo netstat -utapen"'
alias net8='watch --interval=2 "sudo netstat -ano -l -A inet"'
#// netinfo - shows network information for your system
#// TODO: fix this for full osx functionality
#// add homebrew awk, sed, lynx
netinfo () {
echo "--------------- Network Information ---------------"
ifconfig | awk /'inet addr/ {print $2}'
ifconfig | awk /'Bcast/ {print $3}'
ifconfig | awk /'inet addr/ {print $4}'
ifconfig | awk /'HWaddr/ {print $4,$5}'
myip=`lynx -dump -hiddenlinks=ignore -nolist http://checkip.dyndns.org:8245/ | sed '/^$/d; s/^[ ]*//g; s/[ ]*$//g' `
echo "${myip}"
echo "---------------------------------------------------"
}
#// dirsize - finds directory sizes and lists them for the current directory
#// TODO: what the fuck is this supposed to do??
dirsize () {
du -shx * .[a-zA-Z0-9_]* 2> /dev/null | \
egrep '^ *[0-9.]*[MG]' | sort -n > /tmp/list
egrep '^ *[0-9.]*M' /tmp/list
egrep '^ *[0-9.]*G' /tmp/list
rm -rf /tmp/list
}
#// copy and go to dir
cpg () {
if [ -d "$2" ]; then
cp $1 $2 && cd $2
else
cp $1 $2
fi
}
#// move and go to dir
mvg () {
if [ -d "$2" ]; then
mv $1 $2 && cd $2
else
mv $1 $2
fi
}
#// directory navigation aliases
alias cd..='cd ..'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
#// chmod and permissions commands
alias mx='chmod a+x'
alias 000='chmod 000'
alias 644='chmod 644'
alias 755='chmod 755'
alias perm='stat --printf "%a %n \n "' #// requires a file name e.g. perm file
#// aliases for OSX
alias cleanup='find . -type f -name '*.DS_Store' -ls -delete'
alias spot='mdfind -name '
#// aliases for Ruby/Rails/RubyGems
alias killgems='gem uninstall -aIx'
#// aliases for git
#// TODO: bash git aliases vs gitconfig features
alias undopush='git push -f origin HEAD^:master'
#// fun stuff
#alias hax="growlnotify -a 'Activity Monitor' 'System error' -m 'hey noob idiot bitch t(._.t)'"
#//-------------------------------------------------
#// PATH
#//-------------------------------------------------
echo $PATH | grep -q -s "/usr/local/bin"
if [ $? -eq 1 ]; then
PATH=$PATH:/usr/local/bin
export PATH
fi
#// PATH export
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/X11/bin
#// init rbenv
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$HOME/.rbenv/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
#// init pyenv
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi