Gahing's blog Gahing's blog
首页
知识体系
  • 前端基础
  • 应用框架
  • 工程能力
  • 应用基础
  • 专业领域
  • 业务场景
  • 前端晋升 (opens new window)
  • Git
  • 网络基础
  • 算法
  • 数据结构
  • 编程范式
  • 编解码
  • Linux
  • AIGC
  • 其他领域

    • 客户端
    • 服务端
    • 产品设计
软素质
  • 面试经验
  • 人生总结
  • 个人简历
  • 知识卡片
  • 灵感记录
  • 实用技巧
  • 知识科普
  • 友情链接
  • 美食推荐 (opens new window)
  • 收藏夹

    • 优质前端信息源 (opens new window)
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Gahing / francecil

To be best
首页
知识体系
  • 前端基础
  • 应用框架
  • 工程能力
  • 应用基础
  • 专业领域
  • 业务场景
  • 前端晋升 (opens new window)
  • Git
  • 网络基础
  • 算法
  • 数据结构
  • 编程范式
  • 编解码
  • Linux
  • AIGC
  • 其他领域

    • 客户端
    • 服务端
    • 产品设计
软素质
  • 面试经验
  • 人生总结
  • 个人简历
  • 知识卡片
  • 灵感记录
  • 实用技巧
  • 知识科普
  • 友情链接
  • 美食推荐 (opens new window)
  • 收藏夹

    • 优质前端信息源 (opens new window)
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 前端基础

    • 编程语言

    • 开发工具

      • VSCode

        • VS code的Debugger For Chrome插件使用
        • vscode配置同步及拓展批量离线安装
          • 前言
          • 配置同步
          • 离线安装拓展
          • 批量下载离线安装包
            • 一、获取并解析 拓展列表 配置文件
            • 方案0: 直接拿 配置同步 时 gist.github 中保存的json
            • 方案1:解析目录并得到列表:
            • 方案2:使用code --list-extensions命令
            • 方案3:使用 vscode npm 包
            • 二、根据配置下载安装包
            • 在指定目录下利用 git bash 下载文件
          • 后续
        • vue-eslint-vscode 通用配置
    • 前端调试

    • 浏览器原理

    • 浏览器生态

  • 应用框架

  • 工程能力

  • 应用基础

  • 专业领域

  • 业务场景

  • 大前端
  • 前端基础
  • 开发工具
  • VSCode
gahing
2019/07/01
目录

vscode配置同步及拓展批量离线安装

# 前言

  1. 换电脑后,怎么保持 配置(settings.json,插件,键位设置等)同步?
  2. 离线安装拓展?
  3. 利用脚本自动进行前面两个步骤

# 配置同步

三分钟教你同步 Visual Studio Code 设置 (opens new window)

# 离线安装拓展

简单的 VSCode 插件离线安装方法 (opens new window)

安装指令

# vscode安装目录/bin
# 注意拓展的路径

./code --install-extension xxx/octref.vetur-0.22.6.vsix
1
2
3
4

# 批量下载离线安装包

这个需求的来源是:云桌面不能访问外网但是可以访问宿主机,想要同步宿主机的 vscode 拓展到云桌面环境

可以直接采用 离线安装拓展 的做法,但是当拓展多了就很浪费时间。

故主要做的事情就是:

  1. 获取并解析 拓展列表 配置文件
  2. 根据配置下载安装包

我们先上最终的操作步骤:

为了保证平台统一,我们的操作采用 git bash

进入宿主机的 vscode安装目录/bin 下,右键 Git Bash Here 执行以下脚本

# 先创建一个tmp临时目录,安装包都会下到里面
# tr '\n' ' ' 多行转一行
# | sh 将输出进行执行
mkdir tmp;
./code --list-extensions --show-versions | sed -r 's/(.*?)\.(.*?)@(.*)/https:\/\/marketplace.visualstudio.com\/_apis\/public\/gallery\/publishers\/\1\/vsextensions\/\2\/\3\/vspackage -o tmp\/\1.\2-\3.vsix/' | tr '\n' ' ' | sed -r 's/(.*)/curl \1/' | sh
1
2
3
4
5

安装包下载到 tmp 目录下

在云桌面的 vscode 中,点击 EXTENSIONS 后面的 … 符号,选择 install from VXIS 然后选择本地相应的插件包,插入,reload 即可。

下面进行详细介绍:

# 一、获取并解析 拓展列表 配置文件

# 方案0: 直接拿 配置同步 时 gist.github 中保存的json

# 方案1:解析目录并得到列表:

我们可以在以下目录中拿到拓展列表目录,目录名为${publisher}.${name}-${version}

Windows %USERPROFILE%\.vscode\extensions
Mac ~/.vscode/extensions
Linux ~/.vscode/extensions
1
2
3

这个方案是可行的,但是感觉操作有点麻烦,弃

# 方案2:使用code --list-extensions命令

在 vscode 安装目录下的bin目录中执行

// linux or git shell
./code --list-extensions --show-versions
// windows cmd or powershell
.\code --list-extensions --show-versions
1
2
3
4

可以列出 ${publisher}.${name}@${version}列表

例如(第一行为命名行操作完的提示,不在实际输出中):

[createInstance] extensionManagementService depends on downloadService which is NOT registered.
Andreabbondanza.ignoregit@1.0.1
bpruitt-goddard.mermaid-markdown-syntax-highlighting@1.0.1
dbaeumer.vscode-eslint@1.6.0
1
2
3
4

参考Command Line Interface (CLI) (opens new window)

# 方案3:使用 vscode npm 包

本想使用 vscode.extensions.all 接口拿到,碰到一些ts相关的问题后放弃了


最终采用 方案2

# 二、根据配置下载安装包

下载链接为:

https://marketplace.visualstudio.com/_apis/public/gallery/publishers/${publisher}/vsextensions/${name}/${version}/vspackage
1

假设某个插件配置为

  {
    "metadata": {
      "id": "e337c67b-55c2-4fef-8949-eb260e7fb7fd",
      "publisherId": "Shan.code-settings-sync",
      "publisherDisplayName": "Shan"
    },
    "name": "code-settings-sync",
    "publisher": "Shan",
    "version": "3.1.2"
  },
1
2
3
4
5
6
7
8
9
10

则 下载链接为

https://marketplace.visualstudio.com/_apis/public/gallery/publishers/Shan/vsextensions/code-settings-sync/3.1.2/vspackage
1

下载的文件名为 Shan.code-settings-sync-3.1.2.vsix

# 在指定目录下利用 git bash 下载文件

curl https://marketplace.visualstudio.com/_apis/public/gallery/publishers/Shan/vsextensions/code-settings-sync/3.1.2/vspackage -O
1

本以为使用 -O (以服务器上的名称保存在本地),下载的文件名是 Shan.code-settings-sync-3.1.2.vsix,结果是 vspackage

根据 cURL-将链接保存到文件 (opens new window) 中得知,

注意:使用 -O 选项时,必须确保链接末尾包含文件名,否则 curl 无法正确保存文件。如果遇到链接中无文件名的情况,应该使用 -o 选项手动指定文件名,或使用重定向符号。

另外介绍下 sh 的正则和文本替换

echo dbaeumer.vscode-eslint@1.6.0 | egrep "(.*?)\.(.*?)@(.*)"
#输出 dbaeumer.vscode-eslint@1.6.0
1
2

一开始使用 egrep 命令,发现不能直接做替换,后直接采用 sed 命令

echo 'dbaeumer.vscode-eslint@1.6.0' |  sed -r 's/(.*?)\.(.*?)@(.*)/\1.\2-\3.vsix/'
# 输出 dbaeumer.vscode-eslint-1.6.0.vsix
1
2

-r 参数表示 sed 开启拓展正则功能

参考 sed介绍 (opens new window)

单文件下载的 sh 命令即

echo 'dbaeumer.vscode-eslint@1.6.0' | sed -r 's/(.*?)\.(.*?)@(.*)/curl https:\/\/marketplace.visualstudio.com\/_apis\/public\/gallery\/publishers\/\1\/vsextensions\/\2\/\3\/vspackage -o \1.\2-\3.vsix/' | sh
1

结合步骤一

# 先创建一个tmp临时目录,安装包都会下到里面
# tr '\n' ' ' 多行转一行
# | sh 将输出进行执行
mkdir tmp;
./code --list-extensions --show-versions | sed -r 's/(.*?)\.(.*?)@(.*)/https:\/\/marketplace.visualstudio.com\/_apis\/public\/gallery\/publishers\/\1\/vsextensions\/\2\/\3\/vspackage -o tmp\/\1.\2-\3.vsix/' | tr '\n' ' ' | sed -r 's/(.*)/curl \1/' | sh
1
2
3
4
5

# 后续

发现有的文件下载下来安装不了,提示 end of central directory record signature not found

可能是当前插件所依赖的 vscode 版本较高,要么升级 vscode 要么下载旧版插件

可以去 https://marketplace.visualstudio.com/items/${publisher}.${name}/changelog 查看版本记录下载旧版本

也有可能需要去 gallery.vsassets.io 下载

https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
1

sh 命令

echo 'dbaeumer.vscode-eslint@1.6.0' | sed -r 's/(.*?)\.(.*?)@(.*)/curl https:\/\/\1.gallery.vsassets.io\/_apis\/public\/gallery\/publisher\/\1\/extension\/\2\/\3\/assetbyname\/Microsoft.VisualStudio.Services.VSIXPackage -o \1.\2-\3.vsix/' | sh
1

注意,如果用命令行下载的时候提示:curl:(92) HTTP/2 stream 1 was not closed cleanly: HTTP_1_1_REQUIRED (err 13),需要重新下

编辑 (opens new window)
#vscode#shell
上次更新: 2024/09/01, 23:56:56
VS code的Debugger For Chrome插件使用
vue-eslint-vscode 通用配置

← VS code的Debugger For Chrome插件使用 vue-eslint-vscode 通用配置→

最近更新
01
浅谈代码质量与量化指标
08-27
02
快速理解 JS 装饰器
08-26
03
Vue 项目中的 data-v-xxx 是怎么生成的
09-19
更多文章>
Theme by Vdoing | Copyright © 2016-2024 Gahing | 闽ICP备19024221号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式