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

本文介绍了在Linux环境下使用VSCode的shell-format插件美化shell脚本代码的过程,包括安装步骤、快捷键和遇到的不生效问题,解决方法是下载并手动放置shfmt文件到指定目录。
摘要由CSDN通过智能技术生成

前言

最近在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
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

一沐南风

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

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

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

打赏作者

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

抵扣说明:

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

余额充值