-
Notifications
You must be signed in to change notification settings - Fork 2
/
gh-star
executable file
·68 lines (60 loc) · 1.74 KB
/
gh-star
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
#!/usr/bin/env bash
set -e
# fuzzy finder starred repos
_help() {
echo "Usage: gh star [options]
GitHub CLI extension to fuzzy search starred repo using fzf.
Options:
-w, --watch Open a repository in the browser
-h, --help Show this help message"
}
QUERY='
query FetchStarredRepo($endCursor: String) {
viewer {
login
starredRepositories(first: 100, after: $endCursor) {
totalCount
pageInfo {
hasNextPage
endCursor
}
edges {
node {
description
nameWithOwner
}
}
}
}
}
'
TEMPLATE='
{{- range $repo := .data.viewer.starredRepositories.edges -}}
{{ "name" | color "yellow" }}
{{- printf ": %s - " $repo.node.nameWithOwner -}}
{{ "description" | color "blue" }}
{{- printf ": %v\n" $repo.node.description -}}
{{- end -}}
'
case "$1" in
-h|--help)
_help
exit 0
;;
-w|--watch)
exec gh api graphql -f query="${QUERY}" --paginate --template="${TEMPLATE}" --cache 10m \
| fzf --ansi --header 'My favorite star this time is...' --header-lines=0 --height 80% --preview 'gh repo view {+2}' \
| cut -d " " -f 2 \
| xargs gh repo view -w \
;;
*)
exec gh api graphql -f query="${QUERY}" --paginate --template="${TEMPLATE}" --cache 10m \
| fzf --ansi --header 'My favorite star this time is...' --header-lines=0 --height 80% --preview 'gh repo view {+2}' \
| xargs \
| awk -v a="Detail in https://github.com/" -F " " '{print a b $2 "."}'
esac
# exit 1 if fzf not installed
if ! command -v fzf > /dev/null; then
echo "Error: Install \`fzf\` to use this command." >&2
exit 1
fi