diff --git a/README.md b/README.md index ccdee6e..b5f737b 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,13 @@ # github-copilot-cli.fish -> [!IMPORTANT] -> This plugin is obsolete as GitHub is sunsetting Copilot CLI: https://gist.github.com/idan/325676d192b32f169b032fde2d866c2c#github-next--technical-preview-sunsets - -Make GitHub Copilot CLI's alias work for Fish shell. The current Copilot CLI in beta only supports bash-like syntax. +Make GitHub Copilot CLI's alias work for Fish shell. The current Copilot CLI only supports bash, zsh and pwsh. ## How to install ### Via fisher -``` -fisher install z11i/github-copilot-cli.fish +```fish +fisher install xerxes-2/github-copilot-cli.fish ``` ### Manually @@ -19,24 +16,16 @@ Copy the file `conf.d/github-copilot-cli.fish` to `$__fish_config_dir/conf.d/` o ## How to use -Because Fish shell does [wildcards globbing](https://fishshell.com/docs/current/language.html#wildcards-globbing), the default aliases shipped with the CLI do not play well. Therefore I changed `?` to `!` for all aliases. +Identical to the [original Copilot CLI Aliases](https://github.com/github/gh-copilot#set-up-optional-helpers) for bash, zsh and pwsh. -- `!!`: Translate natural language to arbitrary shell commands -- `git!`: Translate natural language to Git commands -- `gh!`: Translate natural language to GitHub CLI commands +- `ghcs` - `gh copilot suggest` +- `ghce` - `gh copilot explain` ### Use your own aliases -If you don't want the default aliases, what you can do now is to put these in your config.fish: +To use your own aliases, for example, to use `,`: -``` -functions -e !! git! gh! -``` - -And use your own aliases, for example, to use `,`: - -``` -alias , __copilot_what-the-shell -alias ,g __copilot_git-assist -alias ,gh __copilot_gh-assist +```fish +alias ,s ghcs +alias ,e ghce ``` diff --git a/conf.d/github-copilot-cli.fish b/conf.d/github-copilot-cli.fish index 391ec5a..385d8a4 100644 --- a/conf.d/github-copilot-cli.fish +++ b/conf.d/github-copilot-cli.fish @@ -10,53 +10,117 @@ function __fish_add_history and history merge end -function __copilot_what-the-shell - set TMPFILE (mktemp) - trap 'rm -f $TMPFILE' EXIT - if github-copilot-cli what-the-shell $argv --shellout $TMPFILE - if test -e $TMPFILE - set FIXED_CMD (cat $TMPFILE) - __fish_add_history $FIXED_CMD - eval $FIXED_CMD - else - echo "Apologies! Extracting command failed" - end - else - return 1 +function ghcs + set -f funcname "$_" + set -f target shell + set -f GH_DEBUG "$GH_DEBUG" + set -f GH_HOST "$GH_HOST" + + set -f 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] + +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 -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"" + + argparse 'd/debug' 'h/help' 'hostname=' 't/target=' -- $argv + + if set -q _flag_debug + set -f GH_DEBUG api end -end -alias '!!'='__copilot_what-the-shell' - -function __copilot_git-assist - set TMPFILE (mktemp) - trap 'rm -f $TMPFILE' EXIT - if github-copilot-cli git-assist $argv --shellout $TMPFILE - if test -e $TMPFILE - set FIXED_CMD (cat $TMPFILE) - __fish_add_history $FIXED_CMD - eval $FIXED_CMD - else - echo "Apologies! Extracting command failed" + + if set -q _flag_help + echo "$usage" + return 0 + end + + if set -q _flag_hostname + set -f GH_HOST "$_flag_hostname" + end + + if set -q _flag_target + set -f target "$_flag_target" + end + + set -f tmp_file (mktemp -t gh-copilotXXXXXX) + trap 'rm -f "$tmp_file"' EXIT + + if GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$target" "$argv" --shell-out "$tmp_file" + if test -s "$tmp_file" + set -f fixed_cmd (cat "$tmp_file") + __fish_add_history "$fixed_cmd" + echo + eval "$fixed_cmd" end else return 1 end end -alias 'git!'='__copilot_git-assist' - -function __copilot_gh-assist - set TMPFILE (mktemp) - trap 'rm -f $TMPFILE' EXIT - if github-copilot-cli gh-assist $argv --shellout $TMPFILE - if test -e $TMPFILE - set FIXED_CMD (cat $TMPFILE) - __fish_add_history $FIXED_CMD - eval $FIXED_CMD - else - echo "Apologies! Extracting command failed" - end - else - return 1 + +function ghce + set -f funcname "$_" + set -f GH_DEBUG "$GH_DEBUG" + set -f GH_HOST "$GH_HOST" + + set -f usage "Wrapper around `gh copilot explain` to explain a given input command in natural language. + +USAGE + $funcname [flags] + +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'" + + argparse 'd/debug' 'h/help' 'hostname=' -- $argv + + if set -q _flag_debug + set -f GH_DEBUG api end + + if set -q _flag_help + echo "$usage" + return 0 + end + + if set -q _flag_hostname + set -f GH_HOST "$_flag_hostname" + end + + GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot explain "$argv" end -alias 'gh!'='__copilot_gh-assist' diff --git a/original/0.1.33/alias.bash b/original/0.1.33/alias.bash deleted file mode 100644 index ddaeedd..0000000 --- a/original/0.1.33/alias.bash +++ /dev/null @@ -1,52 +0,0 @@ - - copilot_what-the-shell () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli what-the-shell "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - history -s $(history 1 | cut -d' ' -f4-); history -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias '??'='copilot_what-the-shell'; - - copilot_git-assist () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli git-assist "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - history -s $(history 1 | cut -d' ' -f4-); history -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias 'git?'='copilot_git-assist'; - - copilot_gh-assist () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli gh-assist "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - history -s $(history 1 | cut -d' ' -f4-); history -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias 'gh?'='copilot_gh-assist'; -alias 'wts'='copilot_what-the-shell'; diff --git a/original/0.1.33/alias.zsh b/original/0.1.33/alias.zsh deleted file mode 100644 index f414f4a..0000000 --- a/original/0.1.33/alias.zsh +++ /dev/null @@ -1,52 +0,0 @@ - - copilot_what-the-shell () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli what-the-shell "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - print -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias '??'='copilot_what-the-shell'; - - copilot_git-assist () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli git-assist "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - print -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias 'git?'='copilot_git-assist'; - - copilot_gh-assist () { - TMPFILE=$(mktemp); - trap 'rm -f $TMPFILE' EXIT; - if /Users/z11i/.asdf/installs/nodejs/16.20.0/bin/github-copilot-cli gh-assist "$@" --shellout $TMPFILE; then - if [ -e "$TMPFILE" ]; then - FIXED_CMD=$(cat $TMPFILE); - print -s "$FIXED_CMD"; - eval "$FIXED_CMD" - else - echo "Apologies! Extracting command failed" - fi - else - return 1 - fi - }; -alias 'gh?'='copilot_gh-assist'; -alias 'wts'='copilot_what-the-shell'; diff --git a/original/1.0.3/alias.bash b/original/1.0.3/alias.bash new file mode 100644 index 0000000..59f360a --- /dev/null +++ b/original/1.0.3/alias.bash @@ -0,0 +1,142 @@ +ghcs() { + TARGET="shell" + local GH_DEBUG="$GH_DEBUG" + local GH_HOST="$GH_HOST" + + read -r -d '' __USAGE <<-EOF + 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] + + 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" + EOF + + local OPT OPTARG OPTIND + while getopts "dht:-:" OPT; do + if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG + OPT="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + fi + + case "$OPT" in + debug | d) + GH_DEBUG=api + ;; + + help | h) + echo "$__USAGE" + return 0 + ;; + + hostname) + GH_HOST="$OPTARG" + ;; + + target | t) + TARGET="$OPTARG" + ;; + esac + done + + # shift so that $@, $1, etc. refer to the non-option arguments + shift "$((OPTIND-1))" + + TMPFILE="$(mktemp -t gh-copilotXXXXXX)" + trap 'rm -f "$TMPFILE"' EXIT + if GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"; then + if [ -s "$TMPFILE" ]; then + FIXED_CMD="$(cat $TMPFILE)" + history -s $(history 1 | cut -d' ' -f4-); history -s "$FIXED_CMD" + echo + eval "$FIXED_CMD" + fi + else + return 1 + fi +} + +ghce() { + local GH_DEBUG="$GH_DEBUG" + local GH_HOST="$GH_HOST" + + read -r -d '' __USAGE <<-EOF + Wrapper around \`gh copilot explain\` to explain a given input command in natural language. + + USAGE + $FUNCNAME [flags] + + 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' + EOF + + local OPT OPTARG OPTIND + while getopts "dh-:" OPT; do + if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG + OPT="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + fi + + case "$OPT" in + debug | d) + GH_DEBUG=api + ;; + + help | h) + echo "$__USAGE" + return 0 + ;; + + hostname) + GH_HOST="$OPTARG" + ;; + esac + done + + # shift so that $@, $1, etc. refer to the non-option arguments + shift "$((OPTIND-1))" + + GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot explain "$@" +} \ No newline at end of file diff --git a/original/1.0.3/alias.zsh b/original/1.0.3/alias.zsh new file mode 100644 index 0000000..8ea0b8c --- /dev/null +++ b/original/1.0.3/alias.zsh @@ -0,0 +1,144 @@ +ghcs() { + FUNCNAME="$funcstack[1]" + TARGET="shell" + local GH_DEBUG="$GH_DEBUG" + local GH_HOST="$GH_HOST" + + read -r -d '' __USAGE <<-EOF + 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] + + 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" + EOF + + local OPT OPTARG OPTIND + while getopts "dht:-:" OPT; do + if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG + OPT="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + fi + + case "$OPT" in + debug | d) + GH_DEBUG=api + ;; + + help | h) + echo "$__USAGE" + return 0 + ;; + + hostname) + GH_HOST="$OPTARG" + ;; + + target | t) + TARGET="$OPTARG" + ;; + esac + done + + # shift so that $@, $1, etc. refer to the non-option arguments + shift "$((OPTIND-1))" + + TMPFILE="$(mktemp -t gh-copilotXXXXXX)" + trap 'rm -f "$TMPFILE"' EXIT + if GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"; then + if [ -s "$TMPFILE" ]; then + FIXED_CMD="$(cat $TMPFILE)" + print -s "$FIXED_CMD" + echo + eval "$FIXED_CMD" + fi + else + return 1 + fi +} + +ghce() { + FUNCNAME="$funcstack[1]" + local GH_DEBUG="$GH_DEBUG" + local GH_HOST="$GH_HOST" + + read -r -d '' __USAGE <<-EOF + Wrapper around \`gh copilot explain\` to explain a given input command in natural language. + + USAGE + $FUNCNAME [flags] + + 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' + EOF + + local OPT OPTARG OPTIND + while getopts "dh-:" OPT; do + if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG + OPT="${OPTARG%%=*}" # extract long option name + OPTARG="${OPTARG#"$OPT"}" # extract long option argument (may be empty) + OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` + fi + + case "$OPT" in + debug | d) + GH_DEBUG=api + ;; + + help | h) + echo "$__USAGE" + return 0 + ;; + + hostname) + GH_HOST="$OPTARG" + ;; + esac + done + + # shift so that $@, $1, etc. refer to the non-option arguments + shift "$((OPTIND-1))" + + GH_DEBUG="$GH_DEBUG" GH_HOST="$GH_HOST" gh copilot explain "$@" +} \ No newline at end of file