-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot_aliases
More file actions
1829 lines (1593 loc) · 68.8 KB
/
Copy pathdot_aliases
File metadata and controls
1829 lines (1593 loc) · 68.8 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
995
996
997
998
999
1000
#################################################################################################################################################
#################################################################################################################################################
#####################################
##################################### Bash Aliases. Feike Li 2020.5.2 ver
##################################### write some documentation formatting here:
#####################################
##################################### 1.temp aliases
##################################### 2.system aliases
##################################### 3.applications
#####################################
#####################################
#################################################################################################################################################
#################################################################################################################################################
#=======================================================================
# TEMP & MISC LAUNCHERS
#=======================================================================
# Temporary aliases and launchers for specific applications.
alias t3='npm create t3-app@latest'
alias disableKeyboard='xinput disable 13 '
alias enableKeyboard='xinput enable 13'
alias enableTapOnClick='xinput set-prop "$(xinput list --name-only | grep -i Touchpad | head -1)" "libinput Tapping Enabled" 1'
alias disableTapOnClick='xinput set-prop "$(xinput list --name-only | grep -i Touchpad | head -1)" "libinput Tapping Enabled" 0'
alias job='uv run job-toolkit '
alias l="fc -s"
#=======================================================================
# CORE SYSTEM & NAVIGATION
#=======================================================================
# Basic aliases for shell navigation, editing config files, and system commands.
alias v='nvim'
alias vv='nvim .'
alias cc='claude --chrome'
alias r='yazi'
alias e='aerc'
alias api='resterm'
alias database='gobang'
alias f='tmux a'
alias c='clear'
alias h='cd $HOME && clear'
alias q='exit'
alias s='cdf'
alias ss='cdf && yazi'
alias clear='clear && tmux clear-history'
alias ls='ls -lAhvFis --color=always --group-directories-first --time-style="+%Y-%m-%d %H:%M"'
alias top='btop'
alias t='btop'
p() { if [ $# -eq 0 ]; then echo "usage: p <command>"; return 1; fi; unbuffer "$@" 2>&1 | less -RiFS --use-color --color=Sky; }
alias tree='tree -a'
alias process='ps -ef | grep'
alias biggestFile='find . -type f -exec du -h {} + | sort -hr | head -20'
alias du='du -h '
cal() {
local CYAN='\033[1;36m'
local GREEN='\033[1;32m'
local YELLOW='\033[1;33m'
local BOLD='\033[1m'
local DIM='\033[2m'
local NC='\033[0m'
local W=76 # inner width; total box = W+2 chars
local CW=$(( (W - 13) / 7 )) # weather column width = 9
local HBAR; HBAR=$(printf '═%.0s' $(seq 1 "$W"))
# $1=plain text (for width measurement), $2=colored display text
_cal_row() {
local plain="$1" display="$2"
local pad=$(( W - ${#plain} - 2 ))
[[ $pad -lt 0 ]] && pad=0
# ${NC} after display resets any ANSI left open by ncal's today-highlight
echo -e "${DIM}║${NC} ${display}${NC}$(printf '%*s' "$pad" "") ${DIM}║${NC}"
}
echo -e "${DIM}╔${HBAR}╗${NC}"
# ── Date ──────────────────────────────────────────────────────────────
local today; today=$(date "+%A, %B %d %Y • %H:%M")
_cal_row "$today" "${BOLD}${CYAN}${today}${NC}"
echo -e "${DIM}╠${HBAR}╣${NC}"
# ── 3-month calendar ──────────────────────────────────────────────────
# unbuffer makes ncal think it's writing to a tty, preserving today's highlight
while IFS= read -r line; do
local plain; plain=$(printf '%s' "$line" | sed 's/\x1b\[[0-9;]*[mK]//g')
if [[ "$plain" =~ (January|February|March|April|May|June|July|August|September|October|November|December) ]]; then
_cal_row "$plain" "${BOLD}${YELLOW}${plain}${NC}"
else
_cal_row "$plain" "$line"
fi
done < <(unbuffer ncal -b -3 2>/dev/null || ncal -b -3)
echo -e "${DIM}╠${HBAR}╣${NC}"
# ── Weather ───────────────────────────────────────────────────────────
local raw; raw=$(ansiweather -l Calgary,CA -u metric -f 7 2>/dev/null \
| perl -pe 's/\x1b\[[0-9;]*[mGKH]//g' \
| tr -d '\n' | sed 's/ */ /g; s/^ //; s/ $//')
local -a NAMES=() DATES=() TEMPS=()
local hdr=""
if echo "$raw" | grep -qi 'forecast:'; then
# Extract city/header (everything before "forecast:")
hdr=$(echo "$raw" | sed -E 's/ *[Ff]orecast:.*//' | sed 's/[[:space:]]*$//')
[[ -n "$hdr" ]] && hdr="${hdr} (°C)"
[[ ${#hdr} -gt $((W - 2)) ]] && hdr="${hdr:0:$((W - 5))}..."
local fcast; fcast=$(echo "$raw" | sed -E 's/.*[Ff]orecast: //')
while IFS= read -r entry; do
entry="${entry# }"; entry="${entry% }"
[[ -z "$entry" ]] && continue
# New format: "Tue Mar 03: 13/-5 °C"
if [[ "$entry" =~ ^[A-Z][a-z]{2}[[:space:]][A-Z][a-z]{2}[[:space:]][0-9] ]]; then
NAMES+=("$(awk '{print $1}' <<< "$entry")")
DATES+=("$(awk '{print $2, $3}' <<< "$entry" | tr -d ':')")
TEMPS+=("$(awk '{print $4}' <<< "$entry")") # Hi/Lo only, strip °C (° is 2-cell wide)
# Old format: "Mon - Clear - 5/15 °C"
else
NAMES+=("$(awk -F' - ' '{print $1}' <<< "$entry")")
DATES+=("$(awk -F' - ' '{print $2}' <<< "$entry")")
TEMPS+=("$(awk -F' - ' '{print $3}' <<< "$entry" | sed 's/ °C$//')")
fi
done < <(echo "$fcast" | sed -E 's/ - (Mon|Tue|Wed|Thu|Fri|Sat|Sun)/\n\1/g' | grep .)
else
hdr="$raw"
[[ ${#hdr} -gt $((W - 2)) ]] && hdr="${hdr:0:$((W - 5))}..."
fi
if [[ -n "$hdr" ]]; then
_cal_row "$hdr" "${GREEN}${hdr}${NC}"
echo -e "${DIM}╠${HBAR}╣${NC}"
fi
# ── 7-column forecast table ───────────────────────────────────────────
local n=${#NAMES[@]}
if [[ $n -gt 0 ]]; then
local r1="${DIM}║${NC}" r2="${DIM}║${NC}" r3="${DIM}║${NC}"
local sep
for (( i=0; i<n; i++ )); do
[[ $i -lt $((n-1)) ]] && sep="${DIM}│${NC}" || sep="${DIM}║${NC}"
r1+=" ${BOLD}${CYAN}$(printf "%-${CW}.${CW}s" "${NAMES[$i]:-}")${NC}${sep}"
r2+=" ${YELLOW}$(printf "%-${CW}.${CW}s" "${DATES[$i]:-}")${NC}${sep}"
r3+=" ${GREEN}$(printf "%-${CW}.${CW}s" "${TEMPS[$i]:-}")${NC}${sep}"
done
echo -e "$r1"
echo -e "$r2"
echo -e "$r3"
fi
echo -e "${DIM}╚${HBAR}╝${NC}"
printf "\n"
}
alias neofetch='fastfetch'
#=======================================================================
# CONFIGURATION & EDITING SHORTCUTS
#=======================================================================
# Quick access to edit configuration files and other specific text files.
alias password='nvim ~/Documents/feeco/1.lifeike/password.txt'
alias config='cd ~/.config && yazi'
alias vali='nvim ~/.aliases'
alias vbash='nvim ~/.bashrc'
alias vhistory='nvim ~/.bash_history'
#=======================================================================
# DIRECTORY SHORTCUTS
#=======================================================================
# Quick navigation to frequently used directories.
alias d='cd /home/feeco/Downloads && yazi'
repos() {
local dir
dir=$(find ~/Documents -maxdepth 3 -name .git -type d 2>/dev/null | sed 's|/.git$||' | fzf --height=40% --reverse --prompt='Repo> ')
if [[ -n "$dir" ]]; then
cd "$dir"
else
cd ~/Documents && yazi
fi
}
alias desktop='cd /home/feeco/Desktop && yazi'
alias video='cd /home/feeco/Videos && yazi'
alias picture='cd /home/feeco/Pictures && yazi'
alias music='cd /home/feeco/Music && yazi'
#=======================================================================
# SEARCH, HISTORY & BOOKMARKS
#=======================================================================
# Fuzzy search for files, history, and marked directories.
cdf() {
cd ~
local file
local dir
file=$(fzf +m -q "$1") && dir=$(dirname "$file")
cd "$dir"
pwd
}
# find available commands from .bashrc .alias and command history
alias lc='eval $(fh)'
fh() {
set -o history
HISTFILE=~/.bash_history
local cmd
# STAGE 1: Search Aliases and Functions
cmd=$( (alias; declare -F | cut -d' ' -f3) |
fzf --height=40% --border --prompt='Alias/Func> ' \
--header='Searching Aliases & Functions (ESC to search History)' \
--bind='tab:down,shift-tab:up' --select-1 --exit-0)
# STAGE 2: If nothing found in Stage 1, search History
if [[ -z "$cmd" ]]; then
cmd=$(history | tac | sed 's/^[[:space:]]*[0-9]\+[[:space:]]*//' | awk '!seen[$0]++' |
fzf --height=80% --border --prompt='History> ' \
--bind='tab:down,shift-tab:up')
fi
# Execution logic
if [[ -n "$cmd" ]]; then
# If it was an alias, clean the 'alias ' prefix and '=...' suffix to get the name
if [[ "$cmd" == alias* ]]; then
cmd=$(echo "$cmd" | sed "s/^alias //; s/='.*$//")
fi
echo "$cmd"
fi
}
# mark current directory as marked list
mm() {
echo "$PWD" >> "$HOME/.marked_directories"
echo "Marked: $PWD"
}
# search marked list with fzf
lm() {
if [[ ! -f "$HOME/.marked_directories" ]]; then
echo "No directories marked yet."
return 1
fi
local dir
dir=$(cat "$HOME/.marked_directories" | fzf)
[[ -n "$dir" ]] && cd "$dir" && echo "Changed directory to: $dir"
}
#=======================================================================
# NETWORKING
#=======================================================================
# Functions and aliases for managing Wi-Fi and inspecting network ports.
alias wifilist='nmcli device wifi list'
show_connected_wifi(){
nmcli connection show
}
delete_connected_wifi(){
read -r -p "Enter SSID: " ssid
nmcli connection delete "$ssid"
}
connect_wifi() {
read -r -p "Enter SSID: " ssid
read -r -s -p "Enter Password: " password
echo
sudo nmcli device wifi connect "$ssid" password "$password"
}
port() {
local search_term="${1:-}"
local GREEN='\033[0;32m'
local BLUE='\033[0;34m'
local YELLOW='\033[1;33m'
local CYAN='\033[1;36m'
local NC='\033[0m'
echo -e "\n╔════════════════════════════════════════════════════════════════════════════╗"
echo -e "║ NETWORK PORTS & CONNECTIONS ║"
echo -e "╚════════════════════════════════════════════════════════════════════════════╝\n"
printf "%-10s %-25s %-10s %-15s %-12s %s\n" "PROTO" "LOCAL ADDRESS" "PORT" "STATE" "PID" "PROGRAM"
echo "────────────────────────────────────────────────────────────────────────────────────────"
sudo netstat -tulpn 2>/dev/null | grep -v "^Active\|^Proto" | while read -r line; do
[ -z "$line" ] && continue
proto=$(echo "$line" | awk '{print $1}')
local_addr=$(echo "$line" | awk '{print $4}')
if [[ $proto == udp* ]]; then
state="-"
pid_program=$(echo "$line" | awk '{print $6}')
else
state=$(echo "$line" | awk '{print $6}')
pid_program=$(echo "$line" | awk '{print $7}')
fi
if [[ $local_addr == *":"* ]]; then
ip=$(echo "$local_addr" | rev | cut -d: -f2- | rev)
port=$(echo "$local_addr" | rev | cut -d: -f1 | rev)
else
ip="N/A"
port="N/A"
fi
if [[ $pid_program == *"/"* ]]; then
pid=$(echo "$pid_program" | cut -d/ -f1)
program=$(echo "$pid_program" | cut -d/ -f2-)
elif [[ $pid_program == "-" ]]; then
pid="-"
program="-"
else
pid="${pid_program:-N/A}"
program="N/A"
fi
[ -n "$search_term" ] && ! echo "$line $program $port" | grep -qi "$search_term" && continue
case $proto in
tcp*) proto_colored="${GREEN}${proto}${NC}" ;;
udp*) proto_colored="${BLUE}${proto}${NC}" ;;
*) proto_colored="$proto" ;;
esac
case $state in
LISTEN) state_colored="${YELLOW}${state}${NC}" ;;
ESTABLISHED) state_colored="${GREEN}${state}${NC}" ;;
*) state_colored="$state" ;;
esac
port_colored="${CYAN}${port}${NC}"
printf "%-10s %-25s %-10s %-15s %-12s %s\n" "$proto" "$ip" "$port" "$state" "$pid" "$program" | \
sed -E "s/^(tcp[^ ]*)/$(echo -e ${GREEN})\1$(echo -e ${NC})/" | \
sed -E "s/^(udp[^ ]*)/$(echo -e ${BLUE})\1$(echo -e ${NC})/" | \
sed -E "s/([0-9]+)( +LISTEN)/$(echo -e ${CYAN})\1$(echo -e ${NC})\2/" | \
sed -E "s/([0-9]+)( +-)/$(echo -e ${CYAN})\1$(echo -e ${NC})\2/" | \
sed -E "s/LISTEN/$(echo -e ${YELLOW})LISTEN$(echo -e ${NC})/" | \
sed -E "s/ESTABLISHED/$(echo -e ${GREEN})ESTABLISHED$(echo -e ${NC})/"
done
echo "────────────────────────────────────────────────────────────────────────────────────────"
echo -e "\n💡 Usage: port [search_term] | Examples: port nginx | ports 80\n"
}
portlistening() {
local CYAN='\033[1;36m'
local GREEN='\033[0;32m'
local NC='\033[0m'
echo -e "\n🔊 LISTENING PORTS\n"
printf "%-10s %-12s %-25s\n" "PROTO" "PORT" "PROGRAM"
echo "───────────────────────────────────────────────────────"
sudo netstat -tulpn 2>/dev/null | grep LISTEN | awk '{print $1, $4, $7}' | \
while read proto addr pidprog; do
port=$(echo "$addr" | rev | cut -d: -f1 | rev)
prog=$(echo "$pidprog" | cut -d/ -f2-)
printf "%-10s %-12s %-25s\n" "$proto" "$port" "$prog"
done | sort -k2 -n | while IFS= read -r line; do
echo "$line" | sed -E "s/^(tcp[^ ]*)/\\$(echo -e '\033[0;32m')\1\\$(echo -e '\033[0m')/" | \
sed -E "s/([0-9]+)/\\$(echo -e '\033[1;36m')\1\\$(echo -e '\033[0m')/"
done
echo ""
}
look() {
if [ $# -eq 0 ]; then
echo "Please provide a domain name."
return 1
fi
local domain="$1"
whois "$domain" | \
awk '/Creation Date/ {print "\033[31m" $0 "\033[0m"} {print}' | \
less -R
}
#=======================================================================
# HARDWARE & DISPLAY
#=======================================================================
# Control screen brightness, rotation, and audio volume.
alias d1='xrandr --output DP-2 --brightness 0.5'
alias d2='xrandr --output DP-2 --brightness 0.7'
alias d3='xrandr --output DP-2 --brightness 0.9'
alias d4='xrandr --output DP-2 --brightness 1.1'
alias l1='xrandr --output eDP --brightness 0.6'
alias l2='xrandr --output eDP --brightness 0.8'
alias l3='xrandr --output eDP --brightness 1'
alias l4='xrandr --output eDP --brightness 1.2'
alias secondMonitorRotation='xrandr --output DP-1 --rotate left'
alias volume='alsamixer'
#=======================================================================
# FILE & TEXT MANIPULATION
#=======================================================================
# Aliases and functions for file conversion, extraction, and formatting.
alias unrarall='for file in *.rar; do unrar e -p "$file"; done'
alias unzipgarbled='unzip -O cp936 '
alias convertallpdf='ls *.pdf | xargs -n1 pdftotext'
alias convertallpdftopng=allpdftopng
function allpdftopng(){
for file in *.pdf;
do pdftoppm "$file" "$file";
done
}
alias convertpptxtopdf='libreoffice --headless --invisible --convert-to pdf *.pptx'
alias convertdocxtotxt='libreoffice --headless --convert-to txt'
alias convertjpgtopdf='convert *.jpg output.pdf'
md2pdf_batch() {
local tmp_css="__temp_style.css"
cat > "$tmp_css" <<'EOF'
body { margin: 5mm; font-family: sans-serif; }
pre { background-color: #eaeaea; color: #000000; padding: 10px; border-radius: 4px; overflow-x: auto; border: 1px solid #cccccc; }
code { font-family: monospace; }
code span.kw { font-weight: bold; }
code span.st { font-style: italic; }
code span.co { color: #555555; }
code span.fu { text-decoration: underline; }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid; }
table { border-collapse: collapse; }
table, th, td { border: 1px solid #ccc; padding: 4px; }
EOF
for f in *.md; do
[[ -f "$f" ]] || continue
echo "Converting $f → ${f%.md}.pdf"
pandoc "$f" -o "${f%.md}.pdf" \
--pdf-engine=wkhtmltopdf \
-V margin-top=5mm \
-V margin-bottom=5mm \
-V margin-left=5mm \
-V margin-right=5mm \
--css="$tmp_css" \
--pdf-engine-opt=--enable-local-file-access
done
rm -f "$tmp_css"
echo "✅ All Markdown files converted."
}
#=======================================================================
# PACKAGE MANAGEMENT & SYSTEM UPDATES
#=======================================================================
# Aliases for installing, removing, and updating system packages.
alias install='sudo apt install -y'
alias remove='sudo apt purge -y'
alias installed=manually_installed
function manually_installed(){
comm -23 <(apt-mark showmanual | sort -u) <(gzip -dc /var/log/installer/initial-status.gz | sed -n 's/^Package: //p' | sort -u)
}
alias update=updateall
function updateall(){
sudo apt upgrade;
sudo apt-get upgrade;
sudo apt update;
sudo apt-get update;
updateChrome;
sudo snap refresh;
sudo apt-get clean;
sudo apt clean;
sudo apt autoremove;
sudo apt-get autoremove;
sudo apt-get autoclean;
sudo apt autoclean;
}
function clean(){
sudo apt-get clean;
sudo apt clean;
sudo apt autoremove;
sudo apt-get autoremove;
sudo apt-get autoclean;
sudo apt autoclean;
}
updateChrome(){
cd $HOME
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
rm google-chrome-stable_current_amd64.deb
}
#=======================================================================
# GIT & GITHUB WORKFLOW
#=======================================================================
# A comprehensive set of aliases and functions to streamline Git and GitHub usage.
# ── Project shortcut ──────────────────────────────────────────────────
alias lifeike='cd /home/feeco/Documents/feeco && gb && gs && yazi'
# ── Status & inspection ───────────────────────────────────────────────
# gs: pretty working-tree status with staged/modified/untracked breakdown
gs() {
local CYAN='\033[1;36m'
local GREEN='\033[1;32m'
local RED='\033[1;31m'
local YELLOW='\033[1;33m'
local MAGENTA='\033[1;35m'
local BLUE='\033[1;34m'
local DIM='\033[2m'
local NC='\033[0m'
local branch=$(git branch --show-current 2>/dev/null)
local repo=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)")
local ahead_behind=$(git rev-list --left-right --count HEAD...@{upstream} 2>/dev/null)
local ahead=$(echo "$ahead_behind" | cut -f1)
local behind=$(echo "$ahead_behind" | cut -f2)
echo -e "\n${DIM}╔════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${DIM}║${NC} ${MAGENTA}${repo}${NC} ${DIM}│${NC} ${CYAN}${branch}${NC} ${ahead:+${GREEN}↑$ahead${NC}} ${behind:+${RED}↓$behind${NC}}"
echo -e "${DIM}╠════════════════════════════════════════════════════════════════════════════╣${NC}"
local has_changes=false
while IFS= read -r line; do
[[ -z "$line" ]] && continue
has_changes=true
local status="${line:0:2}"
local file="${line:3}"
case "$status" in
"M ") echo -e "${DIM}║${NC} ${GREEN} staged${NC} $file" ;;
" M") echo -e "${DIM}║${NC} ${CYAN} modified${NC} $file" ;;
"MM") echo -e "${DIM}║${NC} ${YELLOW} partial${NC} $file" ;;
"A ") echo -e "${DIM}║${NC} ${GREEN} added${NC} $file" ;;
"AM") echo -e "${DIM}║${NC} ${YELLOW} added+mod${NC} $file" ;;
" D") echo -e "${DIM}║${NC} ${RED} deleted${NC} $file" ;;
"D ") echo -e "${DIM}║${NC} ${RED} staged-del${NC}$file" ;;
"R ") echo -e "${DIM}║${NC} ${BLUE} renamed${NC} $file" ;;
"??") echo -e "${DIM}║${NC} ${YELLOW} untracked${NC} $file" ;;
"UU") echo -e "${DIM}║${NC} ${RED} conflict${NC} $file" ;;
*) echo -e "${DIM}║${NC} ${DIM}$status${NC} $file" ;;
esac
done < <(git status --short 2>/dev/null)
if [[ "$has_changes" == false ]]; then
echo -e "${DIM}║${NC} ${GREEN} clean${NC} working tree is clean"
fi
echo -e "${DIM}╚════════════════════════════════════════════════════════════════════════════╝${NC}\n"
}
# gb: list local and remote branches with hash, date, and subject
gb() {
local CYAN='\033[1;36m'
local GREEN='\033[1;32m'
local RED='\033[1;31m'
local YELLOW='\033[1;33m'
local MAGENTA='\033[1;35m'
local BLUE='\033[1;34m'
local DIM='\033[2m'
local NC='\033[0m'
local current
current=$(git branch --show-current 2>/dev/null)
echo -e "\n${DIM}╔════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${DIM}║${NC} ${MAGENTA}branches${NC} ${DIM}on${NC} ${CYAN}${current}${NC}"
echo -e "${DIM}╠════════════════════════════════════════════════════════════════════════════╣${NC}"
echo -e "${DIM}║${NC} ${YELLOW}local${NC}"
git branch --format='%(refname:short)|%(objectname:short)|%(committerdate:relative)|%(subject)' | \
while IFS='|' read -r branch hash date msg; do
if [[ "$branch" == "$current" ]]; then
echo -e "${DIM}║${NC} ${GREEN}★${NC} ${CYAN}${branch}${NC} ${DIM}${hash}${NC} ${BLUE}${date}${NC} ${msg}"
else
echo -e "${DIM}║${NC} ${branch} ${DIM}${hash} ${date} ${msg}${NC}"
fi
done
if git branch -r 2>/dev/null | grep -q .; then
echo -e "${DIM}║${NC}"
echo -e "${DIM}║${NC} ${RED}remote${NC}"
git branch -r --format='%(refname:short)|%(objectname:short)|%(committerdate:relative)|%(subject)' | \
while IFS='|' read -r branch hash date msg; do
echo -e "${DIM}║${NC} ${RED}${branch}${NC} ${DIM}${hash} ${date} ${msg}${NC}"
done
fi
echo -e "${DIM}╚════════════════════════════════════════════════════════════════════════════╝${NC}\n"
}
# gl: pretty graph log (default: last 40 commits across all branches)
gl() {
local fmt="%C(bold yellow)%<(9,trunc)%h%C(reset) %C(bold blue)%<(14,trunc)%ar%C(reset) %C(green)%<(17,trunc)%an%C(reset) %C(white)%s%C(reset)%C(bold magenta)%d%C(reset)"
git log \
--graph \
--abbrev-commit \
--all \
--topo-order \
--format=format:"$fmt" \
"${@:--40}"
}
# gitlastcommit: fzf-browse files changed in the last commit with diff preview
alias gitlastcommit='git diff --name-only HEAD^ | fzf --ansi \
--preview "git diff --color=always HEAD^ -- {}" \
--preview-window "right:70%" \
--bind "tab:down,shift-tab:up,ctrl-k:preview-up,ctrl-j:preview-down"'
alias gitcommitscount='git shortlog -sn --all' # commit count per author
alias gitbigfile='git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10' # top 10 largest tracked files
# ── Conflicts & checks ────────────────────────────────────────────────
alias gitlistconflicts='git diff --check' # show whitespace/conflict markers
alias gitconflict='git diff --name-only --diff-filter=U' # list files with merge conflicts
# ── Tags ──────────────────────────────────────────────────────────────
alias gt='echo "local tags: " && git tag -n && echo "" && echo "" && echo "remote tags: " && git ls-remote --tags'
alias gnewtag='git tag -a'
# ── Commit & push ─────────────────────────────────────────────────────
alias gr='git reset --hard && git clean -fd' # hard reset + clean untracked files
alias gp='pushall'
# pushall: prompt for commit message, stage all, commit, and push current branch
function pushall(){
IFS= read -r -p "commit message: " commitMessage
git add -A;
git commit --allow-empty -am "$commitMessage";
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
git push -u origin $branch
clear
}
# ── Pull & sync ───────────────────────────────────────────────────────
# pull: fetch all remotes and pull/track every remote branch
pull() {
local CYAN='\033[1;36m'
local GREEN='\033[1;32m'
local RED='\033[1;31m'
local YELLOW='\033[1;33m'
local MAGENTA='\033[1;35m'
local BLUE='\033[1;34m'
local DIM='\033[2m'
local NC='\033[0m'
local current
current=$(git branch --show-current 2>/dev/null)
if [[ -z "$current" ]]; then
echo -e "${RED}✗ Not in a git repository.${NC}"
return 1
fi
local repo
repo=$(basename "$(git rev-parse --show-toplevel 2>/dev/null)")
echo -e "\n${DIM}╔════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${DIM}║${NC} ${MAGENTA}pull${NC} ${DIM}│${NC} ${CYAN}${repo}${NC} ${DIM}on${NC} ${GREEN}${current}${NC}"
echo -e "${DIM}╠════════════════════════════════════════════════════════════════════════════╣${NC}"
{ git fetch --all; } 2>&1 | while IFS= read -r line; do
echo -e "${DIM}║${NC} ${DIM}${line}${NC}"
done
git branch -r | grep -v '\->' | sed 's|origin/||' | while read -r branch; do
echo -e "${DIM}║${NC}"
if git show-ref --verify --quiet "refs/heads/$branch"; then
echo -e "${DIM}║${NC} ${CYAN}↓ pulling ${NC}${branch}"
{ git checkout "$branch" && git pull origin "$branch"; } 2>&1 | while IFS= read -r line; do
echo -e "${DIM}║${NC} ${line}"
done
else
echo -e "${DIM}║${NC} ${YELLOW}⊕ tracking ${NC}${branch}"
{ git checkout --track "origin/$branch"; } 2>&1 | while IFS= read -r line; do
echo -e "${DIM}║${NC} ${line}"
done
fi
echo -e "${DIM}║${NC}"
done
git checkout "$current"
echo -e "${DIM}╚════════════════════════════════════════════════════════════════════════════╝${NC}\n"
}
# ── Deploy ────────────────────────────────────────────────────────────
# gitdeploy: merge current branch into main, push, then return to original branch
function gitdeploy(){
local current
current=$(git branch --show-current)
git checkout main
git merge "$current"
git push origin main
git checkout "$current"
}
# ── Pull requests & issues ────────────────────────────────────────────
# pr: commit, push current branch, and open a PR with auto-filled title/body
pr() {
local branch
branch=$(git branch --show-current)
git add -A
git commit
git push -u origin "$branch"
gh pr create --fill
}
alias gittodolist='gh issue list' # list open issues
alias gittodo='gh issue create' # create a new issue
# ── GitHub auth & account switching ──────────────────────────────────
alias githublogin='gh auth login'
alias githubbrowser='gh browse'
declare -A GH_ALIAS_MAP=(
[hankAndfeeco]=hankAndfeeco
[lifeike]=lifeike
)
# github: switch gh account and list all repos + org repos for that user
github() {
local user
user=$(gh auth status 2>&1 | grep -oP 'account \K\S+' | fzf --height=40% --reverse --prompt='GitHub User> ')
if [[ -n "$user" ]]; then
gh auth switch --user "$user"
echo "=== $user ==="
gh repo list "$user" --limit 100
local orgs
orgs=$(gh api user/orgs --jq '.[].login' 2>/dev/null)
for org in $orgs; do
echo ""
echo "=== $org ==="
gh repo list "$org" --limit 100
done
fi
}
# ── Clone & fork & Create ──────────────────────────────────────────────────────
alias githubrepos='ghclone'
alias githuborganizationrepos='ghcloneorg'
alias githubcreaterepo='gh repo create'
alias githubdeleterepo='gh repo delete'
# ghclone: fzf-pick from all personal, collaborator, and org repos then clone
ghclone() {
local repo
repo=$(
{
gh repo list \
--limit 100 \
--json nameWithOwner,description \
--jq '.[] | "\(.nameWithOwner)\t\(.description // "")"'
gh api "user/repos?affiliation=collaborator&per_page=100" \
--paginate \
--jq '.[] | "\(.full_name)\t\(.description // "")"' 2>/dev/null
gh api user/orgs --jq '.[].login' 2>/dev/null | while read -r org; do
gh repo list "$org" \
--limit 100 \
--json nameWithOwner,description \
--jq '.[] | "\(.nameWithOwner)\t\(.description // "")"' 2>/dev/null
done
} | sort -u |
fzf \
--height=80% \
--layout=reverse \
--prompt="Clone repo > " \
--delimiter=$'\t' \
--with-nth=1,2 \
--bind='tab:down,shift-tab:up,ctrl-j:down,ctrl-k:up' \
--preview 'echo {2}' \
--preview-window=down:3:wrap |
cut -f1
)
[[ -n "$repo" ]] && gh repo clone "$repo"
}
# ghcloneorg: fzf-pick an org then a repo within it, then clone
ghcloneorg() {
local org
org=$(gh api user/orgs --jq '.[].login' 2>/dev/null | fzf --height=40% --reverse --prompt='Organization> ')
[[ -z "$org" ]] && return
local repo
repo=$(
gh repo list "$org" \
--limit 100 \
--json nameWithOwner,description \
--jq '.[] | "\(.nameWithOwner)\t\(.description // "")"' |
fzf \
--height=80% \
--layout=reverse \
--prompt="$org repo > " \
--delimiter=$'\t' \
--with-nth=1,2 \
--bind='tab:down,shift-tab:up,ctrl-j:down,ctrl-k:up' \
--preview 'echo {2}' \
--preview-window=down:3:wrap |
cut -f1
)
[[ -n "$repo" ]] && gh repo clone "$repo"
}
# gc: clone a repo, track all remote branches, then open in nvim
gc() {
local repo_dir
repo_dir=$(basename "${1%/}" .git)
gh repo clone "$1" || return
cd "$repo_dir" || return
for branch in $(git branch -r | grep -v '\->'); do
git branch --track "${branch#origin/}" "$branch" 2>/dev/null
done
git fetch --all
nvim .
}
# gf: fork a repo, clone it, track all remote branches, then open in nvim
gf() {
local repo_dir
repo_dir=$(basename "${1%/}" .git)
gh repo fork "$1" --clone || return
cd "$repo_dir" || return
for branch in $(git branch -r | grep -v '\->'); do
git branch --track "${branch#origin/}" "$branch" 2>/dev/null
done
git fetch --all
nvim .
}
# githubsearch: interactive GitHub repo search with rich metadata preview and optional clone
githubsearch() {
local CYAN='\033[1;36m'
local GREEN='\033[1;32m'
local RED='\033[1;31m'
local YELLOW='\033[1;33m'
local MAGENTA='\033[1;35m'
local BLUE='\033[1;34m'
local DIM='\033[2m'
local NC='\033[0m'
local BOLD='\033[1m'
local query="$*"
if [[ -z "$query" ]]; then
IFS= read -r -p "Search GitHub repos: " query
[[ -z "$query" ]] && return
fi
echo -e "\n${DIM}Searching GitHub for: ${NC}${CYAN}${query}${NC}\n"
local selected
selected=$(
gh search repos "$query" \
--limit 50 \
--json fullName,description,stargazersCount,language,forksCount \
--jq '.[] | "\(.fullName)\t⭐\(.stargazersCount) 🍴\(.forksCount) [\(.language // "?")]\t\(.description // "")"' |
fzf \
--height=80% \
--layout=reverse \
--prompt="GitHub Search> " \
--delimiter=$'\t' \
--with-nth=1,2,3 \
--bind='tab:down,shift-tab:up,ctrl-j:down,ctrl-k:up' \
--preview='gh repo view {1} 2>/dev/null' \
--preview-window=right:55%:wrap \
--header="Results for: $query" |
cut -f1
)
[[ -z "$selected" ]] && return
echo -e "\n${DIM}Fetching repo data...${NC}"
local meta commits issues prs contributors
meta=$(gh api "repos/$selected" 2>/dev/null)
commits=$(gh api "repos/$selected/commits?per_page=10" 2>/dev/null)
issues=$(gh api "repos/$selected/issues?state=open&per_page=10" 2>/dev/null)
prs=$(gh api "repos/$selected/pulls?state=open&per_page=10" 2>/dev/null)
contributors=$(gh api "repos/$selected/contributors?per_page=10" 2>/dev/null)
local W=76
local HBAR; HBAR=$(printf '═%.0s' $(seq 1 $W))
_ghs_row() { echo -e "${DIM}║${NC} $1"; }
echo -e "${DIM}╔${HBAR}╗${NC}"
# Header: repo name + stats
local stars forks lang license desc homepage topics created updated open_issues owner_type
stars=$(echo "$meta" | jq -r '.stargazers_count // 0')
forks=$(echo "$meta" | jq -r '.forks_count // 0')
lang=$(echo "$meta" | jq -r '.language // "unknown"')
license=$(echo "$meta" | jq -r '.license.spdx_id // "no license"')
desc=$(echo "$meta" | jq -r '.description // ""')
homepage=$(echo "$meta" | jq -r '.homepage // ""')
topics=$(echo "$meta" | jq -r '.topics | join(", ")' 2>/dev/null)
created=$(echo "$meta" | jq -r '.created_at[:10]')
updated=$(echo "$meta" | jq -r '.updated_at[:10]')
open_issues=$(echo "$meta" | jq -r '.open_issues_count // 0')
owner_type=$(echo "$meta" | jq -r '.owner.type // ""')
_ghs_row " ${BOLD}${MAGENTA}${selected}${NC} ${YELLOW}⭐ $stars${NC} ${BLUE}🍴 $forks${NC} ${GREEN}$lang${NC} ${DIM}$license${NC}"
[[ -n "$desc" ]] && _ghs_row " ${desc}"
[[ -n "$homepage" ]] && _ghs_row " ${DIM}🌐 $homepage${NC}"
[[ -n "$topics" ]] && _ghs_row " ${DIM}tags:${NC} $topics"
_ghs_row " ${DIM}owner: $owner_type • created: $created • updated: $updated • open issues: $open_issues${NC}"
echo -e "${DIM}╠${HBAR}╣${NC}"
# Last 10 commits
_ghs_row " ${BOLD}${CYAN}Last 10 Commits${NC}"
echo "$commits" | jq -r '.[] | "\(.commit.committer.date[:10]) \(.commit.author.name) \(.commit.message | split("\n")[0])"' 2>/dev/null | \
while IFS= read -r line; do
local date author msg
date=$(echo "$line" | awk '{print $1}')
author=$(echo "$line" | awk '{print $2}')
msg=$(echo "$line" | cut -d' ' -f3-)
_ghs_row " ${BLUE}$date${NC} ${GREEN}$author${NC} ${msg}"
done
echo -e "${DIM}╠${HBAR}╣${NC}"
# Last 10 open issues
_ghs_row " ${BOLD}${YELLOW}Last 10 Open Issues${NC}"
echo "$issues" | jq -r '.[] | select(.pull_request == null) | "#\(.number) \(.user.login) \(.title)"' 2>/dev/null | head -10 | \
while IFS= read -r line; do
_ghs_row " ${YELLOW}$(echo "$line" | awk '{print $1}')${NC} ${DIM}$(echo "$line" | awk '{print $2}')${NC} $(echo "$line" | cut -d' ' -f3-)"
done
echo -e "${DIM}╠${HBAR}╣${NC}"
# Last 10 open PRs
_ghs_row " ${BOLD}${CYAN}Last 10 Open Pull Requests${NC}"
echo "$prs" | jq -r '.[] | "#\(.number) \(.user.login) \(.title)"' 2>/dev/null | head -10 | \
while IFS= read -r line; do
_ghs_row " ${CYAN}$(echo "$line" | awk '{print $1}')${NC} ${DIM}$(echo "$line" | awk '{print $2}')${NC} $(echo "$line" | cut -d' ' -f3-)"
done
echo -e "${DIM}╠${HBAR}╣${NC}"
# Top 10 contributors
_ghs_row " ${BOLD}${GREEN}Top 10 Contributors${NC}"
echo "$contributors" | jq -r '.[] | "\(.login) \(.contributions)"' 2>/dev/null | head -10 | \
while IFS= read -r line; do
local login contribs
login=$(echo "$line" | awk '{print $1}')
contribs=$(echo "$line" | awk '{print $2}')
_ghs_row " ${GREEN}$login${NC} ${DIM}$contribs commits${NC}"
done
echo -e "${DIM}╚${HBAR}╝${NC}\n"
local choice
IFS= read -r -p "Clone this repo? [y/N] " choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
gc "$selected"
fi
}
alias ghs='githubsearch'
#=======================================================================
# TMUX - TERMINAL MULTIPLEXER
#=======================================================================
# Functions and aliases for managing Tmux sessions, windows, and layouts.
alias tnewsession=createNewSessionInsideTmuxSession
alias tkill=killTmuxSession
alias layout=defaultLayout
alias project=projectLayout
alias tnewwindow='tmux new-window -n '
alias twindowname='tmux rename-window '
alias tsessionname='tmux rename-session '
alias lw='tmw'
alias w='tmw'
tmw() {
local target
target=$(tmux list-windows -a -F "#{session_name}:#{window_index} | #{session_name} > #{window_name} #{?window_active,(active),}" | \
fzf-tmux -p 80% --reverse --header "Search Sessions & Windows" \
--delimiter "|" --with-nth 2 | \
cut -d " " -f 1)
if [[ -n "$target" ]]; then
tmux switch-client -t "${target%:}"
fi
}
function createNewSessionInsideTmuxSession(){
session_name=$1
tmux has-session -t=$session_name 2> /dev/null
if [[ $? -ne 0 ]]; then
TMUX='' tmux new-session -d -s "$session_name"
fi
if [[ -z "$TMUX" ]]; then
tmux attach -t "$session_name"
else
tmux switch-client -t "$session_name"
fi
}
function killTmuxSession(){
tls;
IFS= read -r -p "input session name: " sessionName
tmux switch-client -t main &&
tmux kill-session -t "$sessionName" ;
}
function defaultLayout(){
tmux selectp -t 0;
tmux splitw -v -p 40;
tmux splitw -h -p 50;
tmux splitw -v -p 50;