Last active
May 9, 2023 20:02
-
-
Save asportnoy/a55a7a5df34af008f7ae2fdbbef22f04 to your computer and use it in GitHub Desktop.
GitHub Copilot CLI for Fish Shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires the GitHub Copilot CLI from GitHub Next | |
# https://www.npmjs.com/package/@githubnext/github-copilot-cli#installation-and-setup | |
# This needs to be set up as a function in your fish config. You can use `funced -s q` to do this. | |
# Options: | |
# q -g --git: Use github-copilot-cli git-assist | |
# q -h --gh: Use github-copilot-cli gh-assist | |
# Defaults to using what-the-shell (general command assist) if neither option is provided | |
# Completions for your Fish config: | |
complete -c q -s g -l git -d "Use git assist" | |
complete -c q -s h -l gh -d "Use GitHub CLI assist" | |
# Function code starts here: | |
function q | |
argparse -si --name q g/git h/gh -- $argv | |
set query "$argv" | |
if not test "$query" | |
# prompt user for input if no query is provided | |
read --prompt "set_color --bold 6b75ff; echo -n \" What do you want to do? \"; set_color normal; set_color brblack; echo -n \u203a \"\"; set_color normal;" query | |
end | |
if not test "$query" | |
# no query provided, exit | |
return 1 | |
end | |
set subcmd what-the-shell | |
if test "$_flag_g" | |
set subcmd git-assist | |
end | |
if test "$_flag_h" | |
set subcmd gh-assist | |
end | |
# generate a file for storing the output | |
set file (mktemp) | |
# run copilot | |
github-copilot-cli $subcmd --shellout $file "On Fish Shell: $query" | |
if test "$status" -ne 0 | |
# copilot failed, exit | |
return 1 | |
end | |
# read copilot output | |
set cmd (cat $file) | |
rm -rf $file | |
if not test "$cmd" | |
# no command from copilot, exit | |
return 1 | |
end | |
# execute command | |
commandline $cmd | |
commandline -f execute | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get this
Which seems correct?