Last active 1 month ago

vscode 开发必选扩展

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 48 insertions, 18 deletions

install

@@ -36,36 +36,66 @@ main() {
36 36 URL_DESC="${BASE_URL}${DESC_FILE}"
37 37
38 38 if $VERBOSE; then
39 - # -v 模式:只下载 README.md 并提取表格数据行,输出纯文本单行格式(无额外文字)
39 + # -v 模式:下载 README.md,先提取表格数据行(跳过标题和分隔行),然后逐行处理输出纯文本格式
40 40 curl -s --fail "$URL_DESC" | awk '
41 - /^\| \[\*\*[^\]]+\]\[\d+\] \| `[^\`]+` \| - \| / {
42 - # 提取名称
43 - if (match($0, /\[\*\*([^\*]+)\*\*\]\[\d+\]/)) {
44 - name = substr($0, RSTART+3, RLENGTH-7) # 去除 [** 和 **][n]
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
45 52 } else {
46 53 name = ""
47 54 }
48 55
49 - # 提取官方 ID
50 - if (match($0, /`([^\`]+)`/)) {
51 - id_official = substr($0, RSTART+1, RLENGTH-2)
56 + # 重置 line 为原始
57 + line = $0
58 +
59 + # 提取官方 ID:去除 `
60 + if (match(line, /`([^`]+)`/)) {
61 + id_official = substr(line, RSTART + 1, RLENGTH - 2)
52 62 } else {
53 63 id_official = ""
54 64 }
55 65
56 - # 其他 ID 固定为 -
57 - id_other = "-"
58 -
59 - # 提取描述:从第四个 | 之后的内容
60 - split($0, parts, "|")
61 - if (length(parts) >= 5) {
62 - desc = parts[5]
63 - gsub(/^[ \t]+|[ \t]+$/, "", desc)
66 + # 提取其他 ID:第三列,通常 -
67 + sub(/.*\| [^|]* \| [^|]* \| /, "", line) # 临时去除到第三列后
68 + if (match(line, /^ ([^ |]+) /)) {
69 + id_other = substr(line, RSTART + 1, RLENGTH - 2)
64 70 } else {
65 - desc = ""
71 + id_other = "-"
66 72 }
67 73
68 - printf "%s %s %s %s\n", name, id_official, id_other, desc
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 + }
69 99 }'
70 100 exit 0
71 101 fi

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 22 insertions, 12 deletions

install

@@ -38,22 +38,32 @@ main() {
38 38 if $VERBOSE; then
39 39 # -v 模式:只下载 README.md 并提取表格数据行,输出纯文本单行格式(无额外文字)
40 40 curl -s --fail "$URL_DESC" | awk '
41 - /^\| \[\*\*[^\*]+\*\*\]\[\d+\] \| `[^`]+` \| - \| / {
42 - # 提取名称(去除 [** **][n])
43 - match($0, /\[\*\*([^\*]+)\*\*\]\[\d+\]/, name_arr)
44 - name = name_arr[1]
45 -
46 - # 提取官方 ID(去除 `)
47 - match($0, /`([^`]+)`/, id_arr)
48 - id_official = id_arr[1]
41 + /^\| \[\*\*[^\]]+\]\[\d+\] \| `[^\`]+` \| - \| / {
42 + # 提取名称
43 + if (match($0, /\[\*\*([^\*]+)\*\*\]\[\d+\]/)) {
44 + name = substr($0, RSTART+3, RLENGTH-7) # 去除 [** 和 **][n]
45 + } else {
46 + name = ""
47 + }
48 +
49 + # 提取官方 ID
50 + if (match($0, /`([^\`]+)`/)) {
51 + id_official = substr($0, RSTART+1, RLENGTH-2)
52 + } else {
53 + id_official = ""
54 + }
49 55
50 56 # 其他 ID 固定为 -
51 57 id_other = "-"
52 58
53 - # 提取描述(最后一列)
54 - sub(/.*\| [^|]+ \| $/, "", $0) # 去除前四列
55 - gsub(/^[ \t]+|[ \t]+$/, "", $0)
56 - desc = $0
59 + # 提取描述:从第四个 | 之后的内容
60 + split($0, parts, "|")
61 + if (length(parts) >= 5) {
62 + desc = parts[5]
63 + gsub(/^[ \t]+|[ \t]+$/, "", desc)
64 + } else {
65 + desc = ""
66 + }
57 67
58 68 printf "%s %s %s %s\n", name, id_official, id_other, desc
59 69 }'

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 16 insertions, 17 deletions

install

@@ -36,26 +36,25 @@ main() {
36 36 URL_DESC="${BASE_URL}${DESC_FILE}"
37 37
38 38 if $VERBOSE; then
39 - # -v 模式:只下载 README.md 并提取表格行,输出为纯文本单行格式(无任何额外文字)
39 + # -v 模式:只下载 README.md 并提取表格数据行,输出纯文本单行格式(无额外文字)
40 40 curl -s --fail "$URL_DESC" | awk '
41 - /^\| \[\*\*[^*]+\*\*\]\[\d+\] \| `[^`]+` \|/ {
42 - # 去除名称中的 [**name**][n]
43 - gsub(/\[\*\*[^*]+\*\*\]\[\d+\]/, name_match ? name_match : "", $0)
44 - if (match($0, /\[\*\*([^*]+)\*\*\]\[\d+\]/, arr)) name = arr[1]
45 - else name = ""
46 -
47 - # 提取官方 ID(去除 ` )
48 - if (match($0, /`([^`]+)`/, arr)) id_official = arr[1]
49 - else id_official = ""
50 -
51 - # 提取其他 ID
52 - match($0, /\| ([^-]+) \|/, arr) ? id_other = arr[1] : id_other = "-"
53 -
54 - # 提取描述(剩余部分)
55 - sub(/.*\| [^|]* \| [^|]* \| [^|]* \| /, "", $0)
41 + /^\| \[\*\*[^\*]+\*\*\]\[\d+\] \| `[^`]+` \| - \| / {
42 + # 提取名称(去除 [** **][n])
43 + match($0, /\[\*\*([^\*]+)\*\*\]\[\d+\]/, name_arr)
44 + name = name_arr[1]
45 +
46 + # 提取官方 ID(去除 `)
47 + match($0, /`([^`]+)`/, id_arr)
48 + id_official = id_arr[1]
49 +
50 + # 其他 ID 固定为 -
51 + id_other = "-"
52 +
53 + # 提取描述(最后一列)
54 + sub(/.*\| [^|]+ \| $/, "", $0) # 去除前四列
56 55 gsub(/^[ \t]+|[ \t]+$/, "", $0)
57 56 desc = $0
58 -
57 +
59 58 printf "%s %s %s %s\n", name, id_official, id_other, desc
60 59 }'
61 60 exit 0

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 19 insertions, 13 deletions

install

@@ -6,7 +6,7 @@ DESC_FILE="README.md" # 描述 Markdown 文件
6 6 IDE_CMD="code" # 默认 VSCode
7 7 FORCE=false
8 8 EXTRA=""
9 - VERBOSE=false # -v: 只显示详细扩展信息,不安装
9 + VERBOSE=false # -v: 只显示详细扩展信息(纯文本单行格式),不安装
10 10
11 11 # 参数解析函数
12 12 parameters() {
@@ -38,19 +38,25 @@ main() {
38 38 if $VERBOSE; then
39 39 # -v 模式:只下载 README.md 并提取表格行,输出为纯文本单行格式(无任何额外文字)
40 40 curl -s --fail "$URL_DESC" | awk '
41 - /\| \[\*\*/ && /\]\[\d\]\] \|/`/ {
42 - gsub(/\[|\]|\*\*|\[\d\]/, "", $0) # 去除链接和粗体
43 - split($0, fields, "|")
44 - name = strip(fields[2])
45 - id_official = strip(fields[3])
46 - id_other = strip(fields[4])
47 - desc = strip(fields[5])
48 - gsub(/`/, "", id_official) # 去除代码标记
41 + /^\| \[\*\*[^*]+\*\*\]\[\d+\] \| `[^`]+` \|/ {
42 + # 去除名称中的 [**name**][n]
43 + gsub(/\[\*\*[^*]+\*\*\]\[\d+\]/, name_match ? name_match : "", $0)
44 + if (match($0, /\[\*\*([^*]+)\*\*\]\[\d+\]/, arr)) name = arr[1]
45 + else name = ""
46 +
47 + # 提取官方 ID(去除 ` )
48 + if (match($0, /`([^`]+)`/, arr)) id_official = arr[1]
49 + else id_official = ""
50 +
51 + # 提取其他 ID
52 + match($0, /\| ([^-]+) \|/, arr) ? id_other = arr[1] : id_other = "-"
53 +
54 + # 提取描述(剩余部分)
55 + sub(/.*\| [^|]* \| [^|]* \| [^|]* \| /, "", $0)
56 + gsub(/^[ \t]+|[ \t]+$/, "", $0)
57 + desc = $0
58 +
49 59 printf "%s %s %s %s\n", name, id_official, id_other, desc
50 - }
51 - function strip(s) {
52 - gsub(/^[ \t]+|[ \t]+$/, "", s)
53 - return s
54 60 }'
55 61 exit 0
56 62 fi

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 16 insertions, 2 deletions

install

@@ -36,8 +36,22 @@ main() {
36 36 URL_DESC="${BASE_URL}${DESC_FILE}"
37 37
38 38 if $VERBOSE; then
39 - # -v 模式:优先处理,只下载 README.md 并提取显示扩展推荐部分,不安装
40 - curl -s --fail "$URL_DESC" | sed -n '/## 扩展列表/,/Open VSX:/p'
39 + # -v 模式:只下载 README.md 并提取表格行,输出为纯文本单行格式(无任何额外文字)
40 + curl -s --fail "$URL_DESC" | awk '
41 + /\| \[\*\*/ && /\]\[\d\]\] \|/`/ {
42 + gsub(/\[|\]|\*\*|\[\d\]/, "", $0) # 去除链接和粗体
43 + split($0, fields, "|")
44 + name = strip(fields[2])
45 + id_official = strip(fields[3])
46 + id_other = strip(fields[4])
47 + desc = strip(fields[5])
48 + gsub(/`/, "", id_official) # 去除代码标记
49 + printf "%s %s %s %s\n", name, id_official, id_other, desc
50 + }
51 + function strip(s) {
52 + gsub(/^[ \t]+|[ \t]+$/, "", s)
53 + return s
54 + }'
41 55 exit 0
42 56 fi
43 57

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 16 insertions, 20 deletions

install

@@ -1,9 +1,9 @@
1 1 #!/usr/bin/env bash
2 2
3 3 BASE_URL="https://gist.asfd.cn/jetsung/vscode/raw/HEAD/"
4 - LIST_FILE="index.txt" # 默认列表文件
4 + LIST_FILE="index.txt" # 默认扩展 ID 列表文件
5 5 DESC_FILE="README.md" # 描述 Markdown 文件
6 - IDE_CMD="code" # 默认 VSCode
6 + IDE_CMD="code" # 默认 VSCode
7 7 FORCE=false
8 8 EXTRA=""
9 9 VERBOSE=false # -v: 只显示详细扩展信息,不安装
@@ -28,25 +28,24 @@ parameters() {
28 28 main() {
29 29 parameters "$@"
30 30
31 - if $VERBOSE; then
32 - URL_DESC="${BASE_URL}${DESC_FILE}"
33 - # -v 模式:只下载并显示 README.md 中的扩展推荐表格(不依赖 ID 列表,也不安装)
34 - echo "正在获取扩展详细信息..."
35 - curl -s --fail "$URL_DESC" | sed -n '/## 扩展列表/,/Open VSX:/p' | sed '$d' # 提取从 ## 扩展列表 到 Open VSX 前的内容
36 - echo "- **微软官方:** https://marketplace.visualstudio.com/"
37 - echo "- **Open VSX:** https://open-vsx.org/"
38 - exit 0 # 直接退出,不执行安装
39 - fi
40 -
41 - # 处理 LIST_FILE:如果不包含 . 则自动添加 .txt(除非是 *.*)
31 + # 处理 LIST_FILE
42 32 if [[ "$LIST_FILE" != "*.*" ]] && [[ "$LIST_FILE" != *.* ]]; then
43 33 LIST_FILE="${LIST_FILE}.txt"
44 34 fi
45 35
46 - URL="${BASE_URL}${LIST_FILE}"
36 + URL_DESC="${BASE_URL}${DESC_FILE}"
37 +
38 + if $VERBOSE; then
39 + # -v 模式:优先处理,只下载 README.md 并提取显示扩展推荐部分,不安装
40 + curl -s --fail "$URL_DESC" | sed -n '/## 扩展列表/,/Open VSX:/p'
41 + exit 0
42 + fi
43 +
44 + # 非 -v 模式:正常下载 index.txt 并安装
45 + URL_LIST="${BASE_URL}${LIST_FILE}"
47 46
48 - echo "从 $URL 下载扩展列表..."
49 - EXTENSIONS=$(curl -s --fail "$URL" | grep -v '^#' | grep -v '^$' | sed '/^$/d')
47 + echo "从 $URL_LIST 下载扩展列表..."
48 + EXTENSIONS=$(curl -s --fail "$URL_LIST" | grep -v '^#' | grep -v '^$' | sed '/^$/d')
50 49
51 50 if [ -z "$EXTENSIONS" ]; then
52 51 echo "错误: 未获取到扩展列表或文件为空!请检查文件名(当前: $LIST_FILE)。" >&2
@@ -54,18 +53,15 @@ main() {
54 53 fi
55 54
56 55 BASE_CMD="$IDE_CMD --install-extension"
57 -
58 - # 添加 --force
59 56 if $FORCE; then
60 57 EXTRA="--force $EXTRA"
61 58 fi
62 59
63 60 echo "开始为 $IDE_CMD 安装扩展(命令: $BASE_CMD ... $EXTRA)"
64 61 echo "扩展列表:"
65 - echo "$EXTENSIONS" | tr ' ' '\n' # 美化显示,每行一个
62 + echo "$EXTENSIONS" | tr ' ' '\n'
66 63 echo "-----------------"
67 64
68 - # 遍历安装(处理行内空格分隔或多行)
69 65 echo "$EXTENSIONS" | tr ' ' '\n' | while read -r ext; do
70 66 [ -z "$ext" ] && continue
71 67 echo "安装: $ext"

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 14 insertions, 3 deletions

install

@@ -2,24 +2,25 @@
2 2
3 3 BASE_URL="https://gist.asfd.cn/jetsung/vscode/raw/HEAD/"
4 4 LIST_FILE="index.txt" # 默认列表文件
5 + DESC_FILE="README.md" # 描述 Markdown 文件
5 6 IDE_CMD="code" # 默认 VSCode
6 7 FORCE=false
7 8 EXTRA=""
9 + VERBOSE=false # -v: 只显示详细扩展信息,不安装
8 10
9 11 # 参数解析函数
10 12 parameters() {
11 - while getopts "s:f e:n:" opt; do
13 + while getopts "s:f e:n:v" opt; do
12 14 case $opt in
13 15 s) IDE_CMD="$OPTARG" ;;
14 16 f) FORCE=true ;;
15 17 e) EXTRA="$OPTARG" ;;
16 18 n) LIST_FILE="$OPTARG" ;;
19 + v) VERBOSE=true ;;
17 20 \?) echo "无效参数: -$OPTARG" >&2; exit 1 ;;
18 21 esac
19 22 done
20 23 shift $((OPTIND-1))
21 -
22 - # 剩余所有参数追加到 EXTRA
23 24 EXTRA="$EXTRA $@"
24 25 }
25 26
@@ -27,6 +28,16 @@ parameters() {
27 28 main() {
28 29 parameters "$@"
29 30
31 + if $VERBOSE; then
32 + URL_DESC="${BASE_URL}${DESC_FILE}"
33 + # -v 模式:只下载并显示 README.md 中的扩展推荐表格(不依赖 ID 列表,也不安装)
34 + echo "正在获取扩展详细信息..."
35 + curl -s --fail "$URL_DESC" | sed -n '/## 扩展列表/,/Open VSX:/p' | sed '$d' # 提取从 ## 扩展列表 到 Open VSX 前的内容
36 + echo "- **微软官方:** https://marketplace.visualstudio.com/"
37 + echo "- **Open VSX:** https://open-vsx.org/"
38 + exit 0 # 直接退出,不执行安装
39 + fi
40 +
30 41 # 处理 LIST_FILE:如果不包含 . 则自动添加 .txt(除非是 *.*)
31 42 if [[ "$LIST_FILE" != "*.*" ]] && [[ "$LIST_FILE" != *.* ]]; then
32 43 LIST_FILE="${LIST_FILE}.txt"

jetsung revised this gist 5 months ago. Go to revision

2 files changed, 3 insertions, 3 deletions

README.md

@@ -11,5 +11,5 @@
11 11 [7]:https://github.com/ultram4rine/vscode-choosealicense
12 12 [8]:https://github.com/CodeZombieCH/vscode-gitignore
13 13
14 - - **微软官方:**https://marketplace.visualstudio.com/
15 - - **Open VSX:**https://open-vsx.org/
14 + - **微软官方:** https://marketplace.visualstudio.com/
15 + - **Open VSX:** https://open-vsx.org/

python.txt

@@ -1,7 +1,7 @@
1 1 ms-python.isort
2 2 ms-python.autopep8
3 3 ms-python.python
4 - pylance
4 + ms-python.vscode-pylance
5 5 ms-python.vscode-python-envs
6 6 ms-python.debugpy
7 7 charliermarsh.ruff

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 1 deletion

python.txt

@@ -1,7 +1,6 @@
1 1 ms-python.isort
2 2 ms-python.autopep8
3 3 ms-python.python
4 - ms-python.vscode
5 4 pylance
6 5 ms-python.vscode-python-envs
7 6 ms-python.debugpy

jetsung revised this gist 5 months ago. Go to revision

1 file changed, 2 insertions, 1 deletion

python.txt

@@ -2,6 +2,7 @@ ms-python.isort
2 2 ms-python.autopep8
3 3 ms-python.python
4 4 ms-python.vscode
5 - pylancems-python.vscode-python-envs
5 + pylance
6 + ms-python.vscode-python-envs
6 7 ms-python.debugpy
7 8 charliermarsh.ruff