1
- LIBSH_VERSION=20250310_1b90edd
1
+ LIBSH_VERSION=20250320_597f75f
2
2
export LIBSH_VERSION
3
3
cat << EOF
4
4
lib.sh v$LIBSH_VERSION
@@ -16,6 +16,14 @@ set -o pipefail
16
16
17
17
# helpers
18
18
19
+ function pd() {
20
+ if [ $# = 0 ]; then
21
+ popd 1> /dev/null
22
+ else
23
+ pushd " $1 " 1> /dev/null
24
+ fi
25
+ }
26
+
19
27
_alias () {
20
28
local name=" $1 "
21
29
shift
@@ -187,15 +195,18 @@ alias sinfo=bf # small info
187
195
rand () {
188
196
if [[ $# == 0 ]]; then
189
197
cat << EOF
190
- the util takes <count> bytes from /dev/random and outputs lower-case hex values
198
+ The util takes <count> bytes from /dev/random and outputs lower-case hex values
191
199
192
- usage: rand <count> [-f] [-n]
200
+ Usage:
201
+ rand <count> [-f] [-n]
193
202
194
- <count> byte count
195
- -f, --force if count > 64, the flag is required
196
- -n, --newline if specified, '\n' is added after the output
203
+ Parameters:
204
+ <count> byte count
205
+ -f, --force if count > 64, the flag is required
206
+ -n, --newline if specified, '\n' is added after the output
197
207
198
- example: to get 256 bit nonce use: $( rand 32)
208
+ Example:
209
+ To get 256 bit nonce use: $( rand 32)
199
210
200
211
EOF
201
212
return 1
@@ -236,19 +247,19 @@ EOF
236
247
function randpass() {
237
248
if [[ $1 == " --help" || $1 == " -h" ]]; then
238
249
cat << EOF
239
- generates random password
240
- usage: randpass [length]
241
- default length is 16
250
+ Generates random password
251
+
252
+ Usage:
253
+ randpass [length]
254
+
255
+ Parameters:
256
+ length length in characters, default is 16
242
257
243
- <count> symbol count
244
258
EOF
245
259
exit 1
246
260
fi
247
261
248
- if ! command -v python > /dev/null 2>&1 ; then
249
- echo ERROR: python not found
250
- exit 1
251
- fi
262
+ _require python3 || return 1
252
263
253
264
local length=" ${1:- 16} "
254
265
@@ -328,6 +339,8 @@ alias pig=isnet
328
339
_salias ap /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
329
340
_salias apd /usr/libexec/airportd
330
341
342
+ _salias sysinfocachegen /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/sysinfocachegen
343
+
331
344
# use always native ifconfig for the purpose of lib.sh!
332
345
_salias ifc /sbin/ifconfig
333
346
@@ -410,30 +423,34 @@ if0() {
410
423
}
411
424
412
425
randmac () {
426
+ echo " 🪦 you've just stumbled upon a tumbstone with the text on it: 🪦"
427
+ echo
413
428
414
- if (( $# > 1 )) ; then
415
- cat << 'EOF '
429
+ cat << 'EOF '
416
430
Temporary changes network interface mac address. This does not survice a reboot.
417
431
418
- usage: randmac [<interface>]
419
-
420
- [<interface>] optionally specified interace for the mac address to be set on
421
- EOF
422
- return 1
423
- fi
432
+ Usage:
433
+ randmac [<interface>]
424
434
425
- local interface=en0
435
+ Parameters:
426
436
427
- if [ " $1 " != " " ] ; then
428
- interface= " $1 "
429
- fi
437
+ [<interface>] optionally specified interace for the mac address to be set on
438
+ EOF
439
+ return 1
430
440
431
- ap -z
432
- local mac=$( rand 6 | sed -E ' s/([0-9a-f]{2})/:\1/g' | sed ' s/^://g' )
441
+ # local interface=en0
442
+ #
443
+ # if [ "$1" != "" ]; then
444
+ # interface="$1"
445
+ # fi
446
+ #
447
+ # ap -z
448
+ # local mac=$(rand 6 | sed -E 's/([0-9a-f]{2})/:\1/g' | sed 's/^://g')
449
+ #
450
+ # echo -- "generated value: $mac; attempting to set..."
451
+ # ifc $interface ether "$mac"
452
+ # (($? == 0)) && mac && echo done.
433
453
434
- echo -- " generated value: $mac ; attempting to set..."
435
- ifc $interface ether " $mac "
436
- (( $? == 0 )) && mac && echo done.
437
454
}
438
455
439
456
alias ms=' m status'
@@ -478,16 +495,53 @@ msss() {
478
495
printf " \tRelay info:\n\t\t%s\n" " $( m relay get | sed -E ' s/^[^:]+: //g' ) "
479
496
}
480
497
481
- function nets () {
498
+ function netsetup () {
482
499
_exec networksetup " $@ "
483
500
484
501
}
485
- function dhinfo() {
486
- nets -getinfo " Wi-Fi" | rg --color=never ' (^[^:]+$)|(^[^:]+:.+$)' --replace ' $1 $2'
502
+ alias nsetup=netsetup
503
+
504
+ alias _netservices=' networksetup -listnetworkserviceorder'
505
+
506
+ function netservices() {
507
+
508
+ for (( i = 1 ; i <= $# ; i++ )) ; do
509
+ case " ${! i} " in
510
+ -h | --help)
511
+ cat << 'EOF '
512
+
513
+ Lists macos network services, in their order (priority)
514
+
515
+ Usage:
516
+ netservices [-h|--help] [--json]
517
+
518
+ Parameters:
519
+ --json output JSON
520
+
521
+ EOF
522
+ return 1
523
+ ;;
524
+
525
+ --json)
526
+ local json=1
527
+ _require rg || return 1
528
+ ;;
529
+ esac
530
+ done
531
+
532
+ if [[ $json == 1 ]]; then
533
+ _netservices | rg --color never -o ' Hardware Port: ([^,]+), Device: (en[\d]+)' --replace ' {"name":"$1","port":"$2"}'
534
+ else
535
+ _netservices
536
+ fi
487
537
}
488
538
489
- function netsocks() {
490
- nets -setsocksfirewallproxy " Wi-Fi" " $1 " " $2 "
539
+ alias nservices=netservices
540
+ alias nsvc=nservices
541
+ alias nsvcj=' nsvc --json'
542
+
543
+ function dhinfo() {
544
+ netsetup -getinfo " Wi-Fi" | rg --color=never ' (^[^:]+$)|(^[^:]+:.+$)' --replace ' $1 $2'
491
545
}
492
546
493
547
alias dhi=dhinfo
@@ -570,27 +624,6 @@ alias pxgh='pxg help'
570
624
alias hch=hatch
571
625
alias ach=hch
572
626
alias tch=hch
573
- alias pd=pdm
574
-
575
- alias mm=mamba
576
- alias um=micromamba
577
- alias uma=' um activate'
578
- alias umd=' um deactivate'
579
- alias umc=' um env create -n'
580
- alias uml=' um env list'
581
- alias umll=' um list'
582
- alias umu=' um update'
583
- alias umua=' umu -a'
584
-
585
- umca () {
586
- umc " $1 "
587
- uma " $1 "
588
- }
589
-
590
- alias umi=' um install'
591
- alias umr=' um remove'
592
- alias umrm=' um env remove -n'
593
- alias ums=' um search'
594
627
595
628
# venv / uv
596
629
alias _venv=' python -m venv'
@@ -1085,6 +1118,7 @@ alias nxconf='nx show-config'
1085
1118
alias nxc=nxconf
1086
1119
alias nxsh=' nx shell'
1087
1120
alias nxs=' nix-search'
1121
+ alias nxsd=' nxs -d'
1088
1122
1089
1123
alias nxb=' nx build'
1090
1124
alias nxbi=" nxb $_nxi "
@@ -1117,7 +1151,8 @@ nxdrvpaths() {
1117
1151
Prints nix store "requisites" paths for specified derivation(s).
1118
1152
Useful when one needs to do fine-grained filtering (like for pushing to binary cache).
1119
1153
1120
- Usage: $0 <derivation...>
1154
+ Usage:
1155
+ $0 <derivation...>
1121
1156
EOF
1122
1157
return 1
1123
1158
fi
@@ -1138,7 +1173,7 @@ nxfi() {
1138
1173
1139
1174
if [[ $1 =~ -h | --help ]]; then
1140
1175
cat << 'EOF '
1141
- initializes nix flake in the current directory, using one of
1176
+ Initializes nix flake in the current directory, using one of
1142
1177
flake.parts template
1143
1178
1144
1179
Usage:
@@ -1239,6 +1274,8 @@ alias nxw='nxp wipe-history'
1239
1274
1240
1275
alias nxhash=' nx hash'
1241
1276
alias nxh=' nxhash'
1277
+ alias nxhsri=' nxh to-sri --type sha256'
1278
+ alias xsri=' xargs nix hash to-sri --type sha256'
1242
1279
1243
1280
nxhrand () {
1244
1281
_require nix || return 1
@@ -1303,36 +1340,8 @@ EOF
1303
1340
open /Applications/nix
1304
1341
}
1305
1342
1306
- # deprecated
1307
- # TODO: remove
1308
- # alias nu-legacy='nix-env --upgrade' # broken allegedly by nixpkgs' 8a5b9ee
1309
- #
1310
- # # creates upggradeable list of packages as --attr parameters to nix-env --upgrade
1311
- # _nuattrs() {
1312
- #
1313
- # nix-shell -p ripgrep --run sh < <(
1314
- # cat <<'EOF'
1315
- # nix-env -q | rg -o '^([a-zA-Z-]+)[.-](?:[\d.-]+)*' --replace '--attr nixpkgs.$1' | sed -e 's/-i/I/g;s/-min/Min/g;s/nss-//g;s/-(wrapped|unstable)//g'
1316
- # EOF
1317
- # )
1318
- # return 0
1319
- # }
1320
- #
1321
- # _nu() {
1322
- # _nuattrs $@ | xargs nix-env --upgrade
1323
- #
1324
- # }
1325
- #
1326
- # alias nu-attrs=_nuattrs
1327
- # alias nu='nix-env --upgrade'
1328
- #
1329
- # alias ncu='nix-channel --update'
1330
- #
1331
- # alias u='nix-env -e'
1332
- # alias q='nix-env -q'
1333
-
1334
1343
# direnv / nix-direnv
1335
- alias renv =nix-direnv-reload
1344
+ alias dre =nix-direnv-reload
1336
1345
1337
1346
# filesystem
1338
1347
@@ -2784,9 +2793,23 @@ alias rgnc='rg --color=never'
2784
2793
2785
2794
# tor
2786
2795
mytorsocks () {
2787
- _exec netsocks localhost 9050
2796
+ # set it up on all the services available
2797
+
2798
+ _require jq
2799
+
2800
+ local svcs=
2801
+
2802
+ mapfile -t svcs < <( netservices --json | jq ' .name' -r)
2803
+
2804
+ for svc in " ${svcs[@]} " ; do
2805
+ netsetup -setsocksfirewallproxy " $svc " localhost 9050
2806
+ done
2807
+
2788
2808
tor
2789
- _exec netsocks " " " "
2809
+
2810
+ for svc in " ${svcs[@]} " ; do
2811
+ netsetup -setsocksfirewallproxy " $svc " " " " "
2812
+ done
2790
2813
}
2791
2814
2792
2815
# gollama
@@ -3068,6 +3091,9 @@ snkc() {
3068
3091
snyk config | rg -o ' INTERNAL_OAUTH_TOKEN_STORAGE: (.+)$' --replace ' $1' | jq
3069
3092
}
3070
3093
alias snc=snkc
3094
+
3095
+ alias verifyNotarization=' spctl -a -vvv -t install'
3096
+ alias vn=verifyNotarization
3071
3097
# TODO: ✂ - - - - - - - - - - - - - - - - - - -
3072
3098
3073
3099
_init () {
0 commit comments