-
Notifications
You must be signed in to change notification settings - Fork 0
/
gh-copilot-alias.fish
124 lines (108 loc) · 3.78 KB
/
gh-copilot-alias.fish
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
function ghcs
set -l FUNCNAME (status function)
set -l TARGET "shell"
set -l GH_DEBUG "$GH_DEBUG"
set -l GH_HOST "$GH_HOST"
set -l __USAGE "
Wrapper around \`gh copilot suggest\` to suggest a command based on a natural language description of the desired output effort.
Supports executing suggested commands if applicable.
USAGE
$FUNCNAME [flags] <prompt>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
--hostname The GitHub host to use for authentication
-t, --target target Target for suggestion; must be shell, gh, git
default: \"$TARGET\"
EXAMPLES
- Guided experience
$FUNCNAME
- Git use cases
$FUNCNAME -t git \"Undo the most recent local commits\"
$FUNCNAME -t git \"Clean up local branches\"
$FUNCNAME -t git \"Setup LFS for images\"
- Working with the GitHub CLI in the terminal
$FUNCNAME -t gh \"Create pull request\"
$FUNCNAME -t gh \"List pull requests waiting for my review\"
$FUNCNAME -t gh \"Summarize work I have done in issues and pull requests for promotion\"
- General use cases
$FUNCNAME \"Kill processes holding onto deleted files\"
$FUNCNAME \"Test whether there are SSL/TLS issues with github.com\"
$FUNCNAME \"Convert SVG to PNG and resize\"
$FUNCNAME \"Convert MOV to animated PNG\"
"
set -l argv_copy $argv
for i in (seq (count $argv_copy))
switch $argv_copy[$i]
case '-d' '--debug'
set -l GH_DEBUG "api"
case '-h' '--help'
echo "$__USAGE"
return 0
case '--hostname'
set -l GH_HOST $argv_copy[(math $i + 1)]
set -e argv_copy[(math $i + 1)]
case '-t' '--target'
set -l TARGET $argv_copy[(math $i + 1)]
set -e argv_copy[(math $i + 1)]
end
end
set -e argv_copy[1..(math $i - 1)]
set -l TMPFILE (mktemp -t gh-copilotXXXXXX)
function cleanup
rm -f "$TMPFILE"
end
trap cleanup EXIT
if env GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$TARGET" $argv_copy --shell-out "$TMPFILE"
if test -s "$TMPFILE"
set -l FIXED_CMD (cat $TMPFILE)
history --merge --save -- $FIXED_CMD
echo
eval $FIXED_CMD
end
else
return 1
end
end
function ghce
set -l FUNCNAME (status function)
set -l GH_DEBUG $GH_DEBUG
set -l GH_HOST $GH_HOST
set -l __USAGE "
Wrapper around \`gh copilot explain\` to explain a given input command in natural language.
USAGE
$FUNCNAME [flags] <command>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
--hostname The GitHub host to use for authentication
EXAMPLES
# View disk usage, sorted by size
$FUNCNAME 'du -sh | sort -h'
# View git repository history as text graphical representation
$FUNCNAME 'git log --oneline --graph --decorate --all'
# Remove binary objects larger than 50 megabytes from git history
$FUNCNAME 'bfg --strip-blobs-bigger-than 50M'
"
set -l argv_copy $argv
set -l optind 1
for arg in $argv_copy
switch $arg
case '-d' '--debug'
set -l GH_DEBUG api
set argv_copy (string match -v $arg $argv_copy)
set -l optind (math $optind + 1)
case '-h' '--help'
echo "$__USAGE"
return 0
case '--hostname=*'
set -l GH_HOST (string split -m 1 '=' $arg)[2]
set argv_copy (string match -v $arg $argv_copy)
set -l optind (math $optind + 1)
case '*'
break
end
end
set argv_copy (string sub -s (math $optind + 1) -- $argv)
env GH_DEBUG=$GH_DEBUG GH_HOST=$GH_HOST gh copilot explain $argv_copy
end