-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
501 lines (428 loc) · 15.5 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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
#
# /etc/bash.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
[[ $DISPLAY ]] && shopt -s checkwinsize
alias grep='grep --color=auto'
#usually i want to grep things ignored by git \rg if you dont
alias rg='rg --no-ignore'
alias ls='exa --group-directories-first'
alias ll='exa -l --group-directories-first'
alias ld='exa -dl */'
alias tree='tree -C'
#ive done this too many times
alias ':q'='exit'
#disable import being a valid command as it keeps calling imagemagik
alias 'import'=''
alias sume='sudo -E'
alias fucking='sudo'
#:yeet:
alias yeet='sudo'
alias yoot='sudo -E'
alias 'cd..'='cd ..'
alias bk='cd -'
alias gitwhat='git log -p -M --follow --stat --'
alias fpsteam='flatpak run com.valvesoftware.Steam'
alias cmaker='cmake -DCMAKE_BUILD_TYPE=Release ..'
alias cmaked='cmake -DCMAKE_BUILD_TYPE=Debug ..'
alias connected_mon='xrandr --query | grep " connected" | awk "{print \$1}"'
alias bn='LD_PRELOAD=libcurl.so.3 ~/binaryninja/binaryninja'
alias tdup='$(cd $(pwd); alacritty)&'
#kill bg tasks ignoring sigterm
alias kbg='kill -9 "$(jobs -p)"'
if [[ $EUID -eq 0 ]]; then
export PATH="$PATH:~/.local/bin:~/.cargo/bin"
else
#if youre not root as a fall back check current dir for command
export PATH="$PATH:~/.local/bin:~/.cargo/bin:."
fi
export EDITOR='nvim'
#include completion sources
[ -r /usr/share/bash-completion/bash_completion ] && . /usr/share/bash-completion/bash_completion
[ -r /usr/share/fzf/completion.bash ] && . /usr/share/fzf/completion.bash
export LANG=en_US.UTF-8
#this is to get around the fact that no one knows what termite is so ssh'ing is a pain
[[ $TERM != 'screen-256color' ]] && export TERM=xterm-256color
#[ -f /usr/bin/clang ] && export CC=/usr/bin/clang
#[ -f /usr/bin/clang++ ] && export CXX=/usr/bin/clang++
hash backup_tend 2>/dev/null && alias shutdown="backup_tend && shutdown"
#fuck that stupid Ctl-s bullshit
stty -ixon
#auto cd
shopt -s autocd
# **/* recurse
shopt -s globstar
#if we ran wall lets get dem colors
#(wal -r -t &)
#wal is too much im disabling it
#fzf is really rad everywhere may as well use rg here too
FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!.git/*"'
# ==> STOLEN FROM STACK OVERFLOW <==
# https://stackoverflow.com/a/19533853/5539918
# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
#cp image to clipboard
function cpi () {
xclip -selection clipboard -t image/png -i $1
}
#get the last scratch file or specify a range via line
function lastscratch () {
for F in $(find "$HOME/.vimscratch/" -type f | sort -r | line ${@:-1}); do
echo "scratch: $F"
cat "$F"
done
}
#is it raining
function rain () {
curl -s https://isitraining.in/vancouver | grep -oP '(?<=>)Yes|No(?=<)'
}
#slack formatting is dumb, this makes it less dumb
function slackfmt () {
sed -r 's/^/ /;s/^([ ]{4,})(.+)([0-9]{2}:[0-9]{2})/\2/;s/[ ]{4,}[0-9]{2}:[0-9]{2}//;s/^[ ]{5,}/ /;' | grep .
}
#new changes reload
function reloadterm () {
killall -USR1 termite
}
#what the weather currently is
function weather () {
curl wttr.in
}
#find leetspeekable names from text data
function leetify () {
grep -oP '^([0-9a-fots]|(?<!i)l|(?<!l)i){4,7}$' | sort -R | head -n 25 | tee ~/tmp | tr 'aeolits' '4301175' | tr a-z A-Z > ~/tmp2 && paste -d"\t" ~/tmp ~/tmp2 && rm ~/tmp ~/tmp2
}
#change filenames to be only sane characters
function mvsane () {
for F in "$@"
do
FP=$(realpath -- "$F")
BN=$(basename -- "$FP")
BP=$(dirname -- "$FP")
NN="${BP}/$(sed -r 's/[ ]+/_/g;s/[^a-zA-Z0-9_.-]//g;s/[_-]{2,}/-/g;s/(^[ _-]+|[ _-]+$)//g' <<< \"${BN}\")"
[ "$FP" != "$NN" ] && mv -T -- "$FP" "$NN"
done
}
#change access permissions to be only sane permissions
function chmodsane () {
find "$1" -type d -exec chmod 755 {} \;
find "$1" -type f -exec chmod 644 {} \;
}
#change access permissions to be only sane permissions
function chgrpsane () {
chgrp -R "$1" "$2"
find "$2" -type d -exec chmod 775 {} \;
find "$2" -type f -exec chmod 664 {} \;
}
#thanks to john saying this:
# [15:51] john_a_macdonald: Oh fuck off
# The only worse option is mixing the digits
# I prefer listing dates as YDYY-MD-MY
#i made it a thing
function bestdate () {
date '+%Y-%m-%d' | sed -r 's/(.)(.)(.)(.)-(.)(.)-(.)(.)/\1\7\3\4-\5\8-\6\2/'
}
#test truecolor support (youll know if it doesnt work)
function truecolortest () {
awk 'BEGIN{
s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
for (colnum = 0; colnum<77; colnum++) {
r = 255-(colnum*255/76);
g = (colnum*510/76);
b = (colnum*255/76);
if (g>255) g = 510-g;
printf "\033[48;2;%d;%d;%dm", r,g,b;
printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
printf "%s\033[0m", substr(s,colnum+1,1);
}
printf "\n";
}'
}
#thanks to this https://gist.github.com/timperez/7892680 im adding whoisport
function whoisport () {
port=$1
pidInfo=$(fuser $port/tcp 2> /dev/null)
pid=$(echo $pidInfo | cut -d':' -f2)
ls -l /proc/$pid/exe
}
#useful for debugging with binding with strace or whatever to a running process
#starts a process stopped
function startstopped () {
( kill -SIGSTOP $BASHPID; exec $@ ) &
}
#lets it continue
function resumestopped () {
kill -SIGCONT $(jobs -l | grep '( kill -SIGSTOP $BASHPID; exec $@ )' | awk '{print $2}')
}
#convert files to shellcode escaped strings
function shellencode () {
for F in "$@"
do
printf '"' && xxd -g 0 "$F" | awk '{print $2}' | fold -w2 | awk '{print "\\x" $1}' | tr -d '\n' && echo '"'
done
}
#do it a bunch
function repeat () {
local i max
max=$1; shift;
for ((i=1; i <= max ; i++)); do
eval "$@";
done
}
#gets random hex data by number of lines and number per line
function hexlines () {
lin=$1
wid=$2
if [ $(($wid%2)) -eq 0 ]; then
head -c $(($lin * $wid / 2)) /dev/urandom | xxd -g0 -| awk '{print $2}' | tr -d '\n' | fold -w$wid && echo
else
head -c $(($lin * $(($wid / 2 + 1)))) /dev/urandom | xxd -g0 -| awk '{print $2}' | tr -d '\n' | fold -w$wid | head -n $lin
fi
}
#for testing ricing colors
alias colortest="echo use bettercolor instead"
#check ~/.local/bin/crazy.c for the version now in use
#function cRaZy () {
# fold -w1 | awk 'NR % 2 == 1 {print toupper($0)}; NR % 2 == 0 {print tolower($0)}' | tr -d '\n'
#}
function localscan () {
arp-scan --interface=$(ip link | grep 2 | awk '{print $2}' | tr -d ':') -l
}
function fine () {
sed -r 's/(.)/\1 /g;s/(.*) /`\1`/g;'
}
function sofine () {
sed -r 's/(.)/\1 /g;s/(.*) /_\*\*`\1`\*\*_/g;'
}
#honestly why is this not built in...
#sum ints one per line
#check ~/.local/bin/total.c for the version now in use
#function total () {
# awk '{s+=$1} END {print s}'
#}
#this automatically generates index.html files for the entire current directory
#note the grep for exclusion is because the built in affects the output
#also yes im fixing the CSS colors with sed, if you can get LS_COLORS to work you better open a PR
function mkhtmltree () {
find . -type d -exec bash -c "cd {}; tree --dirsfirst --du --prune -DhHC . | grep -v 'index.html' | sed -r '0,/(\.NORM.*)black/{s/(\.NORM.*)black/\1blue/};0,/(\.DIR.*)blue/{s/(\.DIR.*)blue/\1black/};s/\"([^\"]*\.(png|jpg))\">([^<]*)/\"\1\"><img src=\"\1\" height=\"200\">/g' > index.html" \;
}
function autoindex () {
title=$(basename "$PWD")
echo "<html><head><title>$title</title><style type=\"text/css\">body{margin:40px auto;color:#444;padding:0 10px}h1{text-align: center};h1,h2,h3{line-height:1.2}</style></head><body><h1>$title</h1><hr/>" > index.html
folders=$(find . -maxdepth 1 -type d | sort)
if [ "$(wc -l <<< "$folders")" -gt "1" ]; then
echo "<h2>Folders</h2><hr/><ul>" >> index.html
while IFS= read -r d
do
[ "$d" == "." ] && continue
echo "<li><a href=\"$d\">${d#./}</a></li>" >> index.html
(cd "$d"; autoindex)
done <<< "$folders"
echo "</ul>" >> index.html
fi
files=$(find . -maxdepth 1 -type f | sort)
if [ $(wc -l <<< "$files") != "0" ]; then
echo "<h2>Files</h2><hr/><table><tr><th>Bytes</th><th>File Name</th></tr>" >> index.html
while IFS= read -r f
do
[ "$f" == "./index.html" ] && continue
echo "<tr><td>$(stat -c '%s' "$f")</td><td><a href=\"$f\">${f#./}</a></td>" >> index.html
done <<< "$files"
echo "</table>" >> index.html
fi
echo "</body></html>" >> index.html
}
#generate documentation comments for c
function mkcdoc () {
for F in "$@"
do
sed -rf ~/.local/sed/mkcdoc.sed -i $F
done
}
#generate documentation comments for asm
function mksmdoc () {
for F in "$@"
do
sed -rf ~/.local/sed/mkasmdoc.sed -i $F
done
}
function sedcheat () {
echo '==>sed quick guide<==
: # label
= # line_number
a # append_text_to_stdout_after_flush
b # branch_unconditional
c # range_change
d # pattern_delete_top/cycle
D # pattern_ltrunc(line+nl)_top/cycle
g # pattern=hold
G # pattern+=nl+hold
h # hold=pattern
H # hold+=nl+pattern
i # insert_text_to_stdout_now
l # pattern_list
n # pattern_flush=nextline_continue
N # pattern+=nl+nextline
p # pattern_print
P # pattern_first_line_print
q # flush_quit
r # append_file_to_stdout_after_flush
s # substitute
t # branch_on_substitute
w # append_pattern_to_file_now
x # swap_pattern_and_hold
y # transform_chars '
}
#sometimes you need to diff binary files, this makes it easy
function bdiff () {
if [ $# -ne 2 ]
then
echo "usage: bdiff file1 file2"
else
diff --color=auto -c --label "$1" --label "$2" <(xxd "$1") <(xxd "$2")
fi
}
#dont ask me why i needed this, but it gets all the links in a page seperated by newlines
function linkrip () {
sed -r 's/(href=")([^"]*)"/\n"\2"\n/' | grep -Po '^".*"$' | tr -d '"'
}
#all my v4 ips on all up interfaces
function allv4 () {
ip addr show up | grep -v 'lo$' | grep 'inet ' | awk '{print $2}'
}
function batstat () {
for B in /sys/class/power_supply/BAT*
do
if [ -f "$B/capacity" ]; then
echo "[$B]"
printf "capacity: "
cat "$B/capacity"
printf "status: "
cat "$B/status"
fi
done
}
# :3
function exit () {
eval $BASH_COMMAND
}
# select a saved session and open it
function nvimp() {
VCMD=$(command -v nvim &>/dev/null && echo nvim || echo vim)
if [ $VCMD == "nvim" ]; then
VFL="$HOME/.local/share/nvim/session"
else
VFL="$HOME/.vim/session"
fi
FILE=$(find $VFL -type f | fzf +m -1)
if [ -n "$FILE" ]; then
VCD=$(grep -Em 1 'cd ' "$FILE")
if [ -n "$VCD" ]; then
${VCD//\~/$HOME}
fi
$VCMD
fi
}
#sometimes you just need to reload it all
function usb_knockknock() {
sudo udevadm control --reload-rules
sudo udevadm trigger -v
}
#for when you dont want any [redacted]
function redact_anime() {
sed -r 's/[aA]+(.*)?[nN]+([^a-zA-Z]+|\1)?[1liI]+([^a-zA-Z]+|\1)?[mM]+([^a-zA-Z]+|\1)?[eEuU3]+/[redacted]/ig'
}
#the above spawned the following
#this generates out a regex like above from a given word
function censor_regex() {
sed -r 's/([a-z])/[\1]+(.*)?/;:a;/[^a-z][a-z]$/{s/(.*)([a-z])$/\1[\2]+/;q};s/(^.*[^a-z])([a-z])/\1[\2]+([^a-z]+|\\1)?/g;ta'
}
#i cant stand /**/ comments, this converts them to // style as best as it can
function fix_comments() {
sed -r ':s;/\/\*/{:g;N;/\*\//{s/(.*)/\/\/\1/g;s/(\/\*|\*\/)//g;s/\n\s*\*/\n/g;s/\n/\n\/\//g;s/(^|\n)\s+\n//g;s/^[\s\/\n]*(\/\/)/\1/g;bs};bg}'
}
#in place removal of anything nonprintable inspired by https://xkcd.com/2143/
function asciionly() {
tmp=$(tr -d "\0" < "$1")
cat <<< "${tmp//[^ -~]}" > "$1"
}
alias clap="sed -r 's/\\s+/ :clap: /g'"
#extract an sql connection string for use manually
function mysqlconf() {
sed -r 's#^.*?mysql://([^:]+):([^@]+)\@([^/]+)/([a-zA-Z0-9_-]+).*?$#mysql -u\1 -p\2 -h\3 \4#g;tg;d;:g;' | sort | uniq
}
#god forbid you ever need this but it turns numbers into their ordinal counterparts ie 1st, 2nd, 3rd, 11th, 21st,...
function ordinal() {
sed -r 's/(^|[^0-9]|[02-9])1( |$)/\11st\2/g;s/(^|[^0-9]|[02-9])2( |$)/\12nd\2/g;s/(^|[^0-9]|[02-9])3( |$)/\13rd\2/g;s/(^|[^0-9]|[0-9])?([0-9])( |$)/\1\2th\3/g'
}
function mvmanual () {
for F in "$@"
do
FP=$(realpath -- "$F")
BN=$(basename -- "$FP")
BP=$(dirname -- "$FP")
TMP_FILE=$(mktemp)
cat -- > "${TMP_FILE}" <<< "${BN}"
nvim "${TMP_FILE}"
NN=$(<"${TMP_FILE}")
rm "${TMP_FILE}"
NP="${BP}/$NN"
[ "$FP" != "$NP" ] && mv -T -- "$FP" "$NP"
done
}
function markws() {
newname="${1:-$(basename $(pwd))}"
num="$(i3-msg -t get_workspaces|jq '.[]|select(.focused==true).num')"
i3-msg "rename workspace to \"${num}: $newname\"" 1>/dev/null 2>/dev/null
}
#alias mpvf='mpv "$(fzf)"'
function mpvf () {
if [ "$1" != "" ]; then
file="$(fzf -1 -q $1)"
else
file="$(fzf)"
fi
if [ "$file" != "" ]; then
echo "opening $file"
mpv "$file"
fi
}
function cdf () {
dir=$(exa --no-quotes --color=never -D | fzf)
if [ "$dir" != "" ]; then
cd "$dir"
fi
}
#it's a pain to pull the cn out of openvpn configs. this does the whole thing
function ovpncn() {
openssl x509 -in <(sed -rn '/<cert>/,/<\/cert/{/<\/?cert>/d;p}' < $1) -text | grep -o 'Issuer.*'
}
#moved this to the bottom because it breaks syntax highlighting bad
__last_cmd="[ \$? == 0 ]&&printf '\[\e[32m\]^_^'||printf '\[\e[31m\]o_o'"
# restriction being needs git 1.6.3 or newer
__git_ps1='git rev-parse --abbrev-ref HEAD 2>/dev/null||printf "-"'
#this is so that the working dir goes red if the fs doesnt match the root as an indicator of risk otherwise its yellow
__same_fs="[ \"$(df --output=source /)\" == \"\$(df --output=source .)\" ]&&printf '\[\e[33m\]'||printf '\[\e[31m\]'"
#this way we can add things to an ignore list that we dont want notifications about
function __send_real () {
cmd="$(HISTTIMEFORMAT="" history 1|tr -s ' '|cut -d' ' -f2-)"
grep -q "$(cut -d' ' -f1 <<< "$cmd")" ~/.bash_ignore || notify-send -t 5000 "Command Finished" "$cmd"
}
#notify the user if any command has taken more than 120 seconds to complete (false positives if you leave your terminal hanging, press enter to refresh the timer)
PROMPT_COMMAND=$'__lastran="${__now:-$(date +%s)}";__now=$(date +%s);[ $(expr ${__now} - ${__lastran}) -gt 120 ]&&[ "${__lastchecked}" != "$(history 1)" ]&&__send_real;__lastchecked=$(history 1)'
#__hostname_hash=$(sha256sum < /etc/hostname)
#__hostname="$(printf '\033[48;2;%d;%d;%dm\033[38;2;%d;%d;%dm%s\033[0m' 0x${__hostname_hash:26:2} 0x${__hostname_hash:28:2} 0x${__hostname_hash:30:2} $(( 255 - 0x${__hostname_hash:26:2} )) $(( 255 - 0x${__hostname_hash:28:2} )) $(( 255 - 0x${__hostname_hash:30:2} )) $(</etc/hostname))"
__hostname="$(lumen -a -t $(</etc/hostname))"
PS1="\e[m\]\e[37m\]\$(${__last_cmd})\[\e[34m\]\D{%T}\[\e[35m\]\$(${__git_ps1})\[\e[36m\]\u\[\e[m\]@${__hostname}\]:\$(${__same_fs})\W\n\[\e[37m\]\[\e[m\]> "
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a;$PROMPT_COMMAND"