Repository navigation
Expand file tree
/
Copy path.bashrc
More file actions
607 lines (520 loc) · 15.6 KB
/
Copy path.bashrc
File metadata and controls
607 lines (520 loc) · 15.6 KB
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
# shellcheck disable=2148
# reedline-bash needs a readline new enough to export rl_full_quoting_desired;
# nixpkgs' bashInteractive has it, distro bashes generally don't yet.
if [[ -z "$_NIX_BASH_REEXEC_DONE" ]] && [[ -x "$HOME/.nix-profile/bin/bash" ]]; then
_nix_bash=$(readlink -f "$HOME/.nix-profile/bin/bash")
if [[ "$(readlink -f "/proc/$$/exe")" != "$_nix_bash" ]]; then
export _NIX_BASH_REEXEC_DONE=1
exec "$_nix_bash"
fi
unset _nix_bash
fi
# source nix environment (multi-user)
if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
. '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
fi
# source home manager session variables
if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh"
fi
# fortune
shopt -s expand_aliases
export GIT_PROMPT=true
export KUBE_PROMPT=false
export NIX_PROMPT=true
export VI_MODE_PROMPT=true
export GPG_PROGRAM=/usr/bin/gpg
export OPENCODE_MODELS_PATH="/home/$USER/clones/forks/models.dev/packages/web/dist/_api.json"
export SOPS_AGE_KEY_FILE=$HOME/.config/sops/age/keys.txt
source ~/.bash_aliases
unset _POST_PROMPT_DONE
# nnn plugins
export NNN_PLUG='m:mediainfo'
if [[ $- == *i* ]] && [[ -t 0 ]]; then
source ~/clones/forks/xelabash/xela.bash
fi
gpsup() {
local branch
branch=$(git symbolic-ref --short HEAD 2>/dev/null)
git push --set-upstream origin "$branch"
}
rad() {
if [ "$1" != "init" ]; then
command rad "$@"
return
fi
shift
local visibility=--public
case " $* " in
*" --private "* | *" --public "*) visibility= ;;
esac
command rad init $visibility "$@" &&
echo "remember to run radit so mlab (git.marcel.cool) seeds this repo"
}
mmview() {
[ -z "$1" ] && {
echo "usage: mmview <file.md>"
return 1
}
local out
out=$(mktemp -d)
nix shell nixpkgs#mermaid-cli --command mmdc -i "$1" -o "$out/out.md" >/dev/null || return 1
{
printf '<!doctype html><meta charset=utf-8><title>%s</title>' "$1"
printf '<style>'
printf 'body{margin:0;background:#111}'
printf 'section{min-height:100vh;display:flex;align-items:center;justify-content:center;overflow:auto}'
printf 'img{max-height:100vh;max-width:100vw;background:#fff;padding:1em;box-sizing:border-box;cursor:zoom-in}'
printf 'img.z{max-height:none;max-width:none;cursor:zoom-out}'
printf '</style>'
for f in "$out"/out-*.svg; do
[ -e "$f" ] && printf '<section><img src="%s" onclick="this.classList.toggle(%c%c%c)"></section>' "$f" 39 z 39
done
} >"$out/index.html"
brave-origin "$out/index.html"
}
sleep_in() {
local minutes="$1"
local seconds=$((minutes * 60))
while [ "$seconds" -gt 0 ]; do
printf "\rSuspending in %02d:%02d" $((seconds / 60)) $((seconds % 60))
sleep 1
seconds=$((seconds - 1))
done
echo
systemctl suspend
}
refresh_techno_playlist() {
password="$(rbw get --folder slskd account)"
sldl \
--input "https://www.youtube.com/watch?v=QAyrU6hhVRc&list=PLHa2a9cVibtnn69H5nJ-hMLGmm3t6lz1z&pp=sAgC" \
--user marcelarie \
--password "${password}" \
--pref-format=flac,wav,mp3 \
--reverse \
--path="${HOME}/techno-electronica/"
}
# nsh: run package in temporary nix shell
# Usage: nsh [-u|--unstable|-s|--stable] [-f|--flake <ref>] <pkg> [args...]
# Options: -u/--unstable (default), -s/--stable (nixos-25.11), -f/--flake (custom flake ref)
nsh() {
local flake="github:nixos/nixpkgs/nixos-unstable"
local unstable_flag=0
local stable_flag=0
local custom_flake=0
# Parse flags
while [[ "$1" == -* ]]; do
case "$1" in
-u | --unstable)
if [ $stable_flag -eq 1 ] || [ $custom_flake -eq 1 ]; then
echo "Error: cannot use -u/--unstable with -s/--stable or -f/--flake" >&2
return 1
fi
flake="github:nixos/nixpkgs/nixos-unstable"
unstable_flag=1
shift
;;
-s | --stable)
if [ $unstable_flag -eq 1 ] || [ $custom_flake -eq 1 ]; then
echo "Error: cannot use -s/--stable with -u/--unstable or -f/--flake" >&2
return 1
fi
flake="github:nixos/nixpkgs/nixos-25.11"
stable_flag=1
shift
;;
-f | --flake)
if [ $unstable_flag -eq 1 ] || [ $stable_flag -eq 1 ] || [ $custom_flake -eq 1 ]; then
echo "Error: cannot use -f/--flake with -u/--unstable or -s/--stable" >&2
return 1
fi
flake="$2"
custom_flake=1
shift 2
;;
*)
echo "Unknown option: $1" >&2
return 1
;;
esac
done
local pkg="$1"
shift
if [ $# -gt 0 ]; then
nix shell "${flake}#${pkg}" --command "$pkg" "$@"
else
nix shell "${flake}#${pkg}"
fi
}
hex() {
# Normalize input: lowercase and remove optional '#'
hex=$(echo "${1#"#"}" | tr '[:upper:]' '[:lower:]')
format=""
# Detect hex format and extract channels
case ${#hex} in
3)
format="RGB"
r=${hex:0:1}${hex:0:1}
g=${hex:1:1}${hex:1:1}
b=${hex:2:1}${hex:2:1}
;;
4)
format="RGBA"
r=${hex:0:1}${hex:0:1}
g=${hex:1:1}${hex:1:1}
b=${hex:2:1}${hex:2:1}
;;
6)
format="RRGGBB"
r=${hex:0:2}
g=${hex:2:2}
b=${hex:4:2}
;;
8)
format="RRGGBBAA"
r=${hex:0:2}
g=${hex:2:2}
b=${hex:4:2}
;;
*)
echo "Invalid color: $1" >&2
return 1
;;
esac
# Print a colored block, format type, and original input
printf "\e[48;2;%d;%d;%dm \e[0m %-10s %s\n" $((16#$r)) $((16#$g)) $((16#$b)) "[$format]" "$1"
}
export -f hex
se() {
local user=$1
local env="mlab"
local timeout=2
if ssh -q -o ConnectTimeout=$timeout -o BatchMode=yes root@mlab-local exit 2>/dev/null; then
env="mlab-local"
fi
~/scripts/tmux-se.sh "$user" "$env" "${user}_mlab"
}
fhex() {
# Requires: fzf, curl, jq, and the 'hex' function
for cmd in fzf curl jq; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "$cmd not found" >&2
return 1
}
done
declare -f hex >/dev/null 2>&1 || {
echo "hex() not defined" >&2
return 1
}
# Cache file
cache="${XDG_CACHE_HOME:-$HOME/.cache}/fhex_colors.json"
mkdir -p "$(dirname "$cache")"
# Fetch color list if cache missing or older than 7 days
if [ ! -f "$cache" ] || [ $(($(date +%s) - $(stat -c %Y "$cache"))) -gt 604800 ]; then
echo "Fetching color list..."
curl -fsSL "https://api.color.pizza/v1/?list=bestOf" -o "$cache" || {
echo "Failed to fetch color list" >&2
return 1
}
fi
# Parse JSON → "name<TAB>#hex"
tmp=$(mktemp)
jq -r '.colors[] | "\(.name)\t\(.hex)"' "$cache" >"$tmp" || {
echo "Failed to parse color list" >&2
rm -f "$tmp"
return 1
}
# fzf picker with preview using hex
choice=$(fzf --ansi --preview-window=up:1:wrap \
--preview 'hex {2}' \
--delimiter='\t' \
--with-nth=1 \
<"$tmp")
[ -n "$choice" ] && hex "$(echo "$choice" | cut -f2)"
rm -f "$tmp"
}
if [[ $- == *i* ]]; then
set -o vi
if command -v carapace >/dev/null 2>&1; then
export CARAPACE_BRIDGES='bash'
source <(carapace _carapace bash)
fi
fi
__post_first_prompt_init() {
if [[ -n "$_POST_PROMPT_DONE" ]]; then return; fi
_POST_PROMPT_DONE=1
command -v direnv >/dev/null 2>&1 && eval "$(direnv hook bash)"
command -v atuin >/dev/null 2>&1 && eval "$(atuin init bash --disable-up-arrow)"
command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init bash)"
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
PROMPT_COMMAND="${PROMPT_COMMAND//__post_first_prompt_init;/}"
PROMPT_COMMAND="${PROMPT_COMMAND//__post_first_prompt_init/}"
PROMPT_COMMAND="${PROMPT_COMMAND//;;/;}"
}
__alacritty_tmux_attach() {
local request=${XDG_RUNTIME_DIR:-/run/user/$UID}/alacritty-tmux/$$ session pid
[[ -f $request ]] || return 0
read -r session pid <"$request"
rm -f "$request"
[[ -z $pid ]] || disown "$pid" 2>/dev/null
tmux attach-session -t "=$session"
}
if [[ $- == *i* ]] && [[ -t 0 ]]; then
precmd_functions+=(__alacritty_tmux_attach)
if [[ -n "$TMUX" ]]; then
__post_first_prompt_init
else
PROMPT_COMMAND="__post_first_prompt_init;${PROMPT_COMMAND}"
fi
fi
vpn_connect() {
local vpn_name
vpn_name="$(nmcli connection show | grep -i vpn | fzf --prompt="Select VPN to connect: " --height=10 | awk '{print $1}')"
if [ -n "$vpn_name" ]; then
echo "Connecting to $vpn_name..."
nmcli connection up "$vpn_name"
else
echo "No VPN selected"
fi
}
vpn_disconnect() {
local vpn_name
vpn_name="$(nmcli connection show --active | grep -i vpn | fzf --prompt="Select VPN to disconnect: " --height=10 | awk '{print $1}')"
if [ -n "$vpn_name" ]; then
echo "Disconnecting $vpn_name..."
nmcli connection down "$vpn_name"
else
echo "No VPN selected"
fi
}
vpn() {
local action
if [ -z "$1" ]; then
action=$(printf "connect\ndisconnect" | fzf --prompt="VPN action: " --height=5)
else
action=$1
fi
case "$action" in
connect)
vpn_connect
;;
disconnect)
vpn_disconnect
;;
*)
echo "Usage: vpn {connect|disconnect}"
;;
esac
}
# Use bash-completion, if available
[[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] &&
. /usr/share/bash-completion/bash_completion
# Start gpg-agent if not already running
GPG_AGENT_INFO=$(gpgconf --list-dirs agent-socket)
GPG_TTY=$(tty 2>/dev/null)
export GPG_AGENT_INFO GPG_TTY
SSH_AUTH_SOCK=${SSH_AUTH_SOCK:-$(gpgconf --list-dirs agent-ssh-socket)}
export SSH_AUTH_SOCK
# source "$HOME/.rye/env"
# source rund bash
# eval "$(starship init bash)"
# ENV. VARIABLES
# export PAGER="moar --no-statusbar"
if command -v rbw >/dev/null 2>&1; then
MINI_FLUX_TOKEN="$(rbw get --folder miniflux pika-token-1 2>/dev/null)"
SYNTHETIC_API_KEY="$(rbw get --folder synthetic.new api-key 2>/dev/null)"
WS_LITE_LLM_API_KEY="$(rbw get --folder worldsensing ws-llm 2>/dev/null)"
SONAR_TOKEN="$(rbw get --folder worldsensing sonar-token 2>/dev/null)"
export MINI_FLUX_TOKEN SYNTHETIC_API_KEY WS_LITE_LLM_API_KEY SONAR_TOKEN
fi
if [[ $PWD == */triumph-dev-environment* || $PWD == */meta-worldsensing* ]] &&
command -v sops >/dev/null 2>&1 && [[ -f ~/clones/own/dots/secrets/keys-for-dev.sh ]]; then
source <(sops decrypt ~/clones/own/dots/secrets/keys-for-dev.sh 2>/dev/null)
fi
export BITBUCKET_USER=mmanzanares@worldsensing.com
bbdiff() {
local pr="${1:?usage: bbdiff <pr_number> [workspace/repo]}"
local repo
local BITBUCKET_TOKEN="${BITBUCKET_TOKEN:-$(rbw get "atlassian.com token")}"
if [[ -n "$2" ]]; then
repo="$2"
else
repo=$(git remote get-url origin 2>/dev/null |
sed -E 's|.*bitbucket\.org[:/]||;s|\.git$||')
[[ -z "$repo" ]] && {
echo "Not a bitbucket repo, pass workspace/repo as \$2"
return 1
}
fi
local base="https://api.bitbucket.org/2.0/repositories/$repo"
curl -sf -m 30 -u "$BITBUCKET_USER:$BITBUCKET_TOKEN" "$base/pullrequests/$pr" |
jq -r '"Title: \(.title)\nDescription: \(.description // "")\nBranch: \(.source.branch.name) → \(.destination.branch.name)\n"'
curl -sL -m 30 -u "$BITBUCKET_USER:$BITBUCKET_TOKEN" "$base/pullrequests/$pr/diff"
}
bbpr() {
local pr="${1:?usage: bbpr <pr_number> [workspace/repo]}"
local repo
local BITBUCKET_TOKEN="${BITBUCKET_TOKEN:-$(rbw get "atlassian.com token")}"
if [[ -n "$2" ]]; then
repo="$2"
else
repo=$(git remote get-url origin 2>/dev/null |
sed -E 's|.*bitbucket\.org[:/]||;s|\.git$||')
[[ -z "$repo" ]] && {
echo "Not a bitbucket repo, pass workspace/repo as \$2"
return 1
}
fi
curl -s -u "$BITBUCKET_USER:$BITBUCKET_TOKEN" \
"https://api.bitbucket.org/2.0/repositories/$repo/pullrequests/$pr" |
jq '{title, state, author: .author.display_name, source: .source.branch.name, destination: .destination.branch.name, description}'
}
export _JAVA_AWT_WM_NONREPARENTING=1
export AWT_TOOLKIT=MToolkit
export GDK_BACKEND=wayland
export ELECTRON_OZONE_PLATFORM_HINT=wayland
export HOMEBREW_NO_AUTO_UPDATE=1
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
export HYPRSHOT_DIR=$HOME/screenshots
# export EDITOR=/home/marcel/.local/share/bob/nvim-bin/nvim
# export SUDO_EDITOR=/home/marcel/.local/share/bob/nvim-bin/nvim
export EDITOR=nvim
export DFT_BACKGROUND=light
export SUDO_EDITOR=nvim
export TERMINAL=foot
if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
export MOZ_ENABLE_WAYLAND=1
fi
function so() {
source "$HOME/.bashrc"
}
syn() {
if [ $# -ne 1 ]; then
echo "Usage: syn <word>"
return 1
fi
local result
result=$(
curl -s "https://api.dictionaryapi.dev/api/v2/entries/en/$1" |
jq -r '.[].meanings[]? | (.synonyms[]?, .definitions[]?.synonyms[]?)'
)
if [ -z "$result" ]; then
echo "No synonyms found"
else
echo "$result"
fi
}
def() {
if [ $# -ne 1 ]; then
echo "Usage: def <word>"
return 1
fi
local result
result=$(
curl -s "https://api.dictionaryapi.dev/api/v2/entries/en/$1" |
jq -r '.[].meanings[]?.definitions[]?.definition'
)
if [ -z "$result" ]; then
echo "No definitions found"
else
echo "$result"
fi
}
wttr() {
if [ -z "$1" ]; then
echo 'City argument missing'
echo 'wttr <city>'
return 1
fi
curl "wttr.in/$1?format=Location:%l\nCondition:%C\nTemp:%t\nFeels:%f\nWind:%w\nHumidity:%h\nPressure:%P\nPrecip:%p"
}
# No need with nix, use the tempshell script instead
# export PYENV_ROOT="$HOME/.pyenv"
# export PATH="$PYENV_ROOT/bin:$PATH"
#
# if command -v pyenv 1>/dev/null 2>&1; then
# eval "$(pyenv init - bash)"
# fi
export PATH="/home/$USER/.local/share/bob/nvim-bin:$PATH"
export PATH=$PATH:/usr/local/bin:/snap/bin
export PATH="/home/$USER/.local/bin:$PATH"
export PATH="/home/$USER/.cargo/bin:$PATH"
for d in "$HOME/scripts" "$HOME/scripts"/*; do
[ -d "$d" ] && PATH="$d:$PATH"
done
if [ -z "$SOURSES_RUNNING" ]; then
export SOURSES_RUNNING=1
# Replace this shell with the sourses recorder (PTY spawn + indexing) exec ~/clones/own/sourses/target/debug/sourses record
fi
# . "$HOME/.cargo/env"
export _ZO_DOCTOR=0
gstp() {
git status --porcelain "$@" | awk '$1 ~ /^M/ { print $2 }' | paste -sd ' '
}
# if [[ $- == *i* ]] && [[ -t 0 ]] && command -v tarea >/dev/null 2>&1; then
# tarea
# fi
mkdir -p ~/.cache/bash-completions
if command -v tarea >/dev/null 2>&1; then
[ -f ~/.cache/bash-completions/tarea.bash ] || tarea --completions bash >~/.cache/bash-completions/tarea.bash
# shellcheck disable=SC1090
. ~/.cache/bash-completions/tarea.bash
fi
# if command -v gcs >/dev/null 2>&1; then
# eval "$(gcs --completion bash)"
# fi
if command -v timer >/dev/null 2>&1; then
eval "$(timer completion bash)"
fi
for reedline_bash_lib in "$HOME/.nix-profile/lib/libreedline_bash.so" "/etc/profiles/per-user/$USER/lib/libreedline_bash.so"; do
if [[ -f "$reedline_bash_lib" ]]; then
enable -f "$reedline_bash_lib" reedline 2>/dev/null
break
fi
done
unset reedline_bash_lib
_wiki_history_file() {
printf '%s' "${XDG_CACHE_HOME:-$HOME/.cache}/wiki_search/history"
}
_wiki_candidates() {
local query="$1"
local history_file
history_file=$(_wiki_history_file)
if [ -z "$query" ]; then
cat "$history_file" 2>/dev/null
return 0
fi
{
grep -iF -- "$query" "$history_file" 2>/dev/null
curl -s -G -d action=opensearch -d limit=15 -d format=json --data-urlencode "search=$query" https://en.wikipedia.org/w/api.php | jq -r '.[1][]'
} | awk '!seen[$0]++'
}
_wiki_history_add() {
local article="$1"
local history_file
history_file=$(_wiki_history_file)
mkdir -p "${history_file%/*}"
{
printf '%s\n' "$article"
grep -vxF -- "$article" "$history_file" 2>/dev/null
} | head -n 100 >"$history_file.tmp" && command mv -f "$history_file.tmp" "$history_file"
}
export -f _wiki_history_file _wiki_candidates
wiki_search() {
local article
article=$(FZF_DEFAULT_COMMAND="_wiki_candidates" fzf --prompt="Wiki Search> " \
--phony \
--bind "alt-j:down,alt-k:up" \
--bind "change:reload(_wiki_candidates {q})")
if [ -n "$article" ]; then
_wiki_history_add "$article"
echo -e "\n\033[1;32m=== $article ===\033[0m\n"
wiki read "$article" --markdown --no-pager | ink
fi
}
# export BEMENU_OPTS="--fb #1c1c1c --ff #c6c6c6 --nb #1c1c1c --nf #c6c6c6 --tb #1c1c1c --tf #5f87af --hb #303030 --hf #ffaf5f --ab #1c1c1c --af #c6c6c6 --fn 'monospace 11'"
unset LS_COLORS
if [ ! -e /etc/NIXOS ]; then
unset LD_LIBRARY_PATH GBM_BACKENDS_PATH LIBGL_DRIVERS_PATH \
LIBVA_DRIVERS_PATH __EGL_VENDOR_LIBRARY_FILENAMES
fi