This repository was archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgf.nu
More file actions
186 lines (157 loc) · 3.85 KB
/
gf.nu
File metadata and controls
186 lines (157 loc) · 3.85 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
#*
#* _ __ _ _
#* __ _ ___ __ _| |_ / _(_) |___ ___ WEBSITE: https://goatfiles.github.io
#* / _` / _ \/ _` | _| _| | / -_|_-< REPOS: https://github.com/goatfiles
#* \__, \___/\__,_|\__|_| |_|_\___/__/ LICENCE: https://github.com/goatfiles/dotfiles/blob/main/LICENSE
#* |___/
#* MAINTAINERS:
#* AMTOINE: https://github.com/amtoine antoine#1306 7C5EE50BA27B86B7F9D5A7BA37AAE9B486CFF1AB
#* ATXR: https://github.com/atxr atxr#6214 3B25AF716B608D41AB86C3D20E55E4B1DE5B2C8B
#*
use context.nu
alias FZF = fzf --ansi --color --reverse
def FZF_LOG_PREVIEW [] {"
hash=$(echo {} | \\
sd -s '|' '' | \\
sd -s '\\' '' | \\
sd -s '/' '' | \\
sd '^\\s*\\*\\s*' '' | \\
awk '{print $1}'\\
)
[ -z $hash ] || git show --color=always $hash
"}
def FZF_STASH_PREVIEW [] { "git stash show --all --color=always $(echo {1} | sd ':' '')" }
def FZF_CHECKOUT_PREVIEW [] {"
branch=$(echo {} | \\
sd -s '*' '' | \\
sd '^\\s*' '' | \\
sd ' .*' '' \\
)
git log --graph --decorate --oneline --color=always $branch
"}
# TODO
def log_error [message: string] {
print $"gf: (ansi red_bold)error(ansi reset): ($message)"
}
# TODO
def log_debug [message: string] {
print $"gf: (ansi yellow_bold)debug(ansi reset): ($message)"
}
# TODO
def ungraph [
commitish: string = "HEAD"
] {
str replace -as "|" "" |
str replace -as '\' "" |
str replace -as "/" "" |
str replace "^\\s*\\*\\s*" "* "
}
# TODO
export def log [
commitish: string = "HEAD"
--all (-a): bool
--debug (-d): bool
] {
alias GIT_LOG = git log --graph --oneline --decorate --color=always
let choice = (
if ($all) {
GIT_LOG --branches --remotes=origin
} else {
GIT_LOG $commitish
} |
FZF --preview (FZF_LOG_PREVIEW) |
str trim
)
# do not try to show the commit if none has been selected!
if ($choice | is-empty) {
error make (context user_choose_to_exit)
}
let commit = ($choice | ungraph)
if not ($commit | is-empty) {
let hash = (
$commit |
parse "* {hash} {rest}" |
get hash
)
if ($debug) {
log_debug $"git show --color=always ($hash)"
} else {
git show --color=always $hash
}
} else {
log_error "not a commit"
}
}
# TODO
export def stash [
--debug (-d): bool
] {
let choice = (
git stash list --color=always |
FZF --preview (FZF_STASH_PREVIEW) |
str trim
)
# do not try to show the stash if none has been selected!
if ($choice | is-empty) {
error make (context user_choose_to_exit)
}
let stash_id = (
$choice |
parse "{stash}: {rest}" |
get stash
)
if ($debug) {
log_debug $"git stash show --all --color=always ($stash_id)"
} else {
git stash show --all --color=always $stash_id
}
}
# TODO
export def checkout [
--debug (-d): bool
] {
let choice = (
git branch --list --color=always | lines |
append (
git branch --remote --color=always | lines
) |
sort -r |
to text |
FZF --preview (FZF_CHECKOUT_PREVIEW) |
str trim
)
# do not try to show the checkout to a branch if none has been selected!
if ($choice | is-empty) {
error make (context user_choose_to_exit)
}
let branch = (
$choice |
str replace -as "*" "" |
str replace "^\\s*" "" |
str replace " .*" ""
)
if ($debug) {
log_debug $"git checkout ($branch)"
} else {
git checkout $branch
}
}
# TODO
export def branch [] {
log_error "branch unsupported"
}
# TODO
def "git branch wipe" [
branch: string
--remote (-r): string = "origin"
] {
let res = (do -i {
git rev-parse --verify $branch
} | complete)
if ($res.exit_code != 0) {
print $"wip: (ansi red_bold)error(ansi reset): '($branch)' does not exist..."
} else {
git branch --delete --force $branch
git push $remote $":($branch)"
}
}