-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaliases
More file actions
executable file
·994 lines (814 loc) · 31.7 KB
/
aliases
File metadata and controls
executable file
·994 lines (814 loc) · 31.7 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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# Common aliases and functions
__aliases_main() {
local SH_SOURCE_FILE SH_SOURCE_DIR SH_SOURCE_FILE_ESCAPED
if [ -n "$ZSH_VERSION" ]; then
SH_SOURCE_FILE=${(%):-%x}
elif [ -n "$BASH_VERSION" ]; then
SH_SOURCE_FILE=${BASH_SOURCE[0]}
fi
while [[ -L "$SH_SOURCE_FILE" ]]; do
SH_SOURCE_FILE=$(readlink "$SH_SOURCE_FILE")
done
SH_SOURCE_DIR=$(dirname "$SH_SOURCE_FILE")
SH_SOURCE_DIR=`cd "$SH_SOURCE_DIR" >/dev/null; pwd`
SH_SOURCE_FILE=$(basename "$SH_SOURCE_FILE")
SH_SOURCE_FILE_ESCAPED=${SH_SOURCE_FILE// /_}
# SH_SOURCE_DIR is a full path to the location of this script
eval "$(cat <<EOF
__get_${SH_SOURCE_FILE_ESCAPED}_dir() {
echo $SH_SOURCE_DIR
}
__get_${SH_SOURCE_FILE_ESCAPED}_file() {
echo $SH_SOURCE_FILE
}
EOF
)"
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
# Early load before bashrc main started
alias cls='clear'
alias grep='grep --color=auto '
alias fgrep='fgrep --color=auto '
alias egrep='egrep --color=auto '
alias dir='ls -al '
alias path='echo $PATH | sed s/\:/\\n/g '
alias ps='ps -ef '
alias psu='ps -u ${USER} '
ff() {
find . -name "*" -type f -exec grep --color=auto -HinF "$@" {} \;
}
ff2() {
# Double-grep to filter out grep warnings
grep --color=auto -RHinF "$@" * 2>&1 | grep --color=auto -i "$@"
}
fff() {
find . -name "$1" -type f -exec grep --color=auto -HinF "${@:2}" {} \;
}
fff2() {
# Double-grep to filter out grep warnings
grep --color=auto -RHinF "${@:2}" "$1" 2>&1 | grep --color=auto -i "${@:2}"
}
ffs() {
set | grep --color=auto -i "$@"
}
fn() {
find -L . -iname "$@"
}
fp() {
ps | grep --color=auto -i "$@"
}
rmr() {
eval "$(__sh_color_definitions)"
if [[ $# -eq 0 ]]; then
echo -e "Usage: "$COLOR_YELLOW_BOLD"rmr"$COLOR_NONE" "$COLOR_CYAN_BOLD"{pattern}"$COLOR_NONE" "$COLOR_CYAN_BOLD"{rm options}"$COLOR_NONE
echo
echo -e $COLOR_YELLOW_BOLD"Rmr"$COLOR_NONE" will execute recursive rm on any files matching the "$COLOR_CYAN_BOLD"pattern"$COLOR_NONE
echo -e "skipping matching files in hidden subdirectories."
echo
echo -e $COLOR_RED_BOLD"Warning:"$COLOR_NONE" rmr is dangerous!"
echo
else
find . -name "$1" ! -path '*/.*' -exec rm "${@:2}" {} \;
fi
}
rmr2() {
eval "$(__sh_color_definitions)"
if [[ $# -eq 0 ]]; then
echo -e "Usage: "$COLOR_YELLOW_BOLD"rmr"$COLOR_NONE" "$COLOR_CYAN_BOLD"{pattern}"$COLOR_NONE" "$COLOR_CYAN_BOLD"{rm options}"$COLOR_NONE
echo
echo -e $COLOR_YELLOW_BOLD"Rmr"$COLOR_NONE" will execute recursive rm on any files matching the "$COLOR_CYAN_BOLD"pattern"$COLOR_NONE"."
echo
echo -e $COLOR_RED_BOLD"Warning:"$COLOR_NONE" rmr is dangerous!"
echo
else
find . -name "$1" -exec rm "${@:2}" {} \;
fi
}
check_whitespace() {
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
echo
echo -e 'Looking for '$COLOR_CYAN_BOLD'trailing space'$COLOR_NONE
# Look for trailing spaces
grep -r -n '[[:space:]]$' *
echo
echo -e 'Looking for '$COLOR_CYAN_BOLD'leading tabs'$COLOR_NONE
# Look for leading tabs
grep -r -n '^\t' *
echo
}
get_ssh_client_ip() {
local client_ip client_port server_port
read client_ip client_port server_port <<< "$SSH_CLIENT"
echo $client_ip
}
is_tailscale_ssh() {
[[ -n $SSH_CONNECTION ]] || return 1
# SSH_CONNECTION format: client_ip client_port server_ip server_port
local client_ip client_port server_ip server_port
read client_ip client_port server_ip server_port <<< "$SSH_CONNECTION"
[[ $server_ip == 100.* ]]
}
groot() {
local GIT_ROOT=$(git rev-parse --show-toplevel)
cd $GIT_ROOT/"$@"
}
ssht() {
ssh -t "$@" 'exec tmux new-session -As "${TMUX_AUTO_ATTACH_SESSION:-main}"'
}
sshn() {
ssh -t "$@" 'exec env TMUX_AUTO_ATTACH=0 "${SHELL:-/bin/sh}" -l'
}
# Switch to tmux session (default: "main", or pass a name); create if needed
t() {
local name="${1:-main}"
if [ -n "$TMUX" ]; then
tmux new-session -ds "$name" 2>/dev/null
tmux switch-client -t "$name"
else
tmux new-session -As "$name"
fi
}
# Detach from tmux (phone-friendly alternative to Ctrl-B D)
td() {
tmux detach-client
}
# List tmux sessions
tl() {
tmux ls
}
cdx() {
codex --dangerously-bypass-approvals-and-sandbox --add-dir ~/src "$@"
}
gmn() {
gemini --yolo --include-directories ~/src "$@"
}
cld() {
claude --dangerously-skip-permissions --add-dir ~/src "$@"
}
kimi-cld() {
cld --settings ~/.claude/kimi-2.5.json "$@"
}
glm4() {
cld --settings ~/.claude/glm-4.7-flash.json "$@"
}
glm5() {
cld --settings ~/.claude/glm-5.json "$@"
}
qwen-cld() {
cld --settings ~/.claude/qwen-coder-next.json "$@"
}
kim() {
kimi --yolo "$@"
}
# Kill orphaned MCP servers and biome LSPs from dead Claude Code sessions
claude-gc() {
local mcp_killed=0 biome_killed=0
# Kill mongodb-mcp-server processes whose parent is init (orphaned)
while read -r pid; do
kill "$pid" 2>/dev/null && ((mcp_killed++))
done < <(pgrep -P 1 -f "mongodb-mcp-server")
# Kill orphaned biome processes
while read -r pid; do
kill "$pid" 2>/dev/null && ((biome_killed++))
done < <(pgrep -P 1 -f "biome")
echo "Reaped $mcp_killed MCP servers, $biome_killed biome LSPs"
}
__get_commands_info() {
local COMMAND_LIST COMMAND COMMAND_INSTALLED COMMAND_LOCATION COMMAND_VERSION
COMMAND_LIST=( $* )
for COMMAND in "${COMMAND_LIST[@]}"; do
COMMAND_INSTALLED=`type -t ${COMMAND} 2>/dev/null || whence ${COMMAND} 2>/dev/null`
if [[ -n "$COMMAND_INSTALLED" ]]; then
echo
echo -e $COLOR_GREEN_BOLD${COMMAND}$COLOR_NONE
COMMAND_VERSION=`${COMMAND} --version 2>/dev/null || ${COMMAND} version 2>/dev/null`
if [[ -n "$COMMAND_VERSION" ]]; then
echo -e $COLOR_CYAN_BOLD' Version : '${COMMAND_VERSION}$COLOR_NONE
fi
COMMAND_LOCATION=`type -p ${COMMAND} 2>/dev/null`
if [[ -n "$COMMAND_LOCATION" ]]; then
echo -e $COLOR_CYAN_BOLD' Location : '${COMMAND_LOCATION}$COLOR_NONE
fi
else
echo
echo -e $COLOR_RED_BOLD${COMMAND}$COLOR_NONE
echo -e $COLOR_RED_BOLD' Not found'$COLOR_NONE
fi
done
}
setup_env() {
# Ensure passwordless sudo
if ! sudo -n true 2>/dev/null; then
echo "Setting up passwordless sudo for $USER..."
sudo sh -c "echo \"$USER ALL=(ALL) NOPASSWD: ALL\" > /etc/sudoers.d/$USER && chmod 440 /etc/sudoers.d/$USER"
fi
# --- Package managers (install first, everything else depends on these) ---
# brew — https://brew.sh/
command -v brew >/dev/null || /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Source brew env if not yet in PATH (fresh install)
if ! command -v brew >/dev/null; then
[ -x /home/linuxbrew/.linuxbrew/bin/brew ] && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
[ -x /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
[ -x /usr/local/bin/brew ] && eval "$(/usr/local/bin/brew shellenv)"
fi
# uv — Python package manager — https://docs.astral.sh/uv/
command -v uv >/dev/null || curl -LsSf https://astral.sh/uv/install.sh | sh
# nvm — Node version manager — https://github.com/nvm-sh/nvm
[ -d "${NVM_DIR:-$HOME/.nvm}" ] || curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.4/install.sh | bash
# --- Core tools ---
# git
command -v git >/dev/null || brew install git
# gh — GitHub CLI
command -v gh >/dev/null || brew install gh
# curl — usually preinstalled
command -v curl >/dev/null || brew install curl
# jq
command -v jq >/dev/null || brew install jq
# tmux
command -v tmux >/dev/null || brew install tmux
# mosh
command -v mosh >/dev/null || brew install mosh
# --- JavaScript ---
# bun — https://bun.sh/
command -v bun >/dev/null || curl -fsSL https://bun.sh/install | bash
# node — install via nvm after sourcing it
# command -v node >/dev/null || nvm install --lts
# npm — comes with node
# pnpm
command -v pnpm >/dev/null || npm install -g pnpm
# --- Python ---
# python3 / pip3 — usually preinstalled; macOS: brew install python3
command -v python3 >/dev/null || brew install python3
# python / pip — aliases for python3 on most systems
# pipx
command -v pipx >/dev/null || brew install pipx
# poetry
command -v poetry >/dev/null || pipx install poetry
# conda — https://docs.conda.io/ (manual install)
# --- AI/ML tools ---
# claude — Claude Code CLI
command -v claude >/dev/null || npm install -g @anthropic-ai/claude-code
# codex — OpenAI Codex CLI
command -v codex >/dev/null || npm install -g @openai/codex
# gemini — Google Gemini CLI (npm install -g @anthropic-ai/gemini... nah just kidding)
# command -v gemini >/dev/null || npm install -g @anthropic-ai/gemini # TODO: verify package name
# agy — Antigravity editor (manual install)
# antigravity — Windsurf editor (manual install)
# prime — (manual install)
# hf — Hugging Face CLI
command -v hf >/dev/null || uv tool install huggingface-hub
# llama-server — built from llama.cpp (manual build)
# --- Languages & compilers ---
# go
command -v go >/dev/null || brew install go
# rustc / cargo — https://rustup.rs/
command -v rustc >/dev/null || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
# ruby / gem — usually preinstalled; macOS: brew install ruby
# gcc / build-essential
if ! command -v gcc >/dev/null; then
if [[ $(uname -s) == "Darwin" ]]; then
xcode-select --install 2>/dev/null
else
sudo apt-get install -y build-essential
fi
fi
# clang
command -v clang >/dev/null || brew install llvm
# --- Build tools ---
# ccache
command -v ccache >/dev/null || brew install ccache
# cmake
command -v cmake >/dev/null || brew install cmake
# ninja
command -v ninja >/dev/null || brew install ninja
# --- Other tools ---
# convert — ImageMagick
command -v convert >/dev/null || brew install imagemagick
# docker
if ! command -v docker >/dev/null; then
if [[ $(uname -s) == "Darwin" ]]; then
brew install --cask docker
else
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker "$USER"
fi
fi
# arduino-cli
command -v arduino-cli >/dev/null || brew install arduino-cli
# nvcc — comes with CUDA toolkit (manual install)
# adb — Android Debug Bridge
# command -v adb >/dev/null || brew install android-platform-tools
echo
echo "--- Next steps for you... ---"
echo " nvm install --lts # Install Node via nvm"
echo " claude # Log in to Claude Code on first run"
echo " codex # Set OPENAI_API_KEY for Codex"
echo " git config --global user.name / user.email"
echo " gh auth login # Authenticate GitHub CLI"
echo " hf login # Log in for private HF models"
}
check_env() {
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
echo
echo -e 'Looking for '$COLOR_CYAN_BOLD'common'$COLOR_NONE' tools...'
__get_commands_info git gh brew bun nvm node npm pnpm python python3 pip pip3 pipx poetry uv hf go rustc cargo ruby gem agy antigravity arduino-cli claude codex gemini prime llama-server gcc clang ccache cmake ninja tmux curl convert docker mosh conda nvcc adb jq
if [[ $SH_OS_TYPE == OSX ]]; then
echo
echo -e 'Looking for '$COLOR_CYAN_BOLD'OS X'$COLOR_NONE' tools...'
__get_commands_info pod
fi
echo
}
deps_update() {
local global_mode=0
if [[ "$1" == "-g" ]]; then
global_mode=1
shift
fi
if (( global_mode )); then
echo "Checking for updates to global npm packages..."
# Avoid npx's interactive install prompt (which appears to hang on some systems,
# e.g. Raspberry Pi) by ensuring npm-check-updates is installed globally up front.
# Use full name to avoid conflict with Nvidia CUDA's ncu
if ! command -v npm-check-updates >/dev/null 2>&1; then
echo "npm-check-updates not found globally; installing..."
npm install -g npm-check-updates || return $?
echo
fi
local json_output
json_output=$(npm-check-updates -g --jsonUpgraded)
local ncu_status=$?
echo
if (( ncu_status != 0 )); then
echo "Error running npm-check-updates for global packages"
return $ncu_status
fi
if [[ -z "$json_output" || "$json_output" =~ ^[[:space:]]*\{[[:space:]]*\}[[:space:]]*$ ]]; then
echo "All global npm packages are up to date!"
return 0
fi
local install_args parse_status
install_args=$(printf '%s' "$json_output" | node -e '
const fs = require("fs");
try {
const raw = fs.readFileSync(0, "utf8").trim();
if (!raw) {
process.exit(1);
}
const upgrades = Object.entries(JSON.parse(raw));
if (!upgrades.length) {
process.exit(1);
}
console.log(upgrades.map(([name, version]) => `${name.trim()}@${String(version).trim()}`).join(" "));
} catch (error) {
console.error(error.message);
process.exit(2);
}
')
parse_status=$?
if (( parse_status == 1 )); then
echo "All global npm packages are up to date!"
return 0
elif (( parse_status != 0 )); then
echo "Failed to parse npm-check-updates output"
return $parse_status
fi
if [[ -z "$install_args" ]]; then
echo "All global npm packages are up to date!"
return 0
fi
if [ -n "$ZSH_VERSION" ]; then
setopt local_options sh_word_split
fi
echo "Running npm install -g $install_args"
npm install -g $install_args
local install_status=$?
if (( install_status != 0 )); then
echo "npm install -g failed"
return $install_status
fi
echo "Global npm packages updated successfully."
return 0
fi
if [ ! -f "package.json" ]; then
echo "No package.json found in current directory"
return 1
fi
# Check if npm-check-updates is installed locally
if ! npm list npm-check-updates >/dev/null 2>&1; then
echo "Installing npm-check-updates as dev dependency..."
npm install -D npm-check-updates
echo
fi
echo "Checking for updates..."
# Run ncu and capture its output and exit code
output=$(npx npm-check-updates -u)
exit_code=$?
echo
if [ $exit_code -ne 0 ]; then
echo "Error running npm-check-updates"
return 1
fi
# Check if any packages were updated
if echo "$output" | grep -q "Run npm install"; then
echo "Updates found. Running npm install..."
npm install
echo
# Check for build script
if grep -q "\"build\":" package.json; then
echo "Running build script..."
npm run build
echo
fi
# Check for test script
if grep -q "\"test\":" package.json; then
echo "Running tests..."
npm test
echo
fi
else
echo "All packages are up to date!"
fi
}
# Function to find and activate a Python virtual environment in the current directory
activate() {
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
# Check for common venv directory names
if [ -d "venv" ] && [ -f "venv/bin/activate" ]; then
echo -e "Activating virtual environment: "$COLOR_GREEN_BOLD"venv"$COLOR_NONE
source venv/bin/activate
elif [ -d ".venv" ] && [ -f ".venv/bin/activate" ]; then
echo -e "Activating virtual environment: "$COLOR_GREEN_BOLD".venv"$COLOR_NONE
source .venv/bin/activate
elif [ -d "env" ] && [ -f "env/bin/activate" ]; then
echo -e "Activating virtual environment: "$COLOR_GREEN_BOLD"env"$COLOR_NONE
source env/bin/activate
elif [ -d ".env" ] && [ -f ".env/bin/activate" ]; then
echo -e "Activating virtual environment: "$COLOR_GREEN_BOLD".env"$COLOR_NONE
source .env/bin/activate
elif [ -f "poetry.lock" ]; then
# Check Poetry version to determine activation method
local POETRY_VERSION=$(poetry --version 2>/dev/null | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
echo -e "Activating virtual environment: "$COLOR_GREEN_BOLD"poetry "$POETRY_VERSION$COLOR_NONE
# Extract major version for comparison
local POETRY_MAJOR_VERSION=$(echo "$POETRY_VERSION" | cut -d. -f1)
if [ -n "$POETRY_VERSION" ] && [ "$POETRY_MAJOR_VERSION" -lt 2 ]; then
# For Poetry < 2.0: use poetry shell
poetry shell
else
# For Poetry >= 2.0: use poetry env activate
eval $(poetry env activate)
fi
else
echo -e $COLOR_YELLOW_BOLD"No virtual environment found in the current directory."$COLOR_NONE
fi
}
# OS-specific aliases and functions
if [[ $SH_OS_TYPE == OSX ]]; then
# OS X aliases
alias ls='ls -Gp '
# Tailscale CLI (App Store version)
if [[ -x "/Applications/Tailscale.app/Contents/MacOS/Tailscale" ]]; then
alias tailscale="/Applications/Tailscale.app/Contents/MacOS/Tailscale"
fi
list() {
eval "$(__sh_color_definitions)"
eval "$(__sh_os_definitions)"
echo -e 'Connected devices'
echo
echo -e '--- '$COLOR_CYAN_BOLD'iOS'$COLOR_NONE' ---'
xcrun xctrace list devices 2>&1 | sed -n '/Simulators/q;p' | sed '1d;2d;$d'
echo
echo -e '--- '$COLOR_GREEN_BOLD'Android'$COLOR_NONE' ---'
adb devices | sed '1d;$d'
echo
echo -e '--- '$COLOR_YELLOW_BOLD'Fastboot'$COLOR_NONE' ---'
fastboot devices
echo
}
ex() {
if [[ $# -eq 0 ]]; then
open .
else
if [[ -d "$1" ]]; then
open "$@"
else
open -R "$@"
fi
fi
}
rep() {
eval "$(__sh_color_definitions)"
if [[ $# -eq 0 ]]; then
echo -e "Usage: rep {sed command}"
echo
echo -e "Rep will execute the sed command on all files in the current directory"
echo -e "and subdirectories, excluding any hidden files. All commands will be"
echo -e "executed in place using sed's -i option."
echo
echo -e "For example rep s/a/b/ will replace all instances of 'a' in all files with 'b'"
echo
sed --help
echo
else
for x in $(find . -type f -name '*' ! -name '.*' ! -path '*/.*'); do
sed -i "" "$@" $x
done
# This is a bit dangerous, and assumes that there are no legitimate files
# that start with .!. Probably should be a bit more careful and match
# more specifically
find . -name "\.\!*" -exec rm {} \;
fi
}
latest() {
if [[ -z $LATEST_SKIP_BREW ]]; then
if [[ $(which brew 2>/dev/null) ]]; then
brew analytics off
brew update
brew upgrade
brew cleanup
fi
fi
if [[ -z $LATEST_SKIP_NPM ]]; then
if [[ $(which npm 2>/dev/null) ]]; then
npm install -g npm@latest
npm update -g
fi
fi
if [[ -z $LATEST_SKIP_PIPX ]]; then
if [[ $(which pipx 2>/dev/null) ]]; then
pipx upgrade-all
fi
fi
if [[ -z $LATEST_SKIP_UV ]]; then
if [[ $(which uv 2>/dev/null) ]]; then
uv self update
uv tool upgrade --all
fi
fi
}
mdns_list() {
dns-sd -B _services._dns-sd._udp .
}
fi
if [[ $SH_OS_TYPE == Linux ]]; then
# Linux aliases and functions
alias ls='ls --color=auto '
rep() {
eval "$(__sh_color_definitions)"
if [[ $# -eq 0 ]]; then
echo -e "Usage: rep {sed command}"
echo
echo -e "Rep will execute the sed command on all files in the current directory"
echo -e "and subdirectories, excluding any hidden files. All commands will be"
echo -e "executed in place using sed's -i option."
echo
sed --help
echo
else
for x in $(find . -type f -name '*' ! -name '.*' ! -path '*/.*'); do
sed -i "$@" $x
done
# This is a bit dangerous, and assumes that there are no legitimate files
# that start with .!. Probably should be a bit more careful and match
# more specifically
find . -name "\.\!*" -exec rm {} \;
fi
}
if [[ $COLORTERM == gnome-terminal ]] ||
[[ $SESSIONTYPE == gnome-session ]] ||
[[ $XDG_CURRENT_DESKTOP == GNOME ]]; then
ex() {
if [[ $# -eq 0 ]]; then
nautilus . &
else
nautilus "$@" &
fi
}
e() {
gedit "$@" &
}
regedit() {
gconf-editor "$@" &
}
else
e() {
vim "$@"
}
fi
if [[ $SH_OS_DISTRO == CentOS ]]; then
# CentOS aliases and functions
alias __dummy='echo dummy'
# CentOS doesn't have --group-directories-first :-(
# Hence why dir is specific for Ubuntu and Debian
fi
if [[ $SH_OS_DISTRO == Debian ]] ||
[[ $SH_OS_DISTRO == Ubuntu ]] ||
[[ $SH_OS_DISTRO == Raspbian ]]; then
# Debian aliases and functions
alias dir='ls -al --group-directories-first '
latest() {
sudo apt-get update
# sudo apt-get upgrade -y
sudo apt-get --with-new-pkgs upgrade -y
sudo apt-get autoremove -y
sudo snap refresh
if [[ -z $LATEST_SKIP_NPM ]]; then
if [[ $(which npm 2>/dev/null) ]]; then
npm install -g npm@latest
npm update -g
fi
fi
if [[ -z $LATEST_SKIP_PIPX ]]; then
if [[ $(which pipx 2>/dev/null) ]]; then
pipx upgrade-all
fi
fi
if [[ -z $LATEST_SKIP_UV ]]; then
if [[ $(which uv 2>/dev/null) ]]; then
uv self update
uv tool upgrade --all
fi
fi
}
fi
if [[ $SH_OS_DISTRO == Ubuntu ]]; then
# Ubuntu aliases and functions
check_mem() {
local compute_total all_total
compute_total=$(nvidia-smi --query-compute-apps=used_gpu_memory --format=csv,noheader,nounits 2>/dev/null | awk '{s+=$1} END {printf "%.2f", s/1024}')
all_total=$(nvidia-smi 2>/dev/null | awk '/^[|] +[0-9]/ {mem=$(NF-1); gsub(/MiB/, "", mem); s+=mem} END {printf "%.2f", s/1024}')
echo "GPU allocations: ${all_total} GiB total (${compute_total} GiB compute)"
awk '/MemTotal/ {t=$2} /MemAvailable/ {a=$2} END {printf "Unified memory: total=%.2f GiB available=%.2f GiB used_or_cached=%.2f GiB\n", t/1024/1024, a/1024/1024, (t-a)/1024/1024}' /proc/meminfo
echo
echo "Per-process allocations:"
printf "%-8s %-4s %-10s %s\n" "PID" "Type" "Alloc" "Process"
nvidia-smi 2>/dev/null | awk '
/Processes:/ {in_proc=1; next}
in_proc && /^[|]=/ {next}
in_proc && /^[|][ ]*[0-9]/ {
pid=$5
type=$6
mem=$(NF-1)
name=""
for (i=7; i<=NF-2; i++) {
name = name (name ? OFS : "") $i
}
printf "%-8s %-4s %-10s %s\n", pid, type, mem, name
found=1
}
in_proc && /^[+]/ {
if (!found) {
print "none"
}
exit
}
'
}
# Ubuntu has a weird bug with graphical sudo and DBUS
sudo() {
local _SUDO_SAVE=$DBUS_SESSION_BUS_ADDRESS
unset DBUS_SESSION_BUS_ADDRESS
command sudo -E env PATH="$PATH" "$@"
export DBUS_SESSION_BUS_ADDRESS=$_SUDO_SAVE
}
gksudo() {
local _SUDO_SAVE=$DBUS_SESSION_BUS_ADDRESS
unset DBUS_SESSION_BUS_ADDRESS
command gksudo -k "$@" &
export DBUS_SESSION_BUS_ADDRESS=$_SUDO_SAVE
}
fi
if [[ $SH_OS_DISTRO == Yocto ]]; then
# Yocto grep doesn't support --color=auto
unalias grep
ff() {
find . -name "*" -type f -exec grep -HinF "$@" {} \;
}
ff2() {
# Double-grep to filter out grep warnings
grep -RHinF "$@" * 2>&1 | grep -i "$@"
}
fff() {
find . -name "$1" -type f -exec grep -HinF "${@:2}" {} \;
}
fff2() {
# Double-grep to filter out grep warnings
grep -RHinF "${@:2}" "$1" 2>&1 | grep -i "${@:2}"
}
ffs() {
set | grep -i "$@"
}
fp() {
ps | grep -i "$@"
}
fi
if [[ $SH_OS_FLAVOR == WSL ]]; then
# WSL aliases and functions
ex() {
if [[ $# -eq 0 ]]; then
explorer.exe .
else
explorer.exe `wslpath -w $1`
fi
}
e() {
if command -v antigravity >/dev/null 2>&1; then
antigravity "$@"
elif command -v windsurf-next >/dev/null 2>&1; then
windsurf-next "$@"
elif command -v code >/dev/null 2>&1; then
code "$@"
else
vim "$@"
fi
}
fi
fi
if [[ $SH_OS_TYPE == Windows ]]; then
# Windows aliases
alias ls='ls --color=auto'
e() {
vim "$@"
}
ex() {
if [[ $# -eq 0 ]]; then
start .
else
if [[ -d "$1" ]]; then
start "$@"
else
notepad "$@"
fi
fi
}
latest() {
pacman -Syuu
if [[ -z $LATEST_SKIP_PIPX ]]; then
if [[ $(which pipx 2>/dev/null) ]]; then
pipx upgrade-all
fi
fi
if [[ -z $LATEST_SKIP_UV ]]; then
if [[ $(which uv 2>/dev/null) ]]; then
uv self update
uv tool upgrade --all
fi
fi
}
fi
# Late load after bashrc main finished
__aliases_load() {
local ALIASES_LOAD
# Replace the cd builtin to turn off the annoying
# echo-new-folder behavior when CDPATH is set
# and to automatically use the correct node version
# moved to delay load to accomodate zshrc cdpath
cd() {
if [[ $# -eq 0 ]]; then
builtin cd ~ >/dev/null
else
builtin cd "$@" >/dev/null
fi
[[ -f .nvmrc && -r .nvmrc ]] && nvm use || true
}
if [[ $SH_OS_TYPE == OSX ]]; then
# OS X aliases
# Eternal Terminal
if [[ "$LC_TERMINAL" == "iTerm2" ]]; then
if [[ -n `type -t et 2>/dev/null` || -n `whence et 2>/dev/null` ]]; then
ett() {
et -p 8090 -c "tmux -CC a || tmux -CC || /usr/bin/env bash" $*
}
etz() {
et -p 8090 -c "tmux -CC a || tmux -CC || /usr/bin/env zsh" $*
}
fi
fi
# Check if Antigravity is installed
# If not, check if Windsurf is installed
# If not, check if Visual Code is installed
# If not, use default editor
e() {
local CODE_COMMAND WINDSURF_COMMAND AGY_COMMAND
AGY_COMMAND=`type -t agy 2>/dev/null || whence agy 2>/dev/null`
WINDSURF_COMMAND=`type -t windsurf-next 2>/dev/null || whence windsurf-next 2>/dev/null`
CODE_COMMAND=`type -t code 2>/dev/null || whence code 2>/dev/null`
if [[ -n $AGY_COMMAND ]]; then
agy "$@"
elif [[ -n $WINDSURF_COMMAND ]]; then
windsurf-next "$@"
elif [[ -n $CODE_COMMAND ]]; then
code "$@"
else
open -e "$@"
fi
}
fi
}
}
__aliases_main "$@"
unset -f __aliases_main