From f6943b7f9a81ff6b4a939213a77a25e677ebcea6 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Sun, 26 Apr 2026 16:24:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20cnb=20=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=20vscode=20=E5=92=8C=20host=20=E9=85=8D=E7=BD=AE=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/open-cnb-remote-vscode.sh | 53 ++++++++++++++++++++++++++++++++++++ sh/set-cnb-host.sh | 45 ++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 sh/open-cnb-remote-vscode.sh create mode 100755 sh/set-cnb-host.sh diff --git a/sh/open-cnb-remote-vscode.sh b/sh/open-cnb-remote-vscode.sh new file mode 100755 index 0000000..e48ef42 --- /dev/null +++ b/sh/open-cnb-remote-vscode.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Required parameters: +# @raycast.schemaVersion 1 +# @raycast.title Open CNB Remote VSCode +# @raycast.mode silent + +# Optional parameters: +# @raycast.icon 🖥️ +# @raycast.packageName @kevisual/raycast + +# Documentation: +# @raycast.description SSH to CNB host, fuzzy select a project with fzf, then open it in VSCode Remote +# @raycast.author abearxiong +# @raycast.authorURL https://raycast.com/abearxiong + +CONFIG_FILE="$HOME/.config/my-raycast/cnb-host" +FZF_BIN="/usr/local/bin/fzf" + +if [[ ! -f "$CONFIG_FILE" ]]; then + osascript -e 'display alert "CNB Host 未配置" message "请先运行 Set CNB Host 脚本设置远程地址"' + exit 1 +fi + +CNB_HOST=$(cat "$CONFIG_FILE" | tr -d '[:space:]') + +if [[ -z "$CNB_HOST" ]]; then + osascript -e 'display alert "CNB Host 为空" message "请先运行 Set CNB Host 脚本设置远程地址"' + exit 1 +fi + +CMD="ssh '$CNB_HOST' 'find /workspace/projects /workspace/docker -maxdepth 1 -mindepth 1 -type d 2>/dev/null' | $FZF_BIN --prompt='CNB Remote > ' | xargs -I{} open 'vscode://vscode-remote/ssh-remote+${CNB_HOST}{}'" + +osascript < 后的内容,去掉路径部分 + HOST=$(echo "$INPUT" | sed 's|.*ssh-remote+||' | cut -d'/' -f1) +else + HOST="$INPUT" +fi + +HOST=$(echo "$HOST" | tr -d '[:space:]') + +if [[ -z "$HOST" ]]; then + echo "无法解析 host,请检查输入" + exit 1 +fi + +mkdir -p "$CONFIG_DIR" +echo "$HOST" > "$CONFIG_FILE" +echo "CNB host 已保存:$HOST"