Unix shell 脚本根据大括号重新格式化代码文件中的制表符/缩进
Unix shell 脚本,用于根据大括号重新格式化代码文件中的制表符/缩进。
环顾四周,找到了一种在 vim 中使用可视模式和等号来执行此操作的方法,但我似乎找不到使用外部 unix shell 脚本来执行此操作的方法。这个想法是能够运行:
./scriptName filename(s)
并且所有文件都将根据花括号的深度缩进。它不必添加额外的换行符/回车符,只需根据深度缩进即可。
namespace Mine {
Class Yours
{
Yours() { something something; }
~Yours() { something
something more }
Yours(too)
{
etc.
} } // Programmer put two braces on the same line, don't do anything
}
我可以想象使用环境变量来跟踪大括号的深度,然后修剪每行上的空格并根据需要添加空格,但我似乎无法弄清楚。任何帮助将非常感激!
Unix shell script to reformat the tabbing/indenting in code files based on curly braces.
Looked around and found a way to do this in vim, using visual mode and the equals sign, but I can't seem to find a way to do it using an external unix shell script. The idea is to be able to run:
./scriptName filename(s)
And all files would be indented according to depth of curly braces. It doesn't have to add in extra newlines/return carriages, just indent based on depth.
namespace Mine {
Class Yours
{
Yours() { something something; }
~Yours() { something
something more }
Yours(too)
{
etc.
} } // Programmer put two braces on the same line, don't do anything
}
I can sort of imagine using an environment variable to keep track of the depth of braces, and then trimming the spaces on each line and adding spaces as needed, but I can't seem to figure it out. Any help would be really appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试缩进。
Try indent.