简体   繁体   English

格式化外壳脚本

[英]format the shell script

I have some 1000 lines shell script with all the kepywords 我有一些带有所有kepywords的1000行shell脚本

if/else, while, HERE document 如果/否则,在这里文档

Can anyone tell the best way to format the script, so the script looks good. 谁能说出格式化脚本的最佳方法,所以脚本看起来不错。

I was trying VG= in vim but that displaces HERE document content as well. 我在vim中尝试使用VG =,但这也替换了这里的文档内容。

检查此https://github.com/mvdan/sh ,这是缩进两个空格的示例命令

shfmt -i 2 -w yourscript

By default the gg=G gives you 8 tab spaces. 默认情况下, gg=G给您8个制表符空间。 To reduce the 8 tab spaces to 3 spaces edit your .vimrc file: 要将8个制表符空间减少到3个空间,请编辑.vimrc文件:

set tabstop=3
set shiftwidth=3
set expandtab

This SO question qives you a good, in context discussion of everything gg=G related. 在与gg=G相关的所有内容的上下文讨论中,这个SO问题使您感到满意。

使用VIM添加以下参数以缩进整个文件

gg=G

PyCharm's BashSupport plugin now has an experimental bash code formatter. PyCharm的BashSupport插件现在具有实验性的bash代码格式化程序。

Sadly the BashSupport plugin "will only receive fixes for major problems" as of 2017 . 不幸的是,自2017年起,BashSupport插件“将仅收到针对主要问题的修复程序”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM