开发者

Unix shell script to reformat the tabbing/indenting in code files based on curly braces

开发者 https://www.devze.com 2023-03-01 00:43 出处:网络
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 f

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; 开发者_如何学JAVA}
        ~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!


Try indent.

0

精彩评论

暂无评论...
验证码 换一张
取 消