-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
268 lines (242 loc) · 7.71 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
#!/usr/bin/env bash
#
# Bash.rc file for linux hosts
# Containing all common aliases
#
# If .bashrc is not included in .bash_profile,
# include the following in .bash_profile:
# if [ -f ~/.bashrc ]; then
# . ~/.bashrc
# fi
#
# Command alias candidates
# history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10
#
# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return
# Source global system definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Check our env
if [ "$(uname)" == "Darwin" ]; then
OS="Darwin"
elif [ "$(uname)" == "Linux" ]; then
OS="Linux"
elif [ "$(uname)" == "MINGW32_NT" ]; then
OS="Cygwin"
elif [ "$(uname)" == "MINGW64_NT" ]; then
OS="Cygwin"
fi
# User settings
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to history don't overwrite it
shopt -s histappend
# History length
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# Check if our term supports color
if test -t 1; then
ncolors=$(tput colors)
if test -n "$ncolors" && test "$ncolors" -ge 8; then
COLOR="true"
bold="$(tput bold)"
# underline="$(tput smul)"
# standout="$(tput smso)"
normal="$(tput sgr0)"
# black="$(tput setaf 0)"
red="$(tput setaf 1)"
# green="$(tput setaf 2)"
# yellow="$(tput setaf 3)"
# blue="$(tput setaf 4)"
# magenta="$(tput setaf 5)"
# cyan="$(tput setaf 6)"
white="$(tput setaf 7)"
fi
fi
# Colorful man pages
if [ $COLOR == "true" ]; then
export LESS_TERMCAP_mb=$(printf '\e[01;31m') # enter blinking mode – red
export LESS_TERMCAP_md=$(printf '\e[01;35m') # enter double-bright mode – bold, magenta
export LESS_TERMCAP_me=$(printf '\e[0m') # turn off all appearance modes (mb, md, so, us)
export LESS_TERMCAP_se=$(printf '\e[0m') # leave standout mode
export LESS_TERMCAP_so=$(printf '\e[01;33m') # enter standout mode – yellow
export LESS_TERMCAP_ue=$(printf '\e[0m') # leave underline mode
export LESS_TERMCAP_us=$(printf '\e[04;36m') # enter underline mode – cyan
fi
# Custom ls colors (defaults are too dark)
if [ $COLOR == "true" ]; then
LS_COLORS='di=1;34:ex=1;31'
export LS_COLORS
fi
if [ -n "$(which vim)" ]; then
alias vi="vim"
else
alias vi="vi"
fi
# For the lazy admin in all of us
alias sl="ls"
alias cd..="cd .."
alias ..="cd .."
# Aliases for ls (based on os)
if [ "$OS" == "Darwin" ]; then
alias ls="ls -CFG"
alias la="ls -CFGA"
alias ll="ls -1hFAlG"
alias lll="ls -1hFAlG |less -r"
elif [ "$OS" == "Linux" ]; then
alias ls="ls -CF --color=always"
alias la="ls -CFA --color=always"
alias ll="ls -1hFAl --color=always"
alias lll="ls -1hFAl --color=always |less -r"
elif [ "$OS" == "Cygwin" ]; then
alias ls="ls -CF --color=auto"
alias la="ls -CFA --color=auto"
alias ll="ls -1hFAl --color=auto"
alias lll="ls -1hFAl --color=auto |less -r"
fi
# User specific aliases
alias c="clear"
alias cl="clear"
alias df="df -Tha"
alias du1="du -ach --max-depth=1"
alias free="free -mt"
alias ps="ps auxf"
alias psg="ps aux | grep -v grep | grep -i -e VSZ -e"
alias mkdir="mkdir -p"
alias chx="chmod 755"
alias chr="chmod 644"
alias wget="wget -c"
alias hist="history | grep"
alias myip="curl http://ipecho.net/plain; echo"
alias lstz="tar -tf"
# Color dependent aliases
# Enable and disable color ls
cls () {
if [ -z "$1" ]; then
if [ $COLOR == "true" ]; then
echo "Enable and disable color ls | This terminal support color"
else
echo "Enable and disable color ls | This terminal does not support color"
return 1
fi
elif [ "$1" == "on" ]; then
if [ $COLOR == "true" ]; then
if [ $OS == "Darwin" ]; then
unalias ls && unalias la && unalias ll && unalias lll
alias ls="ls -CFG"
alias la="ls -CFGA"
alias ll="ls -1hFAlG"
alias lll="ls -1hFAlG |less -r"
else
unalias ls && unalias la && unalias ll && unalias lll
alias ls="ls -CF --color=auto"
alias la="ls -CFA --color=auto"
alias ll="ls -1hFAl --color=auto"
alias lll="ls -1hFAl --color=auto |less -r"
fi
elif [ $COLOR == "false" ]; then
echo "This terminal does not support color"
return 1
fi
elif [ "$1" == "off" ]; then
unalias ls && unalias la && unalias ll && unalias lll
alias ls="ls -CF"
alias la="ls -CFA"
alias ll="ls -1hFAl"
alias lll="ls -1hFAl"
fi
}
# A few useful functions
# For when I forget
als () {
echo "Known aliases:"
grep ^alias .bashrc | cut -d ' ' -f 2- |sed 's/\"//;s/\=/ \= /;s/\"//;'
echo
if [ "$OS" == "Linux" ]; then
echo "Known functions:"
FUNCT="$(declare -F | cut -d ' ' -f 3 |grep -v ^_ |grep '^...$')"
for i in $FUNCT; do
echo "$i:" "$($i)"
done;
else
echo "Known functions:"
echo "to be completed"
fi
}
# Make and cd to new dir
mcd () {
if [ -z "$1" ]; then
echo "Make and change to new dir"
return 1
else
mkdir -p "$1"
cd "$1" || return
fi
}
# Create .tar.gz
tgz () {
if [ -z "$1" ]; then
echo "tar & gz a file or directory"
return 1
else
tar -zcvf "$1".tar.gz "$1"
rm -r "$1"
fi
}
# Extract file by type
ext () {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Extract compressed file(s) ( zip | rar | bz2 | gz | tar | tbz2 | tgz | Z | 7z | xz | ex | tar.bz2 | tar.gz | tar.xz )"
return 1
else
for n in "$@"
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}
# Custom bash prompt
if [ $COLOR == "true" ]; then
PS1="\[${bold}\]\[${white}\][\[${red}\]\u\[${white}\]@\[${red}\]\h\[${white}\]]: \[${normal}\]"
else
PS1="[\u@\h]: "
fi
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac