-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomFunctions
More file actions
executable file
·152 lines (134 loc) · 4.56 KB
/
Copy pathcustomFunctions
File metadata and controls
executable file
·152 lines (134 loc) · 4.56 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
# vim: ft=sh
function extract() {
if [[ -f "$1" ]]; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*.tar.xz) tar xvJf "$1" ;;
*.xz) unxz "$1" ;;
*.tar.zst) tar --zstd -xvf "$1" ;;
*.zst) unzstd "$1" ;;
*) echo "'$1' cannot be extracted via extract" ;;
esac
else
echo "'$1' is not a valid file!"
fi
}
function maketar() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }
function makezip() { zip -r "${1%%/}.zip" "$1" ; }
function cheat() { curl "cht.sh/$1"; }
# Brew helpers with fzf
bip() {
local inst=$(brew search | fzf -m)
[[ $inst ]] && for prog in $(echo $inst); do brew install $prog; done
}
bup() {
local upd=$(brew leaves | fzf -m)
[[ $upd ]] && for prog in $(echo $upd); do brew upgrade $prog; done
}
bcp() {
local uninst=$(brew leaves | fzf -m)
[[ $uninst ]] && for prog in $(echo $uninst); do brew uninstall $prog; done
}
# Misc
mcd() { mkdir -p "$1" && cd "$1"; }
cdl() { cd "$1" && ls; }
backup() { cp "$1"{,.bak}; }
lfind() { find . -iname "$@" 2>/dev/null; }
topcmd() { history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head; }
# Fuzzy tmux session switcher
ts() {
local session
session=$(tmux list-sessions -F "#{session_name}" 2>/dev/null | fzf --height 40% --reverse)
if [[ -n "$session" ]]; then
tmux switch-client -t "$session" 2>/dev/null || tmux attach -t "$session"
fi
}
# Git worktree helpers
gwa() {
if [[ -z $1 ]]; then
echo "Usage: gwa [branch name]"
return 1
fi
local branch="$1"
local base="$(basename "$PWD")"
local wt_path="../${base}--${branch}"
local existing_wt=$(git worktree list --porcelain | grep -B2 "branch refs/heads/$branch$" | grep "^worktree " | cut -d' ' -f2-)
if [[ -n "$existing_wt" ]]; then
if [[ -d "$existing_wt" ]]; then
echo "Branch already in worktree: $existing_wt"
cd "$existing_wt"
return 0
else
echo "Pruning stale worktree: $existing_wt"
git worktree prune
fi
fi
if git show-ref --verify --quiet "refs/heads/$branch"; then
git worktree add "$wt_path" "$branch"
else
git worktree add -b "$branch" "$wt_path"
fi
command -v mise &>/dev/null && mise trust "$wt_path"
cd "$wt_path"
}
gwd() {
command -v gum &>/dev/null || { echo "gum not installed"; return 1; }
if gum confirm "Remove worktree and branch?"; then
local cwd base branch root
cwd="$(pwd)"
worktree="$(basename "$cwd")"
root="${worktree%%--*}"
branch="${worktree#*--}"
if [[ $root != $worktree ]]; then
cd "../$root"
git worktree remove "$worktree" --force
git branch -D "$branch"
fi
fi
}
# AI-powered git commit
gcm() {
command -v llm &>/dev/null || { echo "llm not installed"; return 1; }
generate_commit_message() {
git diff --cached | llm -m "4o" "
Below is a diff of all staged changes, coming from the command:
\`\`\`
git diff --cached
\`\`\`
Please generate a concise, one-line commit message for these changes using the semantic commit convention prefixes: chore:, fix:, feat:, refactor:, docs:, BREAKING:, etc."
}
read_input() {
if [ -n "$ZSH_VERSION" ]; then
echo -n "$1"
read -r REPLY
else
read -p "$1" -r REPLY
fi
}
echo "Generating AI-powered commit message..."
commit_message=$(generate_commit_message)
while true; do
echo -e "\nProposed commit message:"
echo "$commit_message"
read_input "Do you want to (a)ccept, (e)dit, (r)egenerate, or (c)ancel? "
choice=$REPLY
case "$choice" in
a|A ) git commit -m "$commit_message" && echo "Committed!" && return 0 || return 1 ;;
e|E ) read_input "Enter your commit message: "; commit_message=$REPLY
[ -n "$commit_message" ] && git commit -m "$commit_message" && return 0 || return 1 ;;
r|R ) echo "Regenerating..."; commit_message=$(generate_commit_message) ;;
c|C ) echo "Cancelled."; return 1 ;;
* ) echo "Invalid choice." ;;
esac
done
}