Is there a formatter/beautifier for NGINX config files? [closed]
I found a few projects which might suit your needs:
- Nginx Formatter (python) by 1connect
you can get it here - Nginx beautifier (js/nodejs) by vasilevich
nginxbeautifier.com which lets you format configs quickly in a web browser.you can get a command line tool also on the same site to run it locally.
If your block lines end with {
's and }
's, this simple indenter could help you a bit.
It does not format all your configs, it only fixes indentation.
Original in awk (source):
#!/usr/bin/awk -f{sub(/^[ \t]+/,"");idx=0}/\{/{ctx++;idx=1}/\}/{ctx--}{id="";for(i=idx;i<ctx;i++)id=sprintf("%s%s", id, "\t");printf "%s%s\n", id, $0}
Or rewritten in python:
INDENT = ' ' * 4def indent(contents): lines = map(str.strip, contents.splitlines()) current_indent = 0 for index,line in enumerate(lines): if (line.endswith('}')): current_indent -= 1 lines[index] = current_indent * INDENT + line if (line.endswith('{')): current_indent += 1 return ('\n').join(lines)
There is a fork of http://jsbeautifier.org/ for nginx here: https://github.com/vasilevich/nginxbeautifier