-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashrc
executable file
·473 lines (440 loc) · 14.8 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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#!/usr/bin/env bash
shopt -s checkwinsize expand_aliases histappend checkhash
[[ -f /usr/share/bash-completion/bash_completion ]] && \
. /usr/share/bash-completion/bash_completion
set -o posix
# shellcheck disable=SC1091
[[ -f /etc/bashrc ]] && . /etc/bashrc
# shellcheck disable=SC1091
[[ -f /etc/bash_completion ]] && . /etc/bash_completion
# shellcheck disable=SC1091
[[ -f /usr/share/bash-completion/bash_completion ]] && \
. /usr/share/bash-completion/bash_completion
readonly END="\033[0m" BLACK="\033[0;30m" BLACKB="\033[1;30m" \
WHITE="\033[0;37m" WHITEB="\033[1;37m" RED="\033[0;31m" \
REDB="\033[1;31m" GREEN="\033[0;32m" GREENB="\033[1;32m" \
YELLOW="\033[0;33m" YELLOWB="\033[1;33m" BLUE="\033[0;34m" \
BLUEB="\033[1;34m" PURPLE="\033[0;35m" PURPLEB="\033[1;35m" \
LIGHTBLUE="\033[0;36m" LIGHTBLUEB="\033[1;36m"
stats() {
history | awk '{print $2}' | awk 'BEGIN {FS="|"} {print $1}' | sort \
| uniq -c | sort -rn | head -30 | less
}
color_form_output() {
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]] || [[ -z "$1" ]]; then
name="color_form_output"
cat << end_of_message
apply color to any text
USAGE
- show this message (default)
$name [-h, --help]
- get colored message
$name color message
$(printf '=%.0s' {1..80})
by @mb6ockatf, Sat 01 Jul 2023 01:34:03 PM MSK
end_of_message
return 0
fi
local color="$1" message="$2"
case "$color" in
black) color="${BLACK}" ;;
blackb) color="${BLACKB}" ;;
white) color="${WHITE}" ;;
whiteb) color="${WHITEB}" ;;
red) color="${RED}" ;;
redb) color="${REDB}" ;;
green) color="${GREEN}" ;;
greenb) color="${GREENB}" ;;
yellow) color="${YELLOW}" ;;
yellowb) color="${YELLOWB}" ;;
blue) color="${BLUE}" ;;
blueb) color="${BLUEB}" ;;
purple) color="${PURPLE}" ;;
purpleb) color="${PURPLEB}" ;;
lightblue) color="${LIGHTBLUE}" ;;
lightblueb) color="${LIGHTBLUEB}" ;;
*) return 2 ;;
esac
echo -e "${color}${message}${END}"
}
color_color_table() {
local T='gYw'
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m'; do
local FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m; do
echo -en "$EINS \033[$FG\033[$BG $T \033[0m"
done
echo
done
echo
}
color_colorful() {
for x in {0..8}; do
for fg in {30..37}; do
for bg in {40..47}; do
echo -ne "\e[$x;$fg;$bg""m\\\e[$x;$fg;$bg""m\e[0;37;40m "
done
echo
done
done
echo ""
}
ex() {
if [[ -f "$1" ]]; then
case $1 in
*.tar.bz2) tar xjf "$1";;
*.tar.gz) tar xzf "$1";;
*.bz2) bunzip2 "$1";;
*.rar) unrar 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 ex()" ;;
esac
else
echo "'$1' is not a valid file" && return 22
fi
}
light() {
local file="/sys/class/backlight/intel_backlight/brightness"
[[ ! -f $file ]] && echo "intel_backlight settings are not available" \
&& return 2
declare current
current="$(cat "$file")"
local new="$current"
if [[ "$1" = "-dec" ]]; then
new=$(( current - $2 ))
elif [[ "$1" = "-inc" ]]; then
new=$(( current + $2 ))
elif [[ "$1" = "night" ]]; then
new=1
fi
[[ "$new" -ge 0 ]] || exit
echo "$new" | sudo tee "$file"
}
commit() {
declare TYPE SUMMARY
TYPE=$(gum choose "fix" "feat" "docs" "style" "refactor" "test" \
"chore" "revert") SCOPE=$(gum input --placeholder "scope")
test -n "$SCOPE" && SCOPE="($SCOPE)"
SUMMARY=$(gum input --value "$TYPE$SCOPE: " --placeholder \
"Summary of this change") DESCRIPTION=$(gum write --placeholder \
"Details of this change (CTRL+D to finish)")
gum confirm "Commit changes?" && \
git commit -m "$SUMMARY" -m "$DESCRIPTION"
}
set_bash_prompt() {
local LAST_RESULT="$?" DIVIDER="\[\e[30;1m\]" \
COLOR_CMDCOUNT="\[\e[32;1m\]" COLOR_USERNAME="\[\e[37;0m\]" \
COLOR_USERHOSTAT="\[\e[36;1m\]" COLOR_HOSTNAME="\[\e[35;1m\]" \
COLOR_GITBRANCH="\[\e[33;0m\]" COLOR_VENV="\[\e[33;1m\]" \
COLOR_PATH_OK="\[\e[32;1m\]" COLOR_PATH_ERR="\[\e[31;1m\]" \
COLOR_NONE="\[\e[0m\]" PATH_COLOR GIT_IS_AVAILABLE GIT_BRANCH \
git_answer
[ $LAST_RESULT -eq 0 ] && PATH_COLOR="$COLOR_PATH_OK" \
|| PATH_COLOR="$COLOR_PATH_ERR"
PS1="${DIVIDER}[${PATH_COLOR}\w${DIVIDER}"
PS1="${PS1}:${COLOR_CMDCOUNT}\#${DIVIDER}"
GIT_IS_AVAILABLE=$(git --version 2>&1 >/dev/null ; echo $?)
if [ "$GIT_IS_AVAILABLE" -eq 0 ]; then
git_answer=$(git rev-parse --is-inside-work-tree 2>&1 >/dev/null)
if [ "$git_answer" = "" ]; then
GIT_BRANCH=$(git symbolic-ref --short HEAD)
PS1="${PS1}:${COLOR_GITBRANCH}${GIT_BRANCH}${DIVIDER}"
fi
fi
[[ -n "$VIRTUAL_ENV" ]] && \
PS1="${PS1}:${COLOR_VENV}$(basename "$VIRTUAL_ENV")${DIVIDER}"
PS1="${PS1}][${DIVIDER}${COLOR_USERNAME}\u${COLOR_USERHOSTAT}"
PS1+="@${COLOR_HOSTNAME}\h${DIVIDER}]${COLOR_NONE} "
}
mcd() {
[ -d "$1" ] || mkdir "$1"
cd "$1" && pwd
}
wttr() {
local city="$1" options="$2" header="Accept-Language: en"
[[ "$options" -eq "" ]] && options="1FnQp"
curl -H "$header " "wttr.in/$city?$options"
}
clock() {
watch -xtc echo "$(date '+%D %T' | toilet -f term -F border --gay)"
}
ftext() {
# -i case-insensitive
# -I ignore binary files
# -H causes filename to be printed
# -r recursive search
# -n causes line number to be printed
# optional: -F treat search term as a literal, not a regular expression
# optional: -l only print filenames and not the matching lines ex. \
# grep -irl "$1" *
grep -iIHrn --color=always "$1" . | less -r
}
mvg() {
if [ -d "$2" ]; then
mv "$1" "$2" && cd "$2" || return
else
mv "$1" "$3"
fi
}
viewlines () {
sed -n "$1,$2p" "$3"
}
bashrc() {
reload=true
# shellcheck disable=SC1090
. ~/.bashrc > /dev/null 2>&1
reload=false
}
cpg() {
if [ -d "$2" ]; then
cp "$1" "$2" && cd "$2" || return
else
cp "$1" "$2"
fi
}
pwdtail() {
pwd | awk -F/ '{nlast = NF -1;print $nlast"/"$NF}'
}
up() {
local d="" limit=$1
for ((i=1 ; i <= limit ; i++)); do
d=$d/..
done
d=$(echo $d | sed 's/^\///')
[[ -z "$d" ]] && d=..
cd "$d" || return
}
distribution() {
local dtype="unknown"
if [[ -r /etc/rc.d/init.d/functions ]]; then
# shellcheck disable=SC1091
. /etc/rc.d/init.d/functions
[[ zz"$(type -t passed 2>/dev/null)" == "zzfunction" ]] && \
dtype="redhat"
elif [[ -f /etc/arch-release ]]; then
dtype="arch"
elif [[ -r /etc/rc.status ]]; then
# shellcheck disable=SC1091
. /etc/rc.status
[[ zz"$(type -t rc_reset 2>/dev/null)" == "zzfunction" ]] && \
dtype="suse"
elif [[ -r /lib/lsb/init-functions ]]; then
# shellcheck disable=SC1091
. /lib/lsb/init-functions
[[ zz"$(type -t log_begin_msg 2>/dev/null)" == "zzfunction" ]] && \
dtype="debian"
elif [[ -r /etc/init.d/functions.sh ]]; then
# shellcheck disable=SC1091
. /etc/init.d/functions.sh
[[ zz"$(type -t ebegin 2>/dev/null)" == "zzfunction" ]] && \
dtype="gentoo"
elif [[ -s /etc/mandriva-release ]]; then
dtype="mandriva"
elif [[ -s /etc/slackware-version ]]; then
dtype="slackware"
fi
echo "$dtype"
}
ver() {
declare dtype
dtype="$(distribution)"
if [[ "$dtype" == "redhat" ]]; then
[[ -s /etc/redhat-release ]] && cat /etc/redhat-release && \
uname -a && return
cat /etc/issue && uname -a && return
fi
[[ "$dtype" == "suse" ]] && cat /etc/SuSE-release && return
[[ "$dtype" == "debian" ]] && lsb_release -a && return
[[ "$dtype" == "gentoo" ]] && cat /etc/gentoo-release && return
[[ "$dtype" == "mandriva" ]] && cat /etc/mandriva-release && return
[[ "$dtype" == "slackware" ]] && cat /etc/slackware-version && return
[[ -s /etc/issue ]] && cat /etc/issue && return
echo "Error: Unknown distribution" && exit 1
}
apachelog() {
[[ -f /etc/httpd/conf/httpd.conf ]] && \
cd /var/log/httpd && \
ls -xAh && multitail --no-repeat -c -s 2 \
/var/log/httpd/*_log && return
cd /var/log/apache2 && ls -xAh && multitail --no-repeat -c -s 2 \
/var/log/apache2/*.log && return
}
apacheconfig() {
[[ -f /etc/httpd/conf/httpd.conf ]] && \
sedit /etc/httpd/conf/httpd.conf && return
[[ -f /etc/apache2/apache2.conf ]] && \
sedit /etc/apache2/apache2.conf && return
echo "Error: Apache config file could not be found. \
Searching for possible locations:"
sudo updatedb && locate httpd.conf && locate apache2.conf
}
phpconfig() {
[[ -f /etc/php.ini ]] && sedit /etc/php.ini && return
[[ -f /etc/php/php.ini ]] && sedit /etc/php/php.ini && return
[[ -f /etc/php5/php.ini ]] && sedit /etc/php5/php.ini && return
[[ -f /usr/bin/php5/bin/php.ini ]] && \
sedit /usr/bin/php5/bin/php.ini && return
[[ -f /etc/php5/apache2/php.ini ]] && \
sedit /etc/php5/apache2/php.ini && return
echo "Error: php.ini file could not be found.\
Searching for possible locations:"
sudo updatedb && locate php.ini
}
mysqlconfig() {
[[ -f /etc/my.cnf ]] && sedit /etc/my.cnf && return
[[ -f /etc/mysql/my.cnf ]] && sedit /etc/mysql/my.cnf && return
[[ -f /usr/local/etc/my.cnf ]] && sedit /usr/local/etc/my.cnf && return
[[ -f /usr/bin/mysql/my.cnf ]] && sedit /usr/bin/mysql/my.cnf && return
[[ -f ~/my.cnf ]] && sedit ~/my.cnf && return
[[ -f ~/.my.cnf ]] && sedit ~/.my.cnf && return
echo "Error: my.cnf file could not be found.\
Searching for possible locations:"
sudo updatedb && locate my.cnf
}
rot13() {
if [[ $# -eq 0 ]]; then
tr 'a-mn-zA-MN-Z' 'n-za-mN-ZA-M'
else
echo "$@" | tr 'a-mn-zA-MN-Z' 'n-za-mN-ZA-M'
fi
}
trim() {
local var="$*"
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace chars
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace chars
echo -n "$var"
}
folderssort() {
find . -maxdepth 1 -type d -print0 | xargs -0 du -sk | sort -rn
}
ifconfig() {
declare colored
colored="$(color_form_output red 'ip a')"
echo "ifconfig is deprecated with net-tools pkg. use $colored"
}
ls_help() {
cat << End
ls -Al # show hidden files
ls -lX --ignore-backups # sort by extension (ls -lXB)
ls -lSr # sort by size
ls -lcr # sort by change time
ls -lur # sort by access time
ls -l --recursive # recursive (ls -lR)
ls -ltr # sort by date
ls -l | more' # pipe through 'more'
ls -xA # wide listing format
ls -ls # long listing format
ls -lp # alphabetical sort
ls -l | egrep -v '^d'" # files only (remove backslashes)
ls -l | egrep '^d'" # directories only (remove backslashes)
End
}
ping_help() {
cat << End ping='ping -c 5' fastping='ping -c 100 -i 0.2' ping8="ping 8.8.8.8"
End
}
chmod_help() {
cat << End
chmod a+x chmod -R 000 chmod -R 644 chmod -R 666 chmod -R 755 chmod -R 777
End
}
# alias mktar='tar -cvf'
# alias mkbz2='tar -cvjf'
# alias mkgz='tar -cvzf'
# alias untar='tar -xvf'
# alias unbz2='tar -xvjf'
# alias ungz='tar -xvzf'
# alias psmem='ps auxf | sort -nr -k 4'
# alias psmem10='ps auxf | sort -nr -k 4 | head -10'
# alias pscpu='ps auxf | sort -nr -k 3'
# alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
readonly -f light viewlines ex stats commit set_bash_prompt mcd wttr clock \
ftext cpg mvg up pwdtail distribution ver apachelog apacheconfig \
phpconfig mysqlconfig trim folderssort ifconfig color_colorful \
color_color_table color_form_output rot13 bashrc ls_help ping_help \
chmod_help
alias less="less --use-color" ls='sleep 1; ls -Fh --color=auto' cpuinfo='lscpu' \
grep='grep --color=auto' egrep='grep -E' fgrep='grep -F' \
cal="cal -m | pv -qL 10" ln='ln -i' cp='cp -i' df='df -h' \
chown='chown --preserve-root' chmod='chmod --preserve-root' \
chgrp='chgrp --preserve-root' rm='rm -ivI --preserve-root' \
scp='echo "use $(color_form_output red rsync)"' netstat='ss -v' \
iwconfig='iw --version' dig='drill -v' arp='echo "arp -> ip n"' \
nslookup='echo "nslookup -> drill or host"' \
iptunnel='echo "iptunnel -> ip t"' \
ipmaddr='echo "ipmaddr -> ip maddr"' nameif='echo "nameif -> ip l"' \
route='echo "route -> ip r"' mkdir='mkdir -pv' \
mount='mount | column -t' wget='wget -c' \
# alias np='nano -w PKGBUILD'
command -v sl &> /dev/null && alias clear='sl -adF; clear'
command -v bc &> /dev/null && alias bc='bc -l'
command -v less &> /dev/null && alias more='less'
command -v wget &> /dev/null && alias wget='wget -c'
command -v bc &> /dev/null && alias bc='bc -l'
command -v todo.sh &> /dev/null && alias todo='todo.sh -@ -+ -c -t -v'
command -v shellcheck &> /dev/null && alias shellcheck='shellcheck -C'
command -v cowsay &> /dev/null && alias cowsay='cowsay -d -W 80'
command -v cowsay &> /dev/null && command -v fortune &> /dev/null && \
command -v pv &> /dev/null && alias moo='fortune | cowsay | pv -qL 30'
command -v free &> /dev/null && alias free='free -h'
command -v systemctl &> /dev/null && alias poweroff='systemctl poweroff' \
halt='systemctl halt' reboot='systemctl reboot'
alias diskspace="du -S | sort -n -r | more" mountedinfo='df -hT' \
folders='du -h --max-depth=1' f="find . | grep " j='jobs -l' \
gpumeminfo='grep -i --color memory /var/log/Xorg.0.log' \
command -v free &> /dev/null && alias meminfo='free -l'
command -v tree &> /dev/null && alias tree='tree -CAhF --dirsfirst' \
treed='tree -CAFd'
[[ -f /var/log/Xorg.0.log ]] && alias \
gpumeminfo='grep -i memory /var/log/Xorg.0.log'
[[ -f /usr/bin/google-chrome-stable ]] && alias \
google-chrome='/usr/bin/google-chrome-stable %U'
[[ -f .bash_history ]] && alias \
h='cat .bash_history | sort | uniq -c | sort -nr'
[[ -f /etc/passwd ]] && alias pwrd='cat /etc/passwd | column -t -s ":"'
[[ -d "$HOME/.atom" ]] && alias atom='~/.atom/atom &'
declare -x LESS_TERMCAP_mb LESS_TERMCAP_md LESS_TERMCAP_me LESS_TERMCAP_ue \
LESS_TERMCAP_so LESS_TERMCAP_se LESS_TERMCAP_us LESS_TERMCAP_mr \
LESS_TERMCAP_mh LESS_TERMCAP_ZN LESS_TERMCAP_ZV LESS_TERMCAP_ZO \
LESS_TERMCAP_ZW
LESS_TERMCAP_mb=$(tput bold; tput setaf 2)
LESS_TERMCAP_md=$(tput bold; tput setaf 6)
LESS_TERMCAP_me=$(tput sgr0)
LESS_TERMCAP_ue=$(tput rmul; tput sgr0)
LESS_TERMCAP_so=$(tput bold; tput setaf 3; tput setab 4)
LESS_TERMCAP_se=$(tput rmso; tput sgr0)
LESS_TERMCAP_us=$(tput smul; tput bold; tput setaf 7)
LESS_TERMCAP_mr=$(tput rev)
LESS_TERMCAP_mh=$(tput dim)
LESS_TERMCAP_ZN=$(tput ssubm)
LESS_TERMCAP_ZV=$(tput rsubm)
LESS_TERMCAP_ZO=$(tput ssupm)
LESS_TERMCAP_ZW=$(tput rsupm)
export POSIXLY_CORRECT=true CLICOLOR=1 QT_SELECT=4 PYENV_ROOT="$HOME/.pyenv" \
PATH="/home/mb6ockatf/.local/share/gem/ruby/3.0.0/bin:$PATH" \
PATH="/opt/openresty/bin:$PATH" \
PATH="/home/mb6ockatf/.local/bin:$PATH" \
HISTFILESIZE=20000 HISTCONTROL=ignoreboth:erasedups \
PROMPT_COMMAND=set_bash_prompt BROWSER=/usr/bin/chromium EDITOR=vim \
GROFF_NO_SGR=1 # For Konsole and Gnome-terminal
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
bind -f ~/.inputrc
[[ "$(whoami)" != "root" && "$reload" != "true" ]] && moo
# rate.sx
# parrotsay
# rickroll: https://github.com/keroserene/rickrollrc
# curl -s -L \
# https://raw.githubusercontent.com/keroserene/rickrollrc/master/roll.sh | bash
# curl -s -L https://bit.ly/3zvELNz | bash