-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghfused.source
136 lines (118 loc) 路 4.68 KB
/
ghfused.source
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
#!/usr/bin/env bash
# [ghspr] Fuzzy searches for pull requests and allows the user to open them in a web browser.
function ghspr {
local output=$(gh search prs \
--json="url,author,title,state,updatedAt" \
--template='{{range .}}{{tablerow .url .author.login .title .state (timeago .updatedAt)}}{{end}}' "$@")
if [[ -n "$output" ]]; then
local selected=$(echo $output | fzf -d ' ' \
--exit-0 \
--multi \
--ansi \
--expect="enter" \
--header=$'enter: Send to stdout, ctrl-b: Open in Browser, ctrl-d: Open Diff in Browser, ctrl-p: Toggle Preview' \
--inline-info \
--bind='ctrl-p:toggle-preview' \
--bind='ctrl-b:execute(echo {+1} | tr " " "\n" | xargs -I{x} sh -c "gh pr view --web {x}")+deselect-all' \
--bind='ctrl-d:execute(echo {+1} | tr " " "\n" | xargs -I{x} sh -c "gh pr diff --web {x}")+deselect-all' \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh pr view {1}' \
--preview-window 'right:50%:hidden:wrap' \
--prompt="Search: ")
local key="$(head -1 <<<"$selected")"
local args="$(sed 1d <<<"$selected" | awk '{print $1}')"
case "$key" in
enter)
echo $args
;;
esac
else
echo "nothing found!"
fi
}
# [ghpr] Search for open pull requests created by the current user.
alias ghpr="ghspr --sort=updated --limit=100 --author=@me --archived=false --state=open"
# [ghpra] Search for open pull requests assigned to the current user.
alias ghpra="ghspr --sort=updated --limit=100 --assignee=@me --archived=false --state=open"
# [ghprm] Search for open pull requests with mentions of the current user.
alias ghprm="ghspr --sort=updated --limit 100 --mentions=@me --archived=false --state=open"
# [ghrr] Search for open pull requests with review requests wanted from the current user.
alias ghrr="ghspr --sort=updated --limit 100 --review-requested=@me --archived=false --state=open"
# [ghsi] Fuzzy searches for issues and allows the user to open them in a browser
function ghsi {
local output=$(gh search issues \
--json="url,author,title,state,updatedAt" \
--template='{{range .}}{{tablerow .url .author.login .title .state (timeago .updatedAt)}}{{end}}' "$@")
if [[ -n "$output" ]]; then
local selected=$(echo $output | fzf -d ' ' \
--exit-0 \
--multi \
--ansi \
--expect="enter" \
--header=$'enter: Send to stdout, ctrl-b: Open in Browser, ctrl-p: Toggle Preview' \
--inline-info \
--bind='ctrl-p:toggle-preview' \
--bind='ctrl-b:execute(echo {+1} | tr " " "\n" | xargs -I{x} sh -c "gh issue view --web {x}")+deselect-all' \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh issue view {1}' \
--preview-window 'right:50%:hidden:wrap' \
--prompt="Search: ")
local key="$(head -1 <<<"$selected")"
local args="$(sed 1d <<<"$selected" | awk '{print $1}')"
case "$key" in
enter)
echo $args
;;
esac
else
echo "nothing found!"
fi
}
# [ghi] Search for open issues created by the current user.
alias ghi="ghsi --sort=updated --limit=100 --author=@me --archived=false --state=open"
# [ghia] Search for open issues assigned to the current user.
alias ghia="ghsi --sort=updated --limit=100 --assignee=@me --archived=false --state=open"
# [ghim] Search for open issues with mentions of the current user.
alias ghim="ghsi --sort=updated --limit 100 --mentions=@me --archived=false --state=open"
# [ghsr] Fuzzy searches for repositories and allows the user to open them in a browser
function ghsr {
local output=$(gh search repos \
--json="url,description,stargazersCount,forksCount,visibility,updatedAt" \
--template='{{range .}}{{tablerow .url .description .stargazersCount .forksCount .visibility (timeago .updatedAt)}}{{end}}' "$@")
if [[ -n "$output" ]]; then
local selected=$(echo $output | fzf -d ' ' \
--exit-0 \
--multi \
--ansi \
--expect="enter" \
--header=$'enter: Send to stdout, ctrl-b: Open in Browser, ctrl-p: Toggle Preview' \
--inline-info \
--bind='ctrl-p:toggle-preview' \
--bind='ctrl-a:select-all' \
--bind='ctrl-b:execute(echo {+1} | tr " " "\n" | xargs -I{x} sh -c "gh repo view --web {x}")+deselect-all' \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh repo view {1}' \
--preview-window 'right:50%:hidden:wrap' \
--prompt="Search: ")
local key="$(head -1 <<<"$selected")"
local args="$(sed 1d <<<"$selected" | awk '{print $1}')"
case "$key" in
enter)
echo $args
;;
esac
else
echo "nothing found!"
fi
}
# [ghhelp] show this help message
function ghhelp() {
echo "Usage of ghfused aliases"
echo
echo "Collection of powerful aliases to speed up interactions with GitHub"
echo "Find more information at https://github.com/cbrgm/gh-fused"
echo
echo "Usage:"
if [ -n "$ZSH_VERSION" ]; then
grep -E '^# \[.+\]' "${(%):-%x}"
else
grep -E '^# \[.+\]' "${BASH_SOURCE[0]}"
fi
}