-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathbashrc
More file actions
323 lines (242 loc) · 9.21 KB
/
Copy pathbashrc
File metadata and controls
323 lines (242 loc) · 9.21 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
if [[ $- == *i* ]] ; then
export IS_INTERACTIVE=true
else
export IS_INTERACTIVE=false
fi
if [[ -z $SSH_CONNECTION ]]; then
export IS_REMOTE=false
else
export IS_REMOTE=true
fi
# Colors ----------------------------------------------------------
export TERM=xterm-color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
if [ "$OS" = "linux" ] ; then
alias ls='ls --color=auto' # For linux, etc
# ls colors, see: http://www.linux-sxs.org/housekeeping/lscolors.html
export LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rb=90' #LS_COLORS is not supported by the default ls command in OS-X
else
alias ls='ls -G' # OS-X SPECIFIC - the -G command in OS-X is for colors, in Linux it's no groups
fi
# Setup some colors to use later in interactive shell or scripts
export COLOR_NC='\033[0m' # No Color
export COLOR_WHITE='\033[1;37m'
export COLOR_BLACK='\033[0;30m'
export COLOR_BLUE='\033[0;34m'
export COLOR_LIGHT_BLUE='\033[1;34m'
export COLOR_GREEN='\033[0;32m'
export COLOR_LIGHT_GREEN='\033[1;32m'
export COLOR_CYAN='\033[0;36m'
export COLOR_LIGHT_CYAN='\033[1;36m'
export COLOR_RED='\033[0;31m'
export COLOR_LIGHT_RED='\033[1;31m'
export COLOR_PURPLE='\033[0;35m'
export COLOR_LIGHT_PURPLE='\033[1;35m'
export COLOR_BROWN='\033[0;33m'
export COLOR_YELLOW='\033[1;33m'
export COLOR_GRAY='\033[1;30m'
export COLOR_LIGHT_GRAY='\033[0;37m'
alias colorslist="set | egrep 'COLOR_\w*'" # lists all the colors
# History ----------------------------------------------------------
export HISTCONTROL=ignoredups
#export HISTCONTROL=erasedups
export HISTFILESIZE=3000
export HISTIGNORE="ls:cd:[bf]g:exit:..:...:ll:lla"
alias h=history
hf(){
grep "$@" ~/.bash_history
}
if [ $IS_INTERACTIVE = 'true' ] ; then # Interactive shell only
# Input stuff -------------------------------------------------------
bind "set completion-ignore-case on" # note: bind used instead of sticking these in .inputrc
bind "set show-all-if-ambiguous On" # show list automatically, without double tab
bind "set bell-style none" # no bell
# Use vi command mode
#bind "set editing-mode vi"
#set -o vi
#bind -m vi-command -r 'v'
shopt -s checkwinsize # After each command, checks the windows size and changes lines and columns
# Completion -------------------------------------------------------
# Turn on advanced bash completion if the file exists
# Get it here: http://www.caliban.org/bash/index.shtml#completion) or
# on OSX: sudo port install bash-completion
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
if [ -f /usr/local/etc/bash_completion ]; then
. /usr/local/etc/bash_completion
fi
# git completion
source ~/cl/bin/git-completion.bash
# Add completion to source and .
complete -F _command source
complete -F _command .
# Prompts ----------------------------------------------------------
#git_dirty_flag() {
#git status 2> /dev/null | grep -c : | awk '{if ($1 > 0) print "⚡"}'
#}
prompt_func() {
previous_return_value=$?;
if [ $IS_REMOTE = 'true' ] ; then
prompt="\n\[\033]0;${USER} ${PWD}\007\]\[${COLOR_PURPLE}\]\w \[${COLOR_GRAY}\]${USER}@${HOSTNAME%%.*}$(__git_ps1)\[${COLOR_NC}\]\n"
else
prompt="\n\[\033]0;${USER} ${PWD}\007\]\[${COLOR_GREEN}\]\w \[${COLOR_GRAY}\]${USER}@${HOSTNAME%%.*}$(__git_ps1)\[${COLOR_NC}\]\n"
fi
#prompt="\033]0;${PWD}\007\[${COLOR_GREEN}\]\w\[${COLOR_GRAY}\]$(__git_ps1)\[${COLOR_NC}\] "
#prompt="\[${COLOR_GREEN}\]\w\[${COLOR_GRAY}\]$(__git_ps1)\[${COLOR_YELLOW}\]$(git_dirty_flag)\[${COLOR_NC}\] "
if test $previous_return_value -eq 0
then
PS1="${prompt}> "
else
PS1="${prompt}\[${COLOR_RED}\]> \[${COLOR_NC}\]"
fi
}
PROMPT_COMMAND=prompt_func
# export PS1="\[${COLOR_GREEN}\]\w\[${COLOR_NC}\] > " # Primary prompt with only a path
# export PS1="\[${COLOR_RED}\]\w > \[${COLOR_NC}\]" # Primary prompt with only a path, for root, need condition to use this for root
# export PS1="\[${COLOR_GRAY}\]\u@\h \[${COLOR_GREEN}\]\w > \[${COLOR_NC}\]" # Primary prompt with user, host, and path
# This runs before the prompt and sets the title of the xterm* window. If you set the title in the prompt
# weird wrapping errors occur on some systems, so this method is superior
#export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/} ${USER}@${HOSTNAME%%.*}"; echo -ne "\007"' # user@host path
export PS2='> ' # Secondary prompt
export PS3='#? ' # Prompt 3
export PS4='+' # Prompt 4
function xtitle { # change the title of your xterm* window
unset PROMPT_COMMAND
echo -ne "\033]0;$1\007"
}
fi
# Navigation -------------------------------------------------------
alias ..='cd ..'
alias ...='cd .. ; cd ..'
cl() { cd $1; ls -la; }
source ~/cl/bin/bashmarks.sh
# Editors ----------------------------------------------------------
#export EDITOR='mate -w' # OS-X SPECIFIC - TextMate, w is to wait for TextMate window to close
#export EDITOR='gedit' #Linux/gnome
export EDITOR='vim' #Command line
export GIT_EDITOR='vim'
#alias gvim='/Applications/MacVim.app/Contents/MacOS/vim -g'
if [ "$OS" = "darwin" ] ; then
alias v=mvim
alias vc=vim
alias vt='mvim --remote-tab'
else
alias v=vim
fi
# Security ---------------------------------------------------------
# Folder shared by a group
# chmod g+s directory
#find /foo -type f -print | xargs chmod g+rw,o-rwx,u+rw
#find /foo -type d -print | xargs chmod g+rwxs,o-rwx,u+rwx
# this might work just the same (not tested)
# chmod -R g+rwXs,o-rwx,u+rwX /foo
# Sluething----------------------------------------------------
findportuser() {
lsof -i :"$1"
}
findhosts(){
nmap -sP -n -oG - "$1"/24 | grep "Up" | awk '{print $2}' -
echo "To scan those do: nmap $1-254"
echo "To scan and OS detect those do: sudo nmap -O $1-254"
echo "To intensly scan one do: sudo nmap -sV -vv -PN $1"
}
monitor_traffic(){
# install ngrep with sudo port install ngrep
sudo ngrep -W byline -qld en1 "$1"
}
find_large_files(){
find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
}
# Other aliases ----------------------------------------------------
alias ll='ls -hl'
alias la='ls -a'
alias lla='ls -lah'
# Search
# Use ack for grepping and find if ack is available
# sudo port install p5-app-ack
if type -P ack &>/dev/null ; then
g(){
ack "$*" --all-types --color-match=green --color-filename=blue --smart-case
}
grb(){
ack "$*" --type=ruby --color-match=green --color-filename=blue --smart-case
}
gw(){
ack "$*" --all-types --color-match=green --color-filename=blue --word-regexp --smart-case
}
gnolog(){
ack "$*" --all-types --ignore-dir=log --color-match=green --color-filename=blue --smart-case
}
f(){
ack -i -g ".*$*[^\/]*$" | highlight blue ".*/" green "$*[^/]"
}
else
g(){
grep -Rin $1 *
}
f(){
find . -iname "$1"
}
fi
find_replace_log_changes(){
find . -type f | xargs grep -n "$1" | tee files_changed.txt | sed 's/:.*$//' | xargs sed -i "s/$1/$2/g"
}
# Misc
alias reloadbash='source ~/cl/etc/bash_profile'
alias ducks='du -cksh * | sort -rn|head -11' # Lists folders and files sizes in the current folder
alias bigfilesandfolders='du -hsx * | sort -rh | head -20'
alias m='more'
alias top='top -o cpu' # os x:
alias df='df -h' # Show disk usage
if [ "$OS" = "linux" ] ; then
alias psaux='ps -AFH'
else
alias psaux='ps aux'
fi
psgrep(){
psaux | egrep "$1" | egrep -v "grep|highlight" | highlight green "$1"
}
if [ "$OS" = "linux" ] ; then
alias systail='tail -f /var/log/syslog'
else
alias systail='tail -f /var/log/system.log'
fi
# Shows most used commands, cool script I got this from: http://lifehacker.com/software/how-to/turbocharge-your-terminal-274317.php
alias profileme="history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr"
alias untar="tar xvzf"
alias cp_folder="cp -Rpv" #copies folder and all sub files and folders, preserving security and dates
alias mirror_website="wget -m -x -p --convert-links --no-host-directories --no-cache -erobots=off"
killhard() {
kill -9 "$1"
}
# Ruby ----------------------------------------------------
# RVM
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
# Fixes problems with sending email in ruby
#export RUBYOPT="-r openssl"
# Spin: gem install spin kicker
alias spin="spin serve -Itest | highlight red ' [1-9]0* failures' purple '[_a-zA-Z0-9]*\.rb.[0-9]*' red 'Error:' red 'Failure:' red ' [1-9]0* errors' green ' 0 errors' green ' 0 failures'"
alias spin_kicker="kicker -r rails -b 'spin push'"
# Bring in the other files ----------------------------------------------------
if [ $IS_INTERACTIVE = 'true' ] ; then
source ~/.bashrc_help
source ~/cl/bin/mq/mq.sh # MySQL tools
source ~/cl/bin/rr/rr.sh # Rails tools
source ~/cl/bin/gt/gt.sh # Git tools
source ~/cl/bin/be/be.sh # Bundle exec
#source ~/cl/bin/sv/sv.sh # SVN tools
fi
if [ -f ~/.bashrc_local ]; then
source ~/.bashrc_local
fi
# Test ------------------------------------------------------------------------
#if [ "$OS" = "linux" ] ; then
#elif
#else
#fi
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting