使用VSCode格式化Shell脚本,让代码优雅起来

前言

最近在Linux环境中部署了一套springboot项目,由于目录结构繁杂,jdk环境以及jar包引用问题,启停项目非常不方便,于是写了一个shell脚本,实现一键启停服务。在写shell脚本的时候,代码格式看着非常的不顺眼,便想整治一下。

一、安装VSCode插件

在VSCode的插件栏位搜索shell-format,并点击安装
在这里插入图片描述
在这里插入图片描述

插件详情见:https://marketplace.visualstudio.com/items?itemName=foxundermoon.shell-format

二、使用方法

1.快捷键Ctrl+Alt+F

1.右键-格式化文档

三、插件不生效

在安装完插件后,发现使用以上的两种方式均不能格式化代码,而控制台报有错误信息:

shfmt hasn't downloaded yet!Error: ENOENT: no such file or directory, stat 'c:\Users\Administrator\.vscode\extensions\foxundermoon.shell-format-7.2.5\bin\shfmt_v3.6.0_windows_amd64.exe'
Shfmt will be downloaded automatically!
download url: https://github.com/mvdan/sh/releases/download/v3.6.0/shfmt_v3.6.0_windows_amd64.exe
download to: c:\Users\Administrator\.vscode\extensions\foxundermoon.shell-format-7.2.5\bin\shfmt_v3.6.0_windows_amd64.exe
If the download fails, you can manually download it to the dest directory.
Or download to another directory, and then set the "shellformat.path" as the path
download shfmt page: https://github.com/mvdan/sh/releases
You can't use this plugin until the download is successful.
Effective shfmt flags: -i=4
Effective shfmt flags: -i=4

是无法从GitHub上下载文件导致的,可通过重试或者手动点击下载,shfmt_v3.6.0_windows_amd64

完成后,把文件放在c:\Users\Administrator.vscode\extensions\foxundermoon.shell-format-7.2.5\bin目录下。
在这里插入图片描述
重新进行格式化即可。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要在VSCode中编写Shell脚本,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了VSCode。你可以从官方网站下载并安装VSCode的最新版本\[1\]。 2. 打开VSCode,并创建一个新的文件。你可以通过点击左上角的"文件"菜单,然后选择"新建文件"来创建一个新的文件。 3. 将文件保存为以".sh"为后缀的Shell脚本文件。例如,你可以将文件保存为"myscript.sh"。 4. 开始编写你的Shell脚本。你可以使用Shell脚本的语法来编写你的代码VSCode提供了许多有用的功能来帮助你编写和调试Shell脚本,例如语法高亮、代码补全和调试功能。 5. 如果你想运行你的Shell脚本,你可以打开终端窗口,并导航到你的脚本所在的目录。然后,使用"chmod +x"命令给你的脚本添加执行权限,例如"chmod +x myscript.sh"。 6. 最后,你可以在终端中运行你的Shell脚本,例如"./myscript.sh"。 总结起来,要在VSCode中编写Shell脚本,你需要安装VSCode,创建一个新的Shell脚本文件,编写你的代码,并在终端中运行你的脚本\[2\]\[3\]。希望这些步骤对你有帮助! #### 引用[.reference_title] - *1* [使用vscodeshell脚本](https://blog.csdn.net/Garenliu/article/details/123187689)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [VsCode编辑器shell脚本的编辑](https://blog.csdn.net/l1158513573/article/details/125132049)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一沐南风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值