/
gh-fzf
executable file
·652 lines (577 loc) · 28.4 KB
/
gh-fzf
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
#!/usr/bin/env bash
# shellcheck disable=2016
set -e
# An fzf wrapper around the GitHub CLI - https://github.com/benelan/gh-fzf
#
# MIT License
#
# Copyright (c) Ben Elan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
GH_FZF_VERSION="v0.10.0" # x-release-please-version
# Usage info and logs {{{
# --------------------------------------------------------------------- {|}
has() { command -v "$1" >/dev/null 2>&1; }
error() {
if [ -n "$1" ]; then
printf "Error: %s\n" "$*"
fi
printf "\n%s\n" \
"Try -h for usage information" >&2
exit 1
}
help_cmd() {
printf "
An fzf wrapper around the GitHub CLI.
Homepage: https://github.com/benelan/gh-fzf
Usage:
gh fzf <command> [flags]
Core Commands:
issue Search for and interact with GitHub issues.
pr Search for and interact with GitHub pull requests.
run Search for and interact with GitHub Action runs.
workflow Search for and interact with GitHub Action workflows.
release Search for and interact with GitHub releases.
label Search for and interact with GitHub labels.
repo Search for and interact with GitHub repos.
gist Search for and interact with GitHub gists.
See \`gh <command> list --help\` for the flag options.
Other Commands:
help Print this help message.
version Print the version of gh-fzf.
changelog View gh-fzf's changelog via the release command.
Check out the project homepage for more information, such as keybindings,
configuration, and examples.
" >&2
exit 0
}
global_binds="Globals > (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload) (alt-1: 100 items) (alt-2: 200 items) (...) (alt-9: 900 items)"
# --------------------------------------------------------------------- }}}
# Configuration {{{
# --------------------------------------------------------------------- {|}
GH_FZF_DEFAULT_LIMIT="${GH_FZF_DEFAULT_LIMIT:-69}"
if [ -z "$GH_FZF_COPY_CMD" ]; then
if has /mnt/c/Windows/System32/clip.exe; then
GH_FZF_COPY_CMD="/mnt/c/Windows/System32/clip.exe" # Windows (WSL)
elif has xsel; then
GH_FZF_COPY_CMD="xsel -bi" # Linux (X11)
elif has xclip; then
GH_FZF_COPY_CMD="xclip -selection clipboard" # Linux (X11)
elif has wl-copy; then
GH_FZF_COPY_CMD="wl-copy" # Linux (Wayland)
elif has pbcopy; then
GH_FZF_COPY_CMD="pbcopy" # OSX
fi
fi
if [ -n "$GH_FZF_HIDE_HINTS" ]; then
on_start="toggle-header"
fi
if [ -n "$GH_FZF_TRUNCATE_FIELDS" ]; then
gh_columns='100%'
else
gh_columns='9999999'
fi
# The following fzf options are shared by all commands. They are prepended to
# the FZF_DEFAULT_OPTS environment variable so they can be overridden by users.
export FZF_DEFAULT_OPTS='
--no-hscroll --no-exit-0 --header-lines=1 --cycle --reverse --delimiter=" "
--preview-window="right,50%,wrap,~2,<60(down,40%,wrap)"
--preview-label="(alt+P: toggle preview) (alt+H: toggle hints)"
--bind="alt-P:toggle-preview" --bind="alt-H:toggle-header"
--color "fg:#ebdbb2,fg+:#ebdbb2,bg:#282828,bg+:#3c3836,hl:#d3869b:bold,hl+:#d3869b,info:#83a598,prompt:#bdae93,spinner:#fabd2f,pointer:#83a598,marker:#fe8019,header:#928374,label:#83a598"
--bind="ctrl-r:reload(eval \"$FZF_DEFAULT_COMMAND\")"
--bind="alt-1:reload(eval \"$FZF_DEFAULT_COMMAND -L100\")"
--bind="alt-2:reload(eval \"$FZF_DEFAULT_COMMAND -L200\")"
--bind="alt-3:reload(eval \"$FZF_DEFAULT_COMMAND -L300\")"
--bind="alt-4:reload(eval \"$FZF_DEFAULT_COMMAND -L400\")"
--bind="alt-5:reload(eval \"$FZF_DEFAULT_COMMAND -L500\")"
--bind="alt-6:reload(eval \"$FZF_DEFAULT_COMMAND -L600\")"
--bind="alt-6:reload(eval \"$FZF_DEFAULT_COMMAND -L600\")"
--bind="alt-7:reload(eval \"$FZF_DEFAULT_COMMAND -L700\")"
--bind="alt-8:reload(eval \"$FZF_DEFAULT_COMMAND -L800\")"
--bind="alt-9:reload(eval \"$FZF_DEFAULT_COMMAND -L900\")"
'"$FZF_DEFAULT_OPTS"' --no-select-1 --ansi --no-multi'
# Overriding the three options above breaks gh-fzf, so append them instead.
# --------------------------------------------------------------------- }}}
# Command > default {{{
# --------------------------------------------------------------------- {|}
default_cmd() {
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' \
issue pr run workflow release label repo gist" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh help {}' \
--preview-window='right:75%,wrap' \
--bind="enter:execute(gh fzf {})"
}
# --------------------------------------------------------------------- }}}
# Command > issue {{{
# --------------------------------------------------------------------- {|}
issue_cmd() {
issue_template='\
--json "number,title,author,assignees,state,milestone,labels,updatedAt" \
--template '\''
{{- $headerColor := "blue+b" -}}
{{- tablerow
("ISSUE" | autocolor $headerColor)
("LAST UPDATE" | autocolor $headerColor)
("TITLE" | autocolor $headerColor)
("AUTHOR" | autocolor $headerColor)
("MILESTONE" | autocolor $headerColor)
("LABELS" | autocolor $headerColor)
-}}
{{- range . -}}
{{- $milestoneTitle := "" -}}
{{- if ne .milestone nil -}}
{{- $milestoneTitle = .milestone.title -}}
{{- end -}}
{{- $stateColor := "green" -}}
{{- if eq .state "CLOSED" -}}
{{- $stateColor = "red" -}}
{{- end -}}
{{- tablerow
(printf "#%v" .number | autocolor $stateColor)
((timeago .updatedAt) | autocolor "white+d")
(truncate 100 (.title | autocolor "white+h"))
(.author.login | autocolor "white+d")
($milestoneTitle | autocolor "white+h")
(pluck "name" .labels | join ", " | autocolor "white+d")
-}}
{{- end -}}
'\'''
issue_header="Actions > (enter: edit) (alt-c: comment) (alt-o: checkout) (alt-l: add label) (alt-L: remove label) (alt-X: close) (alt-O: reopen)
Filters > (alt-a: assignee) (alt-A: author) (alt-m: mention) (alt-s: state=all)
$global_binds
"
# increase the limit when showing labels
[ "$GH_FZF_DEFAULT_LIMIT" -lt 420 ] && label_limit="-L 420"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh issue list $issue_template -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh issue view {1} --comments '"$repo_flag" \
--header="$issue_header" \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh issue view --web {1} $repo_flag &)+refresh-preview" \
--bind="ctrl-y:execute-silent(
gh issue view {1} --json 'url' -q '.url' $repo_flag | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind="enter:execute(gh issue edit {1} $repo_flag)+refresh-preview" \
--bind='alt-o:execute(
branch="$(gh issue develop --list {1} | tail | cut -f1)"
if git show-ref --quiet "refs/heads/$branch"; then
git checkout "$branch"
else
num="${GH_FZF_BRANCH_ADD_ISSUE_NUMBER:+{1}$GH_FZF_BRANCH_ADD_ISSUE_NUMBER}"
num=$(tr -d "#'\''" <<< ${num// /})
printf "Enter branch name for {1}: ${GH_FZF_BRANCH_PREFIX}${num}";
read -r name;
branch="${GH_FZF_BRANCH_PREFIX}${num}${name// /-}"
gh issue develop {1} --checkout ${branch:+--name "$branch"} '"$repo_flag"'
fi
)+abort' \
--bind="alt-c:execute(gh issue comment {1} $repo_flag)+refresh-preview" \
--bind='alt-l:execute(
gh issue edit --add-label "$(gh fzf label '"$label_limit"')" {1} '"$repo_flag"'
)+refresh-preview' \
--bind='alt-L:execute(
gh issue edit --remove-label "$(gh fzf label '"$label_limit"')" {1} '"$repo_flag"'
)+refresh-preview' \
--bind="alt-O:execute(gh issue reopen {1} $repo_flag)+refresh-preview" \
--bind="alt-X:execute(gh issue close {1} $repo_flag)+refresh-preview" \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --assignee @me")' \
--bind='alt-A:reload(eval "$FZF_DEFAULT_COMMAND --author @me")' \
--bind='alt-m:reload(eval "$FZF_DEFAULT_COMMAND --mention @me")' \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --state all")'
}
# --------------------------------------------------------------------- }}}
# Command > pr {{{
# --------------------------------------------------------------------- {|}
pr_cmd() {
pr_template='\
--json "number,title,state,headRefName,milestone,updatedAt,labels" \
--template '\''
{{- $headerColor := "blue+b" -}}
{{- tablerow
("PR" | autocolor $headerColor)
("LAST UPDATE" | autocolor $headerColor)
("TITLE" | autocolor $headerColor)
("BRANCH" | autocolor $headerColor)
("LABELS" | autocolor $headerColor)
("MILESTONE" | autocolor $headerColor)
-}}
{{- range . -}}
{{- $milestoneTitle := "" -}}
{{- if ne .milestone nil -}}
{{- $milestoneTitle = .milestone.title -}}
{{- end -}}
{{- $stateColor := "green" -}}
{{- if eq .state "CLOSED" -}}
{{- $stateColor = "red" -}}
{{- else if eq .state "MERGED" -}}
{{- $stateColor = "magenta" -}}
{{- end -}}
{{- tablerow
(printf "#%v" .number | autocolor $stateColor)
((timeago .updatedAt) | autocolor "white+d")
(truncate 100 (.title | autocolor "white+h"))
(truncate 60 (.headRefName | autocolor "white+d"))
(pluck "name" .labels | join ", " | autocolor "white+h")
($milestoneTitle | autocolor "white+d")
-}}
{{- end -}}
'\'''
pr_header="Actions > (enter: edit) (alt-o: checkout) (alt-d: diff) (alt-c: comment) (alt-r: review) (alt-l: add label)
> (alt-C: checks) (alt-M: merge) (alt-R: ready) (alt-X: close) (alt-O: reopen) (alt-L: remove label)
Filters > (alt-a: assignee) (alt-A: author) (alt-b: branch) (alt-s: state=all)
$global_binds
"
# increase the limit when showing labels
[ "$GH_FZF_DEFAULT_LIMIT" -lt 420 ] && label_limit="-L 420"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh pr list $pr_template -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh pr view {1} --comments '"$repo_flag" \
--header="$pr_header" \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh pr view --web {1} $repo_flag &)+refresh-preview" \
--bind="ctrl-y:execute-silent(
gh pr view {1} --json 'url' -q '.url' $repo_flag | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind="enter:execute(gh pr edit {1} $repo_flag)+refresh-preview" \
--bind="alt-c:execute(gh pr comment {1} $repo_flag)+refresh-preview" \
--bind="alt-d:execute(gh pr diff {1} $repo_flag)+refresh-preview" \
--bind="alt-o:execute(gh pr checkout {1} $repo_flag)+refresh-preview" \
--bind="alt-r:execute(gh pr review {1} $repo_flag)+refresh-preview" \
--bind='alt-l:execute(
gh issue edit --add-label "$(gh fzf label '"$label_limit"')" {1} '"$repo_flag"'
)+refresh-preview' \
--bind='alt-L:execute(
gh issue edit --remove-label "$(gh fzf label '"$label_limit"')" {1} '"$repo_flag"'
)+refresh-preview' \
--bind='alt-C:execute<gh fzf run -b $(
gh pr view {1} --json headRefName --jq .headRefName '"$repo_flag"'
) '"$repo_flag"'>+refresh-preview' \
--bind="alt-R:execute(gh pr ready {1} $repo_flag)+refresh-preview" \
--bind="alt-M:execute(gh pr merge {1} $repo_flag)+refresh-preview" \
--bind="alt-O:execute(gh pr reopen {1} $repo_flag)+refresh-preview" \
--bind="alt-X:execute(gh pr close {1} $repo_flag)+refresh-preview" \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --assignee @me")' \
--bind='alt-A:reload(eval "$FZF_DEFAULT_COMMAND --author @me")' \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --state all")' \
--bind='alt-b:reload(eval "$FZF_DEFAULT_COMMAND --head \
$(git symbolic-ref --short HEAD)")'
}
# --------------------------------------------------------------------- }}}
# Command > run {{{
# --------------------------------------------------------------------- {|}
run_cmd() {
run_template='\
--json "updatedAt,event,displayTitle,headBranch,databaseId,conclusion,status,name" \
--template '\''
{{- $headerColor := "blue+b" -}}
{{- tablerow
("STATUS" | autocolor $headerColor)
("LAST UPDATE" | autocolor $headerColor)
("WORKFLOW" | autocolor $headerColor)
("BRANCH" | autocolor $headerColor)
("TITLE" | autocolor $headerColor)
("EVENT" | autocolor $headerColor)
("ID" | autocolor $headerColor)
-}}
{{- range . -}}
{{- $statusColor := "yellow" -}}
{{- $statusText := .status -}}
{{- if ne (len .conclusion) 0 -}}
{{- $statusText = .conclusion -}}
{{- if eq .conclusion "failure" "startup_failure" -}}
{{- $statusColor = "red" -}}
{{- else if eq .conclusion "cancelled" "timed_out" -}}
{{- $statusColor = "red+d" -}}
{{- else if eq .conclusion "action_required" -}}
{{- $statusColor = "magenta+h" -}}
{{- else if eq .conclusion "stale" -}}
{{- $statusColor = "yellow+d" -}}
{{- else if eq .conclusion "success" -}}
{{- $statusColor = "green" -}}
{{- else if eq .conclusion "skipped" -}}
{{- $statusColor = "white+d" -}}
{{- end -}}
{{- end -}}
{{- tablerow
($statusText | autocolor $statusColor)
((timeago .updatedAt) | autocolor "white+d")
(.name | autocolor "white+h")
(truncate 60 (.headBranch | autocolor "white+d"))
(truncate 100 (.displayTitle | autocolor "white+h"))
(.event | autocolor "white+d")
(.databaseId | autocolor "white+h")
-}}
{{- end -}}
'\'''
run_header="Actions > (enter: watch) (alt-l: logs) (alt-r: rerun) (alt-x: cancel) (alt-p: pr) (alt-d: download)
Filters > (alt-f: failed runs) (alt-b: current branch) (alt-u: current user)
$global_binds
"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh run list $run_template -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh run view {-1} '"$repo_flag" \
--header="$run_header" \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh run view --web {-1} $repo_flag &)+refresh-preview" \
--bind="ctrl-y:execute-silent(
gh run view {-1} --json 'url' -q '.url' $repo_flag | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind="enter:execute(gh run watch {-1} $repo_flag)+refresh-preview" \
--bind="alt-l:execute(gh run view --log {-1} $repo_flag)+refresh-preview" \
--bind="alt-r:execute(gh run rerun {-1} $repo_flag)+refresh-preview" \
--bind="alt-d:execute(gh run download {-1} $repo_flag)+refresh-preview" \
--bind="alt-x:execute(gh run cancel {-1} $repo_flag)+refresh-preview" \
--bind='alt-p:execute<gh fzf pr --head $(
gh run view {-1} --json headBranch --jq .headBranch '"$repo_flag"'
) '"$repo_flag"'>+refresh-preview' \
--bind='alt-b:reload(
eval "$FZF_DEFAULT_COMMAND --branch $(git symbolic-ref --short HEAD)"
)' \
--bind='alt-f:reload(eval "$FZF_DEFAULT_COMMAND --status failure")' \
--bind='alt-u:reload(
eval "$FZF_DEFAULT_COMMAND --user $(gh api user -q .login)"
)'
}
# --------------------------------------------------------------------- }}}
# Command > workflow {{{
# --------------------------------------------------------------------- {|}
workflow_cmd() {
workflow_header="Actions > (enter: runs) (alt-d: dispatch) (alt-X: disable) (alt-E: enable)
Filters > (alt-a: all)
$global_binds
"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh workflow list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh workflow view --yaml {-1} '"$repo_flag" \
--header="$workflow_header" \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh workflow view --web {-1} $repo_flag &)+refresh-preview" \
--bind="enter:execute(gh fzf run --workflow {-1} $repo_flag)+refresh-preview" \
--bind="alt-d:execute(gh workflow run {-1} $repo_flag)+refresh-preview" \
--bind="alt-E:execute(gh workflow enable {-1} $repo_flag)+refresh-preview" \
--bind="alt-X:execute(gh workflow disable {-1} $repo_flag)+refresh-preview" \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --all")'
}
# --------------------------------------------------------------------- }}}
# Command > release {{{
# --------------------------------------------------------------------- {|}
release_cmd() {
release_template='\
--json "publishedAt,isDraft,isLatest,isPrerelease,name,tagName" \
--template '\''
{{- $headerColor := "blue+b" -}}
{{- tablerow
("TAG" | autocolor $headerColor)
("PUBLISHED" | autocolor $headerColor)
("TITLE" | autocolor $headerColor)
("TYPE" | autocolor $headerColor)
-}}
{{- range . -}}
{{- $type := "" -}}
{{- $typeColor := "white+d" -}}
{{- if eq .isLatest true -}}
{{- $type = "Latest" -}}
{{- $typeColor = "green" -}}
{{- else if eq .isPrerelease true -}}
{{- $type = "Pre-release" -}}
{{- $typeColor = "yellow" -}}
{{- else if eq .isDraft true -}}
{{- $type = "Draft" -}}
{{- end -}}
{{- tablerow
(.tagName | autocolor "white+h")
(printf "%s (%s)"
(timefmt "2006-01-02" .publishedAt)
(timeago .publishedAt)
| autocolor "white+d")
(.name | autocolor "white+h")
($type | autocolor $typeColor)
-}}
{{- end -}}
'\'''
release_header="Actions > (enter: download) (alt-X: delete)
Filters > (alt-s: stable) (alt-p: published) (alt-a: ascending)
$global_binds
"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh release list $release_template -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh release view {1} '"$repo_flag" \
--header="$release_header" \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh release view --web {1} $repo_flag &)+refresh-preview" \
--bind="ctrl-y:execute-silent(
gh release view {1} --json 'url' -q '.url' $repo_flag | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind="alt-enter:execute(gh release download {1} $repo_flag)+refresh-preview" \
--bind="alt-X:execute(gh release delete {1} $repo_flag)+refresh-preview" \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --exclude-pre-releases")' \
--bind='alt-p:reload(eval "$FZF_DEFAULT_COMMAND --exclude-drafts")' \
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --order asc")'
}
# --------------------------------------------------------------------- }}}
# Command > label {{{
# --------------------------------------------------------------------- {|}
label_cmd() {
label_header="Actions > (enter: print) (alt-n: edit name) (alt-d: edit description) (alt-c: edit color) (alt-X: delete)
Filters > (alt-N: sort by name) (alt-D: descending order)
$global_binds
"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh label list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--no-preview \
--header-lines=4 \
--header="$label_header" \
--bind="start:$on_start" \
--bind="enter:execute(printf {1})+abort" \
--bind="ctrl-o:execute-silent(gh label list --web $repo_flag &)" \
--bind='alt-n:execute(
printf "Enter new label name: ";
read -r name;
[ -n "$name" ] && gh label edit {1} --name "$name" '"$repo_flag"'
)' \
--bind='alt-d:execute(
printf "Enter new label description: ";
read -r description;
[ -n "$description" ] &&
gh label edit {1} --description "$description" '"$repo_flag"'
)' \
--bind='alt-c:execute(
printf "Enter new label color: ";
read -r color;
[ -n "$color" ] && gh label edit {1} --color "$color" '"$repo_flag"'
)' \
--bind="alt-X:execute(gh label delete {1} $repo_flag)" \
--bind='alt-N:reload(eval "$FZF_DEFAULT_COMMAND --sort name")' \
--bind='alt-D:reload(eval "$FZF_DEFAULT_COMMAND --order desc")' || true
}
# --------------------------------------------------------------------- }}}
# Command > repo {{{
# --------------------------------------------------------------------- {|}
repo_cmd() {
# repo_template='\
# --json "nameWithOwner,description,stargazerCount,forkCount,updatedAt,viewerPermission,visibility" \
# --template '\''
# {{- $headerColor := "blue+b" -}}
# {{- tablerow
# ("REPO" | autocolor $headerColor)
# ("VISIBILITY" | autocolor $headerColor)
# ("PERMISSIONS" | autocolor $headerColor)
# ("LAST UPDATE" | autocolor $headerColor)
# ("DESCRIPTION" | autocolor $headerColor)
# ("STARS" | autocolor $headerColor)
# ("FORKS" | autocolor $headerColor)
# -}}
# {{- range . -}}
# {{- tablerow
# (.nameWithOwner | autocolor "white+h")
# (.visibility | autocolor "white+d")
# (.viewerPermission | autocolor "white+h")
# ((timeago .updatedAt) | autocolor "white+d")
# (truncate 100 (.description | autocolor "white+h"))
# (.stargazerCount | autocolor "white+d")
# (.forkCount | autocolor "white+h")
# -}}
# {{- end -}}
# '\'''
repo_header="Actions > (enter: edit) (alt-p: prs) (alt-i: issues) (alt-r: runs) (alt-C: clone) (alt-F: fork)
Filters > (alt-c: private) (alt-o: public) (alt-s: source) (alt-f: forks)
$global_binds
"
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh repo list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh repo view {1}' \
--header="$repo_header" \
--header-lines=4 \
--bind="start:$on_start" \
--bind="ctrl-o:execute-silent(gh repo view --web {1} &)+refresh-preview" \
--bind="ctrl-y:execute-silent(
gh repo view {1} --json 'url' -q '.url' | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind="alt-p:execute(gh fzf pr --repo {1})+refresh-preview" \
--bind="alt-i:execute(gh fzf issue --repo {1})+refresh-preview" \
--bind="alt-r:execute(gh fzf run --repo {1})+refresh-preview" \
--bind="enter:execute(gh repo edit {1})+refresh-preview" \
--bind="alt-C:execute(gh repo clone {1})+refresh-preview" \
--bind="alt-F:execute(gh repo fork {1})+refresh-preview" \
--bind='alt-c:reload(eval "$FZF_DEFAULT_COMMAND --visibility private")' \
--bind='alt-o:reload(eval "$FZF_DEFAULT_COMMAND --visibility public")' \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --source")' \
--bind='alt-f:reload(eval "$FZF_DEFAULT_COMMAND --fork")'
}
# --------------------------------------------------------------------- }}}
# Command > gist {{{
# --------------------------------------------------------------------- {|}
gist_cmd() {
gist_header='Actions > (enter: edit) (alt-c: clone) (alt-X: delete)
> (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload)
Filters > (alt-p: public) (alt-s: secret)
'
FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh gist list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh gist view {1}' \
--header="$gist_header" \
--bind="start:$on_start" \
--bind='ctrl-o:execute-silent(gh gist view --web {1} &)+refresh-preview' \
--bind="ctrl-y:execute-silent(
echo https://gist.github.com/$(gh api user -q .login)/{1} | $GH_FZF_COPY_CMD
)+refresh-preview" \
--bind='enter:execute(gh gist edit {1})+refresh-preview' \
--bind='alt-c:execute(gh gist clone {1})+refresh-preview' \
--bind="alt-X:execute(gh gist delete {1})+refresh-preview" \
--bind='alt-p:reload(eval "$FZF_DEFAULT_COMMAND --public")' \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --secret")'
}
# --------------------------------------------------------------------- }}}
# Parse arguments {{{
# --------------------------------------------------------------------- {|}
find_repo_flag() {
for i in "$@"; do
case $i in
-R | --repo) repo_flag="--repo $2" && shift 2 ;;
-R=* | --repo=*) repo_flag="--repo=${i#*=}" && shift ;;
esac
done
}
main() {
command="$1"
if [ -z "$command" ]; then
default_cmd
else
shift
fi
find_repo_flag "$@"
case $command in
h | -h | help | --help) help_cmd "$@" ;;
i | -i | issue | issues | --issue | --issues) issue_cmd "$@" ;;
p | -p | pr | prs | --pr | --prs) pr_cmd "$@" ;;
r | -r | run | runs | --run | --runs) run_cmd "$@" ;;
repo | repos | --repo | --repos) repo_cmd "$@" ;;
release | releases | --release | --releases) release_cmd "$@" ;;
gist | gists | --gist | --gists) gist_cmd "$@" ;;
workflow | workflows | --workflow | --workflows) workflow_cmd "$@" ;;
label | labels | --label | --labels) label_cmd "$@" ;;
changelog) gh fzf release --repo benelan/gh-fzf ;;
v | V | -v | -V | version | --version) printf "%s\n" "$GH_FZF_VERSION" ;;
*) error "invalid command: \"$command\"" ;;
esac
}
# --------------------------------------------------------------------- }}}
main "$@"