forked from jessfraz/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.functions_git
179 lines (154 loc) · 4.88 KB
/
.functions_git
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
#!/bin/bash
# gb - checkout git branch
gb() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local branches branch
branches=$(git --no-pager branch -vv) &&
branch=$(echo "$branches" | fzf-tmux +m) &&
git checkout $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
gbd() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local branches branch
branches=$(git --no-pager branch -vv) &&
branch=$(echo "$branches" | fzf-tmux +m) &&
git branch -D $(echo "$branch" | awk '{print $1}' | sed "s/.* //")
}
# gco - checkout git branch (including remote branches)
gco() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
if [ "$1" == "-" ]; then
git checkout -
return
fi
if [ -n "$1" ]; then
git checkout $1,
return
fi
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# gmb - merge git branch (including remote branches)
gmb() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
echo git merge $(echo "$branch" | sed "s/.* //" | sed "s/remotes\///")
git merge $(echo "$branch" | sed "s/.* //" | sed "s/remotes\///")
}
# gfc - show git commit
gfc() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local commits commit
commits=$(git log --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf-tmux --tac +s +m -e) &&
git show $(echo "$commit" | sed "s/ .*//")
}
gd() (
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local branches branch target
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
target=$(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && echo ${files} && git diff ${target} "${files[@]}"
)
gl() (
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
[[ -n "$files" ]] && echo ${files} && git lg "${files[@]}"
)
gls() (
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
local commits commit
IFS=$'\n' files=($(fzf-tmux --query="$1" --multi --select-1 --exit-0))
commits=$(git log --pretty=oneline --abbrev-commit --reverse "$files") &&
commit=$(echo "$commits" | fzf-tmux --tac +s +m -e) &&
git show $(echo "$commit" | sed "s/ .*//") "$files"
)
gfm() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
if [ -z "$1" ]; then
echo "No commit message specified"
return
fi
local commits commit branches branch trimmed_branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
(echo "-$branch-" | sed "s/.* //" | sed "s/remotes\///")
trimmed_branch=$(echo $branch | tr -d ' ')
git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --reverse --date=short --decorate --no-merges -E --grep="(${1})" "${trimmed_branch}"
}
gfmp() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
if [ -z "$1" ]; then
echo "No commit message specified"
return
fi
local commits commit branches branch trimmed_branch commit_list_file
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
(echo "-$branch-" | sed "s/.* //" | sed "s/remotes\///")
trimmed_branch=$(echo $branch | tr -d ' ')
commit_list_file=$(mktemp)
git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --reverse --date=short --decorate --no-merges -E --grep="(${1})" "${trimmed_branch}" > $commit_list_file
$EDITOR $commit_list_file
cat $commit_list_file | awk '{print $1}' | xargs git cherry-pick
}
ga() {
git ls-files --modified --others --exclude-standard | fzf-tmux -m | xargs git add
}
gcm() {
if [ -z "$(which git)" ]; then
echo "git has not been installed"
return
fi
if [ -z "$(which mods)" ]; then
echo "mods has not been installed"
return
fi
# write git diff to a temp file
local diff_file
diff_file=$(mktemp)
git diff --cached --diff-algorithm=minimal > $diff_file
# prompt LLM using mods against the diff file
mods -f "Generate a concise git commit message written in past tense for the following code diff. Your entire response will be passed directly into git commit." < $diff_file
}