Linux系统使用vscode格式化shell脚本
推荐工具及配置方案
BeautySH
-
特点
- 纯 Python 实现,轻量级且活跃维护。
-
配置步骤
-
安装 BeautySH
pip3 install beautysh
VSCode 集成
-
打开命令面板(
Ctrl+Shift+P
),输入Tasks: Configure Task
,选择Create tasks.json file from template
→Others
。 -
修改
tasks.json
,添加 BeautySH 任务:
{"version": "6.2.1", # 修改成自己安装的版本 查看版本 beautysh --version"tasks": [{"label": "Beautify Shell Script","type": "shell","command": "beautysh","args": ["${file}"], // 直接格式化当前文件"group": "build","problemMatcher": []}]}
-
保存后,在需要格式的代码中全选按
Ctrl+Shift+B
格式化
-
-
- 可能遇到的问题
# 由于beautysh基于python,所以在使用该插件之前,首先需要安装python
sudo yum install -y python3 python3-pip