-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathworkflows.sh
More file actions
106 lines (94 loc) · 2.56 KB
/
workflows.sh
File metadata and controls
106 lines (94 loc) · 2.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
#!/bin/zsh
# delete a branch locally and remotely
function gitbrdel() {
local branches remote main_or_master
while [[ "$#" -gt 0 ]]; do
case $1 in
-r|--remote) remote=1 ;;
*) echo "Unknown parameter passed: $1"; return 1 ;;
esac
shift
done
if git show-ref --verify --quiet refs/heads/master; then
main_or_master=master
elif git show-ref --verify --quiet refs/heads/main; then
main_or_master=main
else
echo "Neither master nor main branches found."
return 1
fi
branches=$(git branch --sort=committerdate |
grep --invert-match '\*' |
cut -c 3- |
fzf --tac --multi --preview="git ls --first-parent $main_or_master..{}");
while IFS= read -r line; do
if [[ $remote ]]; then
echo "deleting remotely..."
git push origin -d $line;
fi
#echo "deleting >>>$line<<<"
git branch -D $line;
done <<< $branches;
echo "done"
}
# checkout a branch
function gitco() {
local main_or_master
local flag_r=""
local flag_a=""
while [[ "$#" -gt 0 ]]; do
case $1 in -r|--remote) flag_r="-r" ;;
-a|--all) flag_a="-a" ;;
*) echo "Unknown parameter passed: $1"; return 1 ;;
esac
shift
done
if git show-ref --verify --quiet refs/heads/master; then
main_or_master=master
elif git show-ref --verify --quiet refs/heads/main; then
main_or_master=main
else
echo "Neither master nor main branches found."
return 1
fi
# Use the captured flags
git branch --sort=committerdate $flag_r $flag_a |
grep --invert-match '\*' |
grep --invert-match '\->' |
cut -c 3- |
fzf --tac --preview="git ls --first-parent origin/$main_or_master..{}" |
sed -r "s/(remotes\/)?origin\///" |
xargs -r git co
}
function gitpr() {
local jq_template pr_number
jq_template='"'\
'#\(.number) - \(.title)'\
'\t'\
'Author: \(.user.login)\n'\
'Created: \(.created_at)\n'\
'Updated: \(.updated_at)\n\n'\
'\(.body)'\
'"'
pr_number=$(
gh api 'repos/:owner/:repo/pulls' |
jq ".[] | $jq_template" |
sed -e 's/"\(.*\)"/\1/' -e 's/\\t/\t/' |
fzf \
--with-nth=1 \
--delimiter='\t' \
--preview='echo -e {2}' \
--preview-window=top:wrap |
sed 's/^#\([0-9]\+\).*/\1/'
)
if [ -n "$pr_number" ]; then
gh pr checkout "$pr_number"
fi
}
# checkout a previous commit in the current branch
function gitgoto() {
git log --pretty='%C(yellow)%h %C(cyan)%cd %Cblue%aN%C(auto)%d %Creset%s' --abbrev-commit --reverse --date='relative' |
fzf --tac --no-sort --preview="git show {1} --stat" |
cut -d' ' -f1 |
xargs -r git checkout
}