bash 格式化shell脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45412325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
format the shell script
提问by Ajay Singh
I have some 1000 lines shell script with all the kepywords
我有一些包含所有关键字的 1000 行 shell 脚本
if/else, while, HERE document
if/else, while, HERE 文档
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= 但这也取代了 HERE 文档内容。
回答by Daniel YC Lin
check this https://github.com/mvdan/sh, here is the sample command for indent with two spaces
检查这个https://github.com/mvdan/sh,这里是两个空格缩进的示例命令
shfmt -i 2 -w yourscript
shfmt -i 2 -w yourscript
回答by Arun Kurian
By default the gg=G
gives you 8 tab spaces. To reduce the 8 tab spaces to 3 spaces edit your .vimrc
file:
默认情况下,gg=G
它为您提供 8 个制表符空间。要将 8 个制表符空格减少到 3 个空格,请编辑您的.vimrc
文件:
set tabstop=3
set shiftwidth=3
set expandtab
This SO questionqives you a good, in context discussion of everything gg=G
related.
这个SO 问题让您在上下文中对所有gg=G
相关内容进行了很好的讨论。
回答by phk
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.
回答by DanieleO
Using VIM add the parameter below in order to indent the entire file
使用 VIM 添加以下参数以缩进整个文件
gg=G