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 |
works but output is bash-like, so most results won't run
@knoopx I prepended "On Fish Shell" to try and combat this but it's not perfect. Let me know if you have a different prompt that's more effective.
works but output is bash-like, so most results won't run
Could you please provide an example? I only used Copilot CLI for specific executable commands, so nothing shell specific.
works but output is bash-like, so most results won't run
Could you please provide an example? I only used Copilot CLI for specific executable commands, so nothing shell specific.
Anything that loops over files like "convert all PNG to JPG"
Anything that loops over files like "convert all PNG to JPG"
I get this
$ q convert all PNG to JPG
──────────────────── Command ────────────────────
for file in *.png; convert $file $file.jpg; end
────────────────── Explanation ──────────────────
○ The for loop iterates over a list of items and executes its body for each, using the loop variable $file.
◆ The list of items is *.png which means all files ending in .png in the current directory.
○ The loop body executes one command for each file:
◆ convert $file $file.jpg converts the current file from PNG to JPG.
Which seems correct?
@WinkelCode certainly works now, ¯\_(ツ)_/¯
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, works great!