Github Copilot CLI 初体验

早上收到邮件,说我已经 off the waitlist, 赶紧去体验一波

下面这个tql,那就不需要学那些git,Linux指令啥的了

  • GitHub Copilot CLI translates natural language into shell commands, with modes for different domains. After installation, you can use the following three command:

    • ??: Translate natural language to arbitrary shell commands
    • git?: Translate natural language to Git commands
    • gh?: Translate natural language to GitHub CLI commands
  • GitHub Copilot CLI will also try to break down and explain piece by piece what the suggested command will do.

以上这两个真的就挺震撼的…

  • 但是看邮件里给我的guide网页,感觉还是不太会用,于是去它的discord社区里找找使用方法

    • 在里面看到一个有趣的叫:sunbeam的东西 https://pomdtr.github.io/sunbeam/schema.html
    • 还了解到了:AWS copilot CLI https://aws.github.io/copilot-cli/
  • 安装、验证GitHub和设备绑定之后,输入 github-copilot-cli,会有下面的指引

    Usage: Copilot CLI [options] [command]
    
    A CLI experience for letting GitHub Copilot help you on the command line.
    
    Options:
      -V, --version                        output the version number
      -h, --help                           display help for command
    
    Commands:
      auth                                 Retrieve and store a GitHub Access Token.
      alias <shell path>                   Add convenient GitHub Copilot CLI aliases to your shell.
      what-the-shell [options] <query...>  Use GitHub Copilot to get shell commands from natural language descriptions.
      git-assist [options] <query...>      Translate a natural language description of a git command to an actual git
                                           command.
      gh-assist [options] <query...>       Convert plain english to GitHub CLI commands.
      help [command]                       display help for command
    
  • 但是每次输入这么大一段很麻烦

    官方给出的解决办法是alias: eval "$(github-copilot-cli alias -- "$0")"

    可是windows上面没有eval,我想在Windows终端实现相同的指令怎么办

    问问AI捏

    • New Bing的回答

      那个invoke-Expression的东西尝试失败了…

      你好,这是必应。我很高兴能继续帮助你在Windows终端实现相同的指令。😊

      根据我的搜索结果,eval是一个Unix命令,它可以执行一个字符串作为命令。在Windows上,没有完全等价的命令,但有一些类似的方法可以尝试。

      • 一种方法是使用PowerShell的Invoke-Expression命令,它可以执行一个字符串作为PowerShell表达式¹。例如,你可以运行以下命令来执行github-copilot-cli alias的输出:
      Invoke-Expression (github-copilot-cli alias -- "$0")
      
      • 另一种方法是使用cmd.exe的for /f命令,它可以读取一个文件或者一个命令的输出,并对每一行进行处理⁴。例如,你可以运行以下命令来执行github-copilot-cli alias的输出:
      for /f "delims=" %i in ('github-copilot-cli alias -- "%0"') do %i
      

      注意:如果你在批处理文件中使用这个方法,你需要把%换成%%。

      我希望这能帮助你在Windows上实现类似eval的功能。👍

      Source: Conversation with Bing, 2023/3/14(1) Windows Powershell: eval a series of commands in active shell. https://superuser/questions/1493033/windows-powershell-eval-a-series-of-commands-in-active-shell Accessed 2023/3/14.
      (2) Eval Function - Microsoft Support. https://support.microsoft/en-us/office/eval-function-8c4a1b10-85ba-40db-b0c8-5290da4d4166 Accessed 2023/3/14.
      (3) Difference between window [] and eval () - Javascript. https://stackoverflow/questions/3294262/difference-between-window-and-eval-javascript Accessed 2023/3/14.
      (4) Windows Powershell: eval a series of commands in active shell. https://superuser/questions/1493033/windows-powershell-eval-a-series-of-commands-in-active-shell Accessed 2023/3/14.
      (5) shell - Equivalent to Unix eval in Windows - Stack Overflow. https://stackoverflow/questions/1195494/equivalent-to-unix-eval-in-windows Accessed 2023/3/14.

    • Chatgpt的回答

      eval is a shell built-in command that evaluates and executes a command as if it was a part of the current script or shell session. Since Windows Command Prompt (CMD) and PowerShell do not have a direct equivalent to eval, you can achieve a similar effect by creating a temporary batch file and executing it using the call command.

      Here is an example of how you can modify the eval "$(github-copilot-cli alias -- "$0")" command to work in Windows Command Prompt:

      echo github-copilot-cli alias -- %0 > temp.bat
      call temp.bat
      del temp.bat
      

      This command creates a temporary batch file called temp.bat, writes the github-copilot-cli alias -- %0 command to it (where %0 is a variable that expands to the name of the current batch file), executes the batch file using the call command, and finally deletes the temporary batch file.

      You can run this command in the Windows Command Prompt to achieve a similar effect as the original eval command. Note that this approach may not work in all scenarios and may require further modifications depending on your specific use case.

      也失败了…

  • 然后去discord 社区看看有无windows的解决方案

    看到有人反馈:

    I’ve been trying to find a workaround(替代方法) on windows for myself, every command I tried for it doesn’t seem to work, not even by using WSL. But you are able to manually make aliases which wouldn’t have the same functionality (you have to copy and paste the commands it gives you. But atleast you won’t have the write the whole thing.

    他们官方应该也正在解决(看了看discord cli分区的聊天记录)

  • 那就赶紧来试试哈哈哈(虽然指令比较长一点)

    看起来好像是可以自己设置alias?

  • 最近发现GitHub issue、discord社区反馈是很好的跟进最新技术的地方

更多推荐

Github Copilot CLI 初体验