Naposledy aktivní 1 month ago

vscode 开发必选扩展

Revize 4fe572713ac133fb9b626ce61bbeab351750d4d2

README.md Raw

VS Code 扩展推荐

扩展列表

名称 扩展 ID (官方) 扩展 ID() 描述
Even Better TOML tamasfe.even-better-toml - 功能齐全的 TOML 支持
Choose a License ultram4rine.vscode-choosealicense - 为你的项目选择一个许可证
gitignore codezombiech.gitignore - https://github.com/github/gitignore 仓库拉取 .gitignore 模板。支持.gitignore 文件的语言。
index.txt Raw
1tamasfe.even-better-toml
2ultram4rine.vscode-choosealicense
3codezombiech.gitignore
4
install Raw
1#!/usr/bin/env bash
2
3BASE_URL="https://gist.asfd.cn/jetsung/vscode/raw/HEAD/"
4LIST_FILE="index.txt" # 默认扩展 ID 列表文件
5DESC_FILE="README.md" # 描述 Markdown 文件
6IDE_CMD="code" # 默认 VSCode
7FORCE=false
8EXTRA=""
9VERBOSE=false # -v: 只显示详细扩展信息(纯文本单行格式),不安装
10
11# 参数解析函数
12parameters() {
13 while getopts "s:f e:n:v" opt; do
14 case $opt in
15 s) IDE_CMD="$OPTARG" ;;
16 f) FORCE=true ;;
17 e) EXTRA="$OPTARG" ;;
18 n) LIST_FILE="$OPTARG" ;;
19 v) VERBOSE=true ;;
20 \?) echo "无效参数: -$OPTARG" >&2; exit 1 ;;
21 esac
22 done
23 shift $((OPTIND-1))
24 EXTRA="$EXTRA $@"
25}
26
27# 主函数
28main() {
29 parameters "$@"
30
31 # 处理 LIST_FILE
32 if [[ "$LIST_FILE" != "*.*" ]] && [[ "$LIST_FILE" != *.* ]]; then
33 LIST_FILE="${LIST_FILE}.txt"
34 fi
35
36 URL_DESC="${BASE_URL}${DESC_FILE}"
37
38 if $VERBOSE; then
39 # -v 模式:下载 README.md,先提取表格数据行(跳过标题和分隔行),然后逐行处理输出纯文本格式
40 curl -s --fail "$URL_DESC" | awk '
41 # 只处理数据行:以 "| [**" 开头(名称带链接)
42 /^\| \[\*\*/ {
43 line = $0
44
45 # 提取名称:去除 [**name**][n]
46 if (match(line, /\[\*\*([^*]+)\*\*\]\[\d+\]/)) {
47 name = substr(line, RSTART + 3, RLENGTH - 7 - length(match(line, /\[\d+\]/))) # 调整去除 [n]
48 # 更精确:从 ** 后到 ** 前
49 sub(/.*\[\*\*/, "", line)
50 sub(/\*\*\].*/, "", line)
51 name = line
52 } else {
53 name = ""
54 }
55
56 # 重置 line 为原始
57 line = $0
58
59 # 提取官方 ID:去除 `
60 if (match(line, /`([^`]+)`/)) {
61 id_official = substr(line, RSTART + 1, RLENGTH - 2)
62 } else {
63 id_official = ""
64 }
65
66 # 提取其他 ID:第三列,通常 -
67 sub(/.*\| [^|]* \| [^|]* \| /, "", line) # 临时去除到第三列后
68 if (match(line, /^ ([^ |]+) /)) {
69 id_other = substr(line, RSTART + 1, RLENGTH - 2)
70 } else {
71 id_other = "-"
72 }
73
74 # 提取描述:第五列(最后一列)
75 if (match($0, /\| ([^|]+) \| ([^|]+) \| ([^|]+) \| (.*) \|$/)) {
76 desc = substr($0, RSTART + RLENGTH - length($4) - 1) # 复杂,改用 split
77 }
78
79 # 更可靠方式:用 split 分隔 |
80 split($0, fields, "|")
81 if (length(fields) >= 5) {
82 name_field = fields[2]
83 gsub(/^[ \t]+|[ \t]+$/, "", name_field)
84 gsub(/\[\*\*[^*]+\*\*\]\[\d+\]/, "", name_field) # 去除链接部分,留空? 等下已提取name
85 # 用之前提取的 name
86
87 id_official_field = fields[3]
88 gsub(/^[ \t]+|[ \t]+$/, "", id_official_field)
89 gsub(/`/, "", id_official_field)
90
91 id_other_field = fields[4]
92 gsub(/^[ \t]+|[ \t]+$/, "", id_other_field)
93
94 desc_field = fields[5]
95 gsub(/^[ \t]+|[ \t]+$/, "", desc_field)
96
97 printf "%s %s %s %s\n", name, id_official_field, id_other_field, desc_field
98 }
99 }'
100 exit 0
101 fi
102
103 # 非 -v 模式:正常下载 index.txt 并安装
104 URL_LIST="${BASE_URL}${LIST_FILE}"
105
106 echo "从 $URL_LIST 下载扩展列表..."
107 EXTENSIONS=$(curl -s --fail "$URL_LIST" | grep -v '^#' | grep -v '^$' | sed '/^$/d')
108
109 if [ -z "$EXTENSIONS" ]; then
110 echo "错误: 未获取到扩展列表或文件为空!请检查文件名(当前: $LIST_FILE)。" >&2
111 exit 1
112 fi
113
114 BASE_CMD="$IDE_CMD --install-extension"
115 if $FORCE; then
116 EXTRA="--force $EXTRA"
117 fi
118
119 echo "开始为 $IDE_CMD 安装扩展(命令: $BASE_CMD ... $EXTRA)"
120 echo "扩展列表:"
121 echo "$EXTENSIONS" | tr ' ' '\n'
122 echo "-----------------"
123
124 echo "$EXTENSIONS" | tr ' ' '\n' | while read -r ext; do
125 [ -z "$ext" ] && continue
126 echo "安装: $ext"
127 $BASE_CMD "$ext" $EXTRA || echo "警告: 安装 $ext 失败(可能已安装或 ID 不兼容)"
128 done
129
130 echo "-----------------"
131 echo "所有扩展安装完成!请重启 IDE 以生效。"
132}
133
134main "$@"
python.txt Raw
1ms-python.isort
2ms-python.autopep8
3ms-python.python
4ms-python.vscode-pylance
5ms-python.vscode-python-envs
6ms-python.debugpy
7charliermarsh.ruff
8