From e2304aff53e0df460b951549face1d24d0362149 Mon Sep 17 00:00:00 2001 From: Mactarvish Date: Thu, 7 Sep 2023 11:45:43 +0800 Subject: [PATCH] =?UTF-8?q?[feature]=20=E6=B7=BB=E5=8A=A0Ubuntu=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=94=AF=E6=8C=81=20(#23)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- vscode-remote.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 vscode-remote.sh diff --git a/README.md b/README.md index 1daa488..7c5e96e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 5. 重启你的IDE就好。此方式对`Vim/NeoVim`亦有效。 6. 这是个小玩具,可能测试不充分,别找我。 -#### 对于`VSCode`,步骤基本相同,执行对应`vscode.sh`/`vscode.bat`,**无需执行**`cocopilot.sh`/`cocopilot.bat`。 +#### 对于`VSCode`,步骤基本相同,执行对应`vscode.sh`/`vscode.bat`(如果是使用vscode远程连接Ubuntu服务器且副驾驶拓展安装在了远程服务器上,需要执行 `vscode-remote.sh`),**无需执行**`cocopilot.sh`/`cocopilot.bat`。 #### `VSCode`中插件更新后需要重新执行脚本,`JetBrains`则不需要。 diff --git a/vscode-remote.sh b/vscode-remote.sh new file mode 100755 index 0000000..c79c7f2 --- /dev/null +++ b/vscode-remote.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +EXTENSIONS_DIR="$HOME/.vscode-server/extensions" +if [ ! -d "$EXTENSIONS_DIR" ]; then + echo "ERROR: VSCode extensions directory not found!" + exit 1 +fi + +COPILOT_DIR=$(ls -lt "$EXTENSIONS_DIR" | grep '^d' | awk '{print $9}' | grep -E '^github\.copilot-[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) +if [ -z "$COPILOT_DIR" ]; then + echo "ERROR: Copilot extension not found!" + exit 1 +fi + +COPILOT_DIR="$EXTENSIONS_DIR/$COPILOT_DIR" +EXTENSION_FILE="$COPILOT_DIR/dist/extension.js" +if [ ! -f "$EXTENSION_FILE" ]; then + echo "ERROR: Copilot extension entry file not found!" + exit 1 +fi + +TMP_FILE="$COPILOT_DIR/dist/extension.js.tmp" +echo 'process.env.CODESPACES="true";process.env.GITHUB_TOKEN="ghu_ThisIsARealFreeCopilotKeyByCoCopilot";process.env.GITHUB_SERVER_URL="https://github.com";process.env.GITHUB_API_URL="https://api.cocopilot.org";' > "$TMP_FILE" +cat "$EXTENSION_FILE" >> "$TMP_FILE" +mv "$TMP_FILE" "$EXTENSION_FILE" + +echo 'done. please restart your vscode.'