-
Notifications
You must be signed in to change notification settings - Fork 12
/
.functionsrc
623 lines (533 loc) · 19.4 KB
/
.functionsrc
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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# ~/.functionsrc
# Defines functions for Bash/Zsh.
# Invoked by .bash_profile file.
# COMMON FUNCTIONS
# Realpath to provide absolute path with OSX
# See: http://stackoverflow.com/questions/3572030/bash-script-absolute-path-with-osx
realpath () {
[[ "$1" = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
# Change dir recursively via find.
# Note: It's basically the same as: cd **/dir when globstar is enabled.
# Usage: cdf (dir)
cdf() {
pushd "$(find . -name "$1")"
}
# Find files/dirs by name recursively.
# Usage: ff (file)
f() {
find . -name "*$1*"
}
# Find file by exact name recursively.
# Usage: ff (file)
ff() {
find . -name "$1"
}
# Search for pattern in UTF-16 files with Ruby.
# Usage: grep16 PATTERN file.txt
grep16() {
ruby -e "puts File.open('$2', mode:'rb:BOM|UTF-16LE').readlines.grep(Regexp.new '$1'.encode(Encoding::UTF_16LE))";
}
# Find recursively and edit the file in Vim.
# Note: It's basically the same as: vim **/file when globstar is enabled.
# Usage: ff (file)
vimf() {
vim "$(find . -name "*$1*")"
}
# Allows you to search for any text in any file recursively.
# Usage: ft "my string" *.php
ft() {
find . -name "$2" -exec grep -il "$1" {} \;
}
# Find duplicate files.
# Usage: dups (dir)
dups() {
fdupes -v && fdupes -rS1 "$1" | sed '$!N;s/\n/ /' | sort -n
}
# Search for command in history.
# Usage: hs (string)
hs() {
history | grep -- "$1"
}
# Trace mysqld for queries
# Usage: dmysql
dmysql() {
sudo dtruss -t read -fn mysqld 2>&1 | grep -Eo '[A-Z]{4}[^"]+'
}
# Trace apache
# Usage: dapache
dapache() {
sudo dtruss -fn httpd
}
# Trace apache files
# Usage: dapache-files
dapache-files() {
sudo dtruss -t open -fn httpd 2>&1 | grep -o '".*"' | grep -o '[^"].*\\'
}
# Strip trailing whitespaces.
# Usage: trim *.*
# See: http://stackoverflow.com/q/149057/55075
#trim() {
# ex +'bufdo!%s/\s\+$//e' -cxa $*
#}
# Convert tabs to spaces.
# Usage: retab *.*
# See: http://stackoverflow.com/q/11094383/55075
#retab() {
# ex +'set ts=2' +'bufdo retab' -cxa $*
#}
# Archive the page in Wayback Machine.
# Usage: archive http://example.com/
archive() {
for url in $*; do curl -vs http://web.archive.org/save/$url | tail; done
}
# Extract most know archives
# Usage: extract (file)
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $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 extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
# Uncompress zlib data (e.g. git objects)
# Usage: deflate (file)
deflate() {
printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" | cat -- - $1 | gunzip
}
# Convert PDFs into a simple HTML file.
# Usage: pdftotext-all (dir)
pdftotext-all() {
find "${1:-.}" -name "*.pdf" -execdir [ ! -f "{}.txt.html" ] ';' -print0 | xargs -0 -t -I% -P8 pdftotext -htmlmeta "%" "%.txt.html"
}
# Convert svn branches and tags into git.
# Usage: svn2git
# See: http://stackoverflow.com/q/2244252/55075
svn2git() {
git svn fetch --all # Fetch all remote branches that have not been fetched yet.
git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags \
| while read BRANCH REF
do
TAG_NAME=${BRANCH#*/}
BODY="$(git log -1 --format=format:%B $REF)"
echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2
git tag -a -m "$BODY" $TAG_NAME $REF^ && \ # Create git tag from tag branch.
git branch -r -d $BRANCH # Delete tag branch.
done
}
# Convert video to gif file.
# Usage: video2gif video_file (scale) (fps)
video2gif() {
ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
rm "${1}.png"
}
# Resize video.
# Usage: video-resize (file) (scale)
video-resize() {
ffmpeg -y -i "${1}" -vf scale=854:${2:-320} "${1%.*}.resized.${1##*.}"
}
#
# Compare two binary files.
# Usage: diffhex file1 file2
# See: http://superuser.com/a/968863/87805
diffhex() {
diff -y -W200 <(xxd -l1000 "$1") <(xxd -l1000 "$2") | colordiff
}
# Compare two binary files.
# Usage: open-rdp ip-address
open-rdp() {
open rdp://full%20address=s:$*
}
# GitHub clone all user repositories.
# Usage: gh-clone-user (user)
gh-clone-user() {
curl -sL "https://api.github.com/users/$1/repos?per_page=1000" | jq -r '.[]|.clone_url' | xargs -L1 git clone --recurse-submodules
}
# GitHub clone all user private repositories.
# Usage: gh-clone-user-priv (user)
gh-clone-user-priv() {
type jq >/dev/null || return
[ -z "$GITHUB_API_TOKEN" ] && { echo "Error: Define GITHUB_API_TOKEN."; return; }
curl -sL "https://api.github.com/users/$1/repos?access_token=$GITHUB_API_TOKEN&per_page=1000&type=private" | jq -r '.[]|.clone_url' | xargs -L1 git clone --recurse-submodules
}
# Updates list of proxies.
# Usage: update-proxies (file)
proxy-update-list() {
proxy_db=${1:-~/.proxies.db}
list_url=$(curl -Ls "http://www.live-socks.net/$(date +%Y)/$(date +%m)/" | grep -om1 http://.*socks-5-servers.html)
curl -s "$list_url" | grep "^[0-9].*:[0-9]\+" | tee -a $proxy_db &>/dev/null
sort -uo $proxy_db $proxy_db
}
# Find valid proxy from the list.
# Usage: proxy-find (file)
proxy-find() {
proxy_db=${1:-~/.proxies.db}
while true; do
proxy_ip="$(shuf -n1 $proxy_db)"
curl -m5 -sqfx socks5://$proxy_ip http://example.com/ &>/dev/null
if [[ "$?" -eq 0 ]]; then
if curl -m5 -sqfx socks5://$proxy_ip http://example.com/ | grep -qw Example; then
break;
fi
fi
[ -n "$proxy_ip" ] && ex +"g/$proxy_ip/d" -scwq! $proxy_db
done
echo $proxy_ip
}
# Curl with proxy.
# Usage: curl-proxy
curl-proxy() {
curl -x "socks5://$(proxy-find)" "$@"
}
# CRYPTO FUNCTIONS
# Based on https://github.com/k4m4/cryptocurrency-address-detector
find-bitcoin-public() {
rg -w '(bc1|[13])[a-km-zA-HJ-NP-Z1-9]{25,39}' $@
}
find-bitcoin-private() {
# BIP38 Encrypted Private Key.
local bip38='6P[a-km-zA-HJ-NP-Z1-9]{56}'
# WIF Private key, uncompressed public keys.
local wif_plain_pub='5[a-km-zA-HJ-NP-Z1-9]{50}'
# WIF Private key, compressed public keys.
local wif_com_pub='[KL][a-km-zA-HJ-NP-Z1-9]{51}'
# BIP32 HD wallet private node.
local bip32_xprv='xprv[a-km-zA-HJ-NP-Z1-9]{107,108}'
# BIP32 HD wallet public node.
local bip32_xpub='xpub[a-km-zA-HJ-NP-Z1-9]{107,108}'
# See: https://gist.github.com/chriswcohen/7e28c95ba7354a986c34
rg -w -e '[0-9A-F]{64}' -e ${bip38} -e ${wif_plain_pub} -e ${wif_com_pub} -e ${bip32_xprv} -e ${bip32_xpub} $@
}
find-bitcoincash-public() {
rg -w -e '[13][a-km-zA-HJ-NP-Z1-9]{33}' -e '((bitcoincash|bchreg|bchtest):)?(q|p)[a-z0-9]{41}' $@
}
find-dash-public() {
rg -w 'X[1-9A-HJ-NP-Za-km-z]{33}' $@
}
find-dogecoin-public() {
rg -w 'D{1}[5-9A-HJ-NP-U]{1}[1-9A-HJ-NP-Za-km-z]{32}' $@
}
find-ethereum-public() {
rg -w '0x[a-fA-F0-9]{40}' $@
}
find-litecoin-public() {
rg -w '[LM3][a-km-zA-HJ-NP-Z1-9]{26,33}' $@
}
find-monero-public() {
rg -w '4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}' $@
}
find-neo-public() {
rg -w 'A[0-9a-zA-Z]{33}' $@
}
find-ripple-public() {
rg -w 'r[0-9a-zA-Z]{24,34}' $@
}
get-crypto-balance() {
# Supported blockains: btc, ltc, bcy, doge.
# Supported networks: main, test, test3.
# Notes: Another API: https://blockchair.com/api/docs
curl -s https://api.blockcypher.com/v1/${2:-btc}/${3:-main}/addrs/$1/balance ${@:4}
}
# CACHE & SWAP
# Create a swap file and activate it.
mk-swap-file() {
set -x
swapfile=${1:-swapfile}
size=${2:-10g}
test -f "$swapfile" && return
sudo truncate -s 0 "$swapfile"
sudo chattr +C "$swapfile"
sudo fallocate "$swapfile" -l "$size"
sudo chmod 600 "$swapfile"
sudo mkswap "$swapfile"
sudo swapon "$swapfile"
}
# MYSQL FUNCTIONS
# Create user in MySQL/MariaDB.
mysql-create-user() {
[ -z "$2" ] && { echo "Usage: mysql-create-user (user) (password)" >&2; return; }
mysql -ve "CREATE USER '$1'@'localhost' IDENTIFIED BY '$2'"
}
# Delete user from MySQL/MariaDB
mysql-drop-user() {
[ -z "$1" ] && { echo "Usage: mysql-drop-user (user)" >&2; return; }
mysql -ve "DROP USER '$1'@'localhost';"
}
# Create new database in MySQL/MariaDB.
mysql-create-db() {
[ -z "$1" ] && { echo "Usage: mysql-create-db (db_name)" >&2; return; }
mysql -ve "CREATE DATABASE IF NOT EXISTS $1"
}
# Drop database in MySQL/MariaDB.
mysql-drop-db() {
[ -z "$1" ] && { echo "Usage: mysql-drop-db (db_name)" >&2; return; }
mysql -ve "DROP DATABASE IF EXISTS $1"
}
# Grant all permissions for user for given database.
mysql-grant-db() {
[ -z "$2" ] && { echo "Usage: mysql-grand-db (user) (database)" >&2; return; }
mysql -ve "GRANT ALL PRIVILEGES ON $2.* TO '$1'@'localhost'"
mysql -ve "FLUSH PRIVILEGES"
}
# Show current user permissions.
mysql-show-grants() {
[ -z "$1" ] && { echo "Usage: mysql-show-grants (user)" >&2; return; }
mysql -ve "SHOW GRANTS FOR '$1'@'localhost'"
}
# Show all variables.
mysql-show-variables() {
mysql -sve "SHOW VARIABLES LIKE '%$1%'"
}
# Show error log.
mysql-show-errorlog() {
sudo tail -f $(mysql -Nse "SELECT @@log_error")
}
# Filters 2-3 words.
rg-23w() {
rg -o '(\w{3,30})\W+(\w{3,30})\W+(\w{3,30})' \
-r "$(printf '$1 $2\n$2 $3\n$1 $2 $3')"
}
# Filters 2-4 words.
rg-234w() {
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2\n$2 $3\n$3 $4\n$1 $2 $3\n$2 $3 $4\n$1 $2 $3 $4')"
}
# Filters 2-5 words.
rg-2345w() {
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2\n$2 $3\n$3 $4\n$4 $5\n$1 $2 $3\n$2 $3 $4\n$3 $4 $5\n$1 $2 $3 $4\n$2 $3 $4 $5\n$1 $2 $3 $4 $5')"
}
# Filters 3-6 words.
rg-3456w() {
rg -o '(\w{2,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2 $3\n$2 $3 $4\n$3 $4 $5\n$4 $5 $6\n$1 $2 $3 $4\n$2 $3 $4 $5\n$3 $4 $5 $6\n$1 $2 $3 $4 $5\n$2 $3 $4 $5 $6\n$1 $2 $3 $4 $5 $6')"
}
# Filters 3-7 words.
rg-34567w() {
rg -o '(\w{2,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2 $3\n$2 $3 $4\n$3 $4 $5\n$4 $5 $6\n$5 $6 $7\n$1 $2 $3 $4\n$2 $3 $4 $5\n$3 $4 $5 $6\n$4 $5 $6 $7\n$1 $2 $3 $4 $5\n$2 $3 $4 $5 $6\n$3 $4 $5 $6 $7\n$1 $2 $3 $4 $5 $6\n$2 $3 $4 $5 $6 $7\n$1 $2 $3 $4 $5 $6 $7')"
}
# Filters 3-8 words.
rg-345678w() {
rg -o '(\w{2,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2 $3\n$2 $3 $4\n$3 $4 $5\n$4 $5 $6\n$5 $6 $7\n$6 $7 $8\n$1 $2 $3 $4\n$2 $3 $4 $5\n$3 $4 $5 $6\n$4 $5 $6 $7\n$5 $6 $7 $8\n$1 $2 $3 $4 $5\n$2 $3 $4 $5 $6\n$3 $4 $5 $6 $7\n$4 $5 $6 $7 $8\n$1 $2 $3 $4 $5 $6\n$2 $3 $4 $5 $6 $7\n$3 $4 $5 $6 $7 $8\n$1 $2 $3 $4 $5 $6 $7\n$2 $3 $4 $5 $6 $7 $8\n$1 $2 $3 $4 $5 $6 $7 $8')"
}
# Filters 3-9 words.
rg-3456789w() {
rg -o '(\w{2,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{1,20})\W+(\w{2,20})' \
-r "$(printf '$1 $2 $3\n$2 $3 $4\n$3 $4 $5\n$4 $5 $6\n$5 $6 $7\n$6 $7 $8\n$7 $8 $9\n$1 $2 $3 $4\n$2 $3 $4 $5\n$3 $4 $5 $6\n$4 $5 $6 $7\n$5 $6 $7 $8\n$6 $7 $8 $9\n$1 $2 $3 $4 $5\n$2 $3 $4 $5 $6\n$3 $4 $5 $6 $7\n$4 $5 $6 $7 $8\n$5 $6 $7 $8 $9\n$1 $2 $3 $4 $5 $6\n$2 $3 $4 $5 $6 $7\n$3 $4 $5 $6 $7 $8\n$4 $5 $6 $7 $8 $9\n$1 $2 $3 $4 $5 $6 $7\n$2 $3 $4 $5 $6 $7 $8\n$3 $4 $5 $6 $7 $8 $9\n$1 $2 $3 $4 $5 $6 $7 $8\n$2 $3 $4 $5 $6 $7 $8 $9\n$1 $2 $3 $4 $5 $6 $7 $8 $9')"
}
# Filters all words.
rg-all-words() {
tee >/dev/null >(rg-23w) >(rg-234w) >(rg-2345w) >(rg-3456w) >(rg-34567w) >(rg-345678w) >(rg-3456789w)
}
# Filters all words (v2).
rg-all-words2() {
pee \
'rg -o "\w+(\W\w+){1}"' 'rg -o "\S+(\s\S+){1}"' \
'rg -o "\w+(\W\w+){2}"' 'rg -o "\S+(\s\S+){2}"' \
'rg -o "\w+(\W\w+){3}"' 'rg -o "\S+(\s\S+){3}"' \
'rg -o "\w+(\W\w+){4}"' 'rg -o "\S+(\s\S+){4}"' \
'rg -o "\w+(\W\w+){5}"' 'rg -o "\S+(\s\S+){5}"' \
'rg -o "\w+(\W\w+){6}"' 'rg -o "\S+(\s\S+){6}"' \
'rg -o "\w+(\W\w+){7}"' 'rg -o "\S+(\s\S+){7}"' \
'rg -o "\w+(\W\w+){8}"' 'rg -o "\S+(\s\S+){8}"' \
'rg -o "\w+(\W\w+){9}"' 'rg -o "\S+(\s\S+){9}"' \
'rg -o "\w+(\W\w+){10}"' 'rg -o "\S+(\s\S+){10}"' \
'rg -o "\w+(\W\w+){11}"' 'rg -o "\S+(\s\S+){11}"' \
'rg -o "\w+(\W\w+){12}"' 'rg -o "\S+(\s\S+){12}"' \
'rg -o "\w+(\W\w+){13}"' 'rg -o "\S+(\s\S+){13}"' \
'rg -o "\w+(\W\w+){14}"' 'rg -o "\S+(\s\S+){14}"'
}
# Filters 2 words.
rg-perm-2w() {
rg_r_arg="$(crunch 2 2 12 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 2 words with punctuations.
rg-perm-2w-punct() {
rg -o '(\w{2,20})\W+(\w{2,20})' \
-r "$(crunch 7 7 + + 12 ' !@%&*-_=+:,|.' -t '${%}^$%' 2>/dev/null)"
}
# Permutate 3 words.
rg-perm-3w() {
rg_r_arg="$(crunch 3 3 123 -p 123 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 3 words with punctuations.
rg-perm-3w-punct() {
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$(crunch 12 12 + + 123 ' ,-+=<>;|' -t '${%}^${%}^$%' 2>/dev/null)"
}
# Permutate 4 words.
rg-perm-4w() {
rg_r_arg="$(crunch 4 4 1234 -p 1234 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 5 words.
rg-perm-5w() {
rg_r_arg="$(crunch 5 5 12345 -p 12345 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 6 words.
rg-perm-6w() {
rg_r_arg="$(crunch 5 5 123456 -p 123456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 5 words into 3.
rg-perm-5w-to-3w() {
rg_r_arg="$(crunch 3 3 234 -p 234 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 5 words into 4.
rg-perm-5w-to-4w() {
rg_r_arg="$(crunch 4 4 1234 -p 1234 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 6 words into 3.
rg-perm-6w-to-3w() {
rg_r_arg="$(crunch 3 3 234 -p 234 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 6 words into 4.
rg-perm-6w-to-4w() {
rg_r_arg="$(crunch 4 4 1234 -p 1234 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 6 words into 5.
rg-perm-6w-to-5w() {
rg_r_arg="$(crunch 5 5 12345 -p 12345 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 7 words into 3.
rg-perm-7w-to-3w() {
rg_r_arg="$(crunch 3 3 123 -p 123 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 7 words into 4.
rg-perm-7w-to-4w() {
rg_r_arg="$(crunch 4 4 2345 -p 2345 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 7 words into 5.
rg-perm-7w-to-5w() {
rg_r_arg="$(crunch 5 5 23456 -p 23456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 7 words into 6.
rg-perm-7w-to-6w() {
rg_r_arg="$(crunch 5 5 123456 -p 123456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 8 words into 3.
rg-perm-8w-to-3w() {
rg_r_arg="$(crunch 3 3 345 -p 345 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 8 words into 4.
rg-perm-8w-to-4w() {
rg_r_arg="$(crunch 4 4 3456 -p 3456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 8 words into 5.
rg-perm-8w-to-5w() {
rg_r_arg="$(crunch 5 5 34567 -p 34567 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 8 words into 6.
rg-perm-8w-to-6w() {
rg_r_arg="$(crunch 6 6 234567 -p 234567 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 9 words into 3.
rg-perm-9w-to-3w() {
rg_r_arg="$(crunch 6 6 456 -p 456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 9 words into 4.
rg-perm-9w-to-4w() {
rg_r_arg="$(crunch 4 4 3456 -p 3456 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 9 words into 5.
rg-perm-9w-to-5w() {
rg_r_arg="$(crunch 4 4 34567 -p 34567 2>/dev/null | sed -E 's/([0-9])/$\1/g;s/([0-9])\$/\1 \$/g')"
rg -o '(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})\W+(\w{2,20})' \
-r "$rg_r_arg"
}
# Permutate 9 words into 5 using perl.
perl-perm-9w-to-5w() {
perl -MList::Util=shuffle -alne '
my %seen;
# Repeat for 10000 variations.
for (1..10000) {
# Shuffle and select 5 words.
@words = (shuffle(@F))[0..4];
# Join the words into a string.
$combo = join(" ", @words);
# Skip if already seen.
next if $seen{$combo}++;
# Print if its a new combination.
print $combo;
}
'
}
# Permutate 3-6 words.
rg-perm-345w() {
tee >(rg-perm-3w) >(rg-perm-4w) >(rg-perm-5w) >/dev/null
}
# Permutate 3-6 words.
rg-perm-3456w() {
tee >(rg-perm-3w) >(rg-perm-4w) >(rg-perm-5w) >(rg-perm-6w) >/dev/null
}
# Permutate 3-5 words.
rg-perm-56789w-to-34w() {
tee \
>(rg-perm-5w) \
>(rg-perm-5w-to-3w) >(rg-perm-5w-to-4w) \
>(rg-perm-6w-to-3w) >(rg-perm-6w-to-4w) \
>(rg-perm-7w-to-3w) >(rg-perm-7w-to-4w) \
>(rg-perm-8w-to-3w) >(rg-perm-8w-to-4w) \
>(rg-perm-9w-to-3w) >(rg-perm-9w-to-4w) \
>/dev/null
}
# Watch
# Watch top listing of UNIX domain socket files.
# @see: https://askubuntu.com/a/1341845/78223
function watchlsof {
watch "lsof -U +c 15 | cut -f1 -d' ' | sort | uniq -c | sort -rn | head -20"
}