添加 cnb 远程 vscode 和 host 配置脚本

This commit is contained in:
2026-04-26 16:24:24 +08:00
parent 1468a9316a
commit f6943b7f9a
2 changed files with 98 additions and 0 deletions

45
sh/set-cnb-host.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Set CNB Host
# @raycast.mode compact
# Optional parameters:
# @raycast.icon ⚙️
# @raycast.packageName @kevisual/raycast
# @raycast.argument1 { "type": "text", "placeholder": "user@host or vscode://vscode-remote/ssh-remote+user@host/..." }
# Documentation:
# @raycast.description Set the CNB SSH remote host used by Open CNB Remote VSCode
# @raycast.author abearxiong
# @raycast.authorURL https://raycast.com/abearxiong
CONFIG_DIR="$HOME/.config/my-raycast"
CONFIG_FILE="$CONFIG_DIR/cnb-host"
if [[ -z "$1" ]]; then
echo "请提供 CNB host 或 VSCode Remote URL"
exit 1
fi
INPUT="$1"
# 如果是 vscode:// 协议地址,提取 ssh-remote+ 后面的 host 部分
if [[ "$INPUT" == vscode://* ]]; then
# 提取 ssh-remote+<host> 后的内容,去掉路径部分
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"