Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (222 sloc) 9.405 kB
39ffca0 @gabesoft bash and vim settings
authored
1 # .bashrc
2
bb9f68e @gabesoft terminal enhancements
authored
3 # --------------------------------------------------------------------------------
4 # options
5 # --------------------------------------------------------------------------------
6 set -o ignoreeof # Stop CTRL+D from logging me out.
7 set -o noclobber # Prevent overwriting files with >.
8 set -o notify # Notify of job termination.
9
10 shopt -s cdspell # Spell check path
11 shopt -s checkhash # Check program exists before executing.
12 shopt -s checkwinsize # Wrap lines correctly after resizing terminal.
13 shopt -s cmdhist # Remember multiline commands in history.
14 shopt -s extglob # Use extended pattern matching.
15 shopt -s histappend # Append to the history file.
16 shopt -s histreedit # Allow re-editing of a failed substitution.
17 shopt -s histverify # Don't execute retrieved history immediately; allow editing.
18 shopt -s lithist # Don't reformat multi-line cmd into one line with semicolons.
19
20 # history
21 export HISTCONTROL=ignoredups
f736ae6 @gabesoft cron update
authored
22
bb9f68e @gabesoft terminal enhancements
authored
23 # bash
24 bind "set completion-ignore-case on"
25 bind "set bell-style none"
26 bind "set show-all-if-ambiguous on"
27
28 # --------------------------------------------------------------------------------
286a6a1 @gabesoft os specific updates
authored
29 # platform
bb9f68e @gabesoft terminal enhancements
authored
30 # --------------------------------------------------------------------------------
286a6a1 @gabesoft os specific updates
authored
31 platform='unkown'
32 unamestr=`uname`
33
34 if [[ "$unamestr" == "Linux" ]]; then
35 platform='linux'
36 elif [[ "$unamestr" == "Darwin" ]]; then
37 platform='mac'
38 fi
39
bb9f68e @gabesoft terminal enhancements
authored
40 [[ "$TERM" != 'dumb' ]] && use_color='true' || use_color='false'
41 [[ "$use_color" == 'true' ]] && {
42 [[ "$(which dircolors)" ]] && use_color_gnu='true' || use_color_bsd='true'
43 }
44
45 # --------------------------------------------------------------------------------
46 # aliases
47 # --------------------------------------------------------------------------------
48
49 # alias = list all aliases
50 # cd = navigate home
51 # cd - = navigate to previous folder
52
f736ae6 @gabesoft cron update
authored
53 #navigation
54 alias ..='cd ..'
55 alias ...='cd .. ; cd ..'
286a6a1 @gabesoft os specific updates
authored
56 alias cdd='cd -' # go to previous directory
57
58 # sudo
59 alias s='sudo'
60d6a7e @gabesoft added alias
authored
60 alias svisudo='sudo visudo' # edit the sudoers file
39ffca0 @gabesoft bash and vim settings
authored
61
62 # delete
63 alias rm='rm -i'
64 alias rf='rm -f'
65 alias rr='rm -f -r'
286a6a1 @gabesoft os specific updates
authored
66 alias srm='sudo rm -i'
67 alias srf='sudo rm -f'
68 alias srr='sudo rm -f -r'
39ffca0 @gabesoft bash and vim settings
authored
69
70 # copy move
71 alias cp='cp -i'
1e45d59 @gabesoft settings
authored
72 alias cpf='cp -f'
286a6a1 @gabesoft os specific updates
authored
73 alias cr='cp -iR'
1e45d59 @gabesoft settings
authored
74 alias crf='cp -fR'
39ffca0 @gabesoft bash and vim settings
authored
75 alias mv='mv -i'
286a6a1 @gabesoft os specific updates
authored
76 alias scp='sudo cp -i'
77 alias scr='sudo cp -iR'
78 alias smv='sudo mv -i'
39ffca0 @gabesoft bash and vim settings
authored
79
bb9f68e @gabesoft terminal enhancements
authored
80 # ls family
e097586 @gabesoft bash aliases
authored
81 alias la='ls -hAF' # show all files
82 alias lA='ls -lhAFT' # show all files (extended)
e98892b @gabesoft more aliases
authored
83 alias la1='ls -hAF */' # show all files and folders with first level contents
84 alias lA1='ls -lhAFT */' # show all files and folders with first level contents (extended)
85 alias la2='ls -hAF */*/' # show all files and folders with second level contents
86 alias lA2='ls -lhAFT */*/' # show all files and folders with second level contents (extended)
87
e097586 @gabesoft bash aliases
authored
88 alias ll='ls -F' # show files
89 alias lL='ls -lhFT' # show files (extended)
70d3dc6 @gabesoft aliases
authored
90 alias ll1='ls -F */' # show files and folders with first level contents
91 alias lL1='ls -lhFT */' # show files and folders with first level contents (extended)
92 alias ll2='ls -F */*/' # show files and folders with second level contents
93 alias lL2='ls -lhFT */*/' # show files and folders with second level contents (extended)
e097586 @gabesoft bash aliases
authored
94
95 alias lz='ls -lhS' # show files sorted by size
96 alias lZ='ls -lhSA' # show all files sorted by size
97
98 alias lt='ls -lht' # show files sorted by time (most recent first)
99 alias lT='ls -lhtA' # show all files sorted by time (most recent first)
100
101 alias lr='ls -lhR' # show files recursive
102 alias lR='ls -lhRA' # show files recursive (include hidden)
103
104 alias lf='ls -l | grep -v "^d"' # show only files
105 alias lF='ls -Al | grep -v "^d"' # show only files (include hidden)
106
107 alias ldir='ls -l | grep "^d"' # show only directories
108 alias lDir='ls -Al | grep "^d"' # show only directories (include hidden)
bb9f68e @gabesoft terminal enhancements
authored
109
1773ec9 @gabesoft vim + bash settings
authored
110
111 function delrec() {
112 find . -iname "$1" -print0 | xargs -0 rm -rfv ;
113 }
114 alias delf='delrec' # delete files matching pattern in all subfolders recursively
115
bb9f68e @gabesoft terminal enhancements
authored
116 # paths
117 alias print-path='echo -e ${PATH//:/\\n}'
118 alias print-libpath='echo -e ${LD_LIBRARY_PATH//:/\\n}'
119
120 # curl
121 alias get='curl -C - -O'
122
123 # add colors for filetype recognition
124 [[ "$use_color_gnu" == 'true' ]] && alias ls='ls -hF --group-directories-first --color=auto'
125 [[ "$use_color_bsd" == 'true' ]] && alias ls='ls -G -F'
126
127 # mkdir make intermediate directories
128 alias mkdir='mkdir -p'
39ffca0 @gabesoft bash and vim settings
authored
129
5f862ba @gabesoft cron update
authored
130 # grep / find
131 alias g='grep -i'
132 alias f='find . -iname'
133
d1baa90 @gabesoft cron update
authored
134 # make a symbolic link
135 alias lk='ln -s'
136
5f862ba @gabesoft cron update
authored
137 # list the size of all folders and files
138 alias ducks='du -cks * | sort -rn|head -11'
139
140 # system log
141 alias systail='tail -f /var/log/system.log'
142
143 # show most used commands
144 alias profileme="history | awk '{print \$2}' | awk 'BEGIN{FS=\"|\"}{print \$1}' | sort | uniq -c | sort -n | tail -n 20 | sort -nr"
145
39ffca0 @gabesoft bash and vim settings
authored
146 # disk usage
147 alias df='df -h'
148
149 # tar
286a6a1 @gabesoft os specific updates
authored
150 alias untar='tar -xvzf'
151 alias suntar='sudo tar -xvzf'
152
f21620a @gabesoft java bash settings
authored
153 # jar (view jar contents)
154 alias vjar='jar -tvf'
155
286a6a1 @gabesoft os specific updates
authored
156 # sudo unzip
157 alias sunzip='sudo unzip'
158 alias sbunzip2='sudo bunzip2'
39ffca0 @gabesoft bash and vim settings
authored
159
9ea3afb @gabesoft cron update
authored
160 # execute permissions
161 alias exusr='chmod u+x' # current user
162 alias exall='chmod ugo+x' # all users
163
39ffca0 @gabesoft bash and vim settings
authored
164 # version
165 alias ver='cat /etc/redhat-release'
166
ae4046b @gabesoft cron update
authored
167 # list all colors
91369a4 @gabesoft cron update
authored
168 alias colors="set | egrep '^COLOR_\w*'"
39ffca0 @gabesoft bash and vim settings
authored
169
f21620a @gabesoft java bash settings
authored
170 # --------------------------------------------------------------------------------
171 # bookmarks
172 # --------------------------------------------------------------------------------
f736ae6 @gabesoft cron update
authored
173 # save bookmarks to folders
5f862ba @gabesoft cron update
authored
174 # save x = bookmarks the current directory as x
175 # cd x = navigates to the bookmarked path
176 # smarks = displays all bookmarks
177 # cmarks = clears all bookmarks
f736ae6 @gabesoft cron update
authored
178 if [ ! -f ~/.dirs ]; then # if doesn't exist, create it
bb9f68e @gabesoft terminal enhancements
authored
179 touch ~/.dirs
f736ae6 @gabesoft cron update
authored
180 fi
181
5f862ba @gabesoft cron update
authored
182 alias smarks='cat ~/.dirs'
183 alias cmarks='rm -f ~/.dirs; touch ~/.dirs'
f736ae6 @gabesoft cron update
authored
184 save (){
bb9f68e @gabesoft terminal enhancements
authored
185 command sed "/!$/d" ~/.dirs > ~/.dirs1; \mv ~/.dirs1 ~/.dirs; echo "$@"=\"`pwd`\" >> ~/.dirs; source ~/.dirs ;
f736ae6 @gabesoft cron update
authored
186 }
187 source ~/.dirs # Initialization for the above 'save' facility: source the .sdirs file
188 shopt -s cdable_vars # set the bash option so that no '$' is required when using the above facility
189
bb9f68e @gabesoft terminal enhancements
authored
190 # --------------------------------------------------------------------------------
c227737 @gabesoft bash prompt fixes
authored
191 # prompt: show git branch and status
bb9f68e @gabesoft terminal enhancements
authored
192 # --------------------------------------------------------------------------------
c227737 @gabesoft bash prompt fixes
authored
193 function _git_prompt() {
194 local git_status="`git status -unormal 2>&1`"
195 if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
196 if [[ "$git_status" =~ nothing\ to\ commit ]]; then
127d54a @gabesoft terminal colors + other settings
authored
197 local branch_color=$COLOR_BLUE
c227737 @gabesoft bash prompt fixes
authored
198 elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
199 local branch_color=$COLOR_PURPLE
200 else
201 local branch_color=$COLOR_RED
202 fi
203 if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
204 branch=${BASH_REMATCH[1]}
205 else
206 # Detached HEAD. (branch=HEAD is a faster alternative.)
207 branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
208 echo HEAD`)"
209 fi
127d54a @gabesoft terminal colors + other settings
authored
210 echo -n '\['"$COLOR_BLUE"'\](''\['"$branch_color"'\]'"$branch"'\['"$COLOR_BLUE"'\])'
c227737 @gabesoft bash prompt fixes
authored
211 fi
212 }
213 function _prompt_command() {
ff77bcd @gabesoft prompt fixes
authored
214 PS1="\[${COLOR_BROWN}\]\w `_git_prompt`\[${COLOR_RED}\]> \[${COLOR_NC}\]"
c227737 @gabesoft bash prompt fixes
authored
215 }
216 PROMPT_COMMAND=_prompt_command
5f862ba @gabesoft cron update
authored
217
bb9f68e @gabesoft terminal enhancements
authored
218 # --------------------------------------------------------------------------------
91369a4 @gabesoft cron update
authored
219 # colors
bb9f68e @gabesoft terminal enhancements
authored
220 # --------------------------------------------------------------------------------
91369a4 @gabesoft cron update
authored
221
222 # Black 0;30 Dark Gray 1;30
223 # Blue 0;34 Light Blue 1;34
224 # Green 0;32 Light Green 1;32
225 # Cyan 0;36 Light Cyan 1;36
226 # Red 0;31 Light Red 1;31
227 # Purple 0;35 Light Purple 1;35
228 # Brown 0;33 Yellow 1;33
229 # Light Gray 0;37 White 1;37
5f862ba @gabesoft cron update
authored
230
bb9f68e @gabesoft terminal enhancements
authored
231 #export CLICOLOR=1
232 #export TERM=xterm-color
286a6a1 @gabesoft os specific updates
authored
233
bb9f68e @gabesoft terminal enhancements
authored
234 [[ "$use_color_gnu" == 'true' ]] && eval $(dircolors $HOME/.dir_colors)
ff77bcd @gabesoft prompt fixes
authored
235 [[ "$use_color_gnu" == 'true' ]] && export LS_COLORS='di=0;36:fi=0;37:ln=0;35:pi=5:so=5:bd=5:cd=5:or=31:mi=1:ex=0;31:*.rb=90'
bb9f68e @gabesoft terminal enhancements
authored
236 [[ "$use_color_bsd" == 'true' ]] && export CLICOLOR=1
237 [[ "$use_color_bsd" == 'true' ]] && export LSCOLORS=Gxfxcxdxbxegedabagacad
39ffca0 @gabesoft bash and vim settings
authored
238
239 export COLOR_NC='\033[0m' # No Color
240 export COLOR_WHITE='\033[1;37m'
241 export COLOR_BLACK='\033[0;30m'
242 export COLOR_BLUE='\033[0;34m'
243 export COLOR_LIGHT_BLUE='\033[1;34m'
244 export COLOR_GREEN='\033[0;32m'
245 export COLOR_LIGHT_GREEN='\033[1;32m'
246 export COLOR_CYAN='\033[0;36m'
247 export COLOR_LIGHT_CYAN='\033[1;36m'
248 export COLOR_RED='\033[0;31m'
249 export COLOR_LIGHT_RED='\033[1;31m'
250 export COLOR_PURPLE='\033[0;35m'
251 export COLOR_LIGHT_PURPLE='\033[1;35m'
252 export COLOR_BROWN='\033[0;33m'
253 export COLOR_YELLOW='\033[1;33m'
254 export COLOR_GRAY='\033[1;30m'
255 export COLOR_LIGHT_GRAY='\033[0;37m'
256
286a6a1 @gabesoft os specific updates
authored
257 export COLOR_BG_NC='\033[49m'
258 export COLOR_BG_LIGHT_GRAY='\033[47m'
259 export COLOR_BG_PURPLE='\033[45m'
260 export COLOR_BG_RED='\033[41m'
261 export COLOR_BG_GREEN='\033[42m'
262 export COLOR_BG_YELLOW='\033[43m'
263 export COLOR_BG_BLUE='\033[44m'
264 export COLOR_BG_CYAN='\033[46m'
265
127d54a @gabesoft terminal colors + other settings
authored
266 echo -e "${COLOR_RED}kernel info: " `uname -smr`
92b6ed4 @gabesoft cron update
authored
267 echo -e "${COLOR_BROWN}`bash --version`"
127d54a @gabesoft terminal colors + other settings
authored
268 echo -ne "${COLOR_GREEN}uptime: "; uptime
269 echo -ne "${COLOR_GREEN}server time is: "; date
92b6ed4 @gabesoft cron update
authored
270 echo -ne "${COLOR_NC}"
Something went wrong with that request. Please try again.