GoAdmio Command Line: reindent with /go/reindent

/go/reindent keeps shell scripts in one consistent style. It runs shfmt, a shell script formatter, with these settings: You can run it on one file, or on every *.sh file in the folder you are standing in. Every admin action in GoAdmio has a matching /go/ command, so anything you can click you can also script.

Quick start

# Reindent one script
/go/reindent /go/postmaxsize

# Reindent every .sh file in the current folder
cd /root/scripts
/go/reindent all

Options

There are no --option flags. The only arguments are:

Argument Required Default Notes
<file> One of the two — A path to a script. A relative path is taken from the current directory. Paths with spaces don’t work.
all One of the two — Matches *.sh in the current directory. It does not include subfolders or files without a .sh extension.

Examples

# Reindent one command
/go/reindent /go/quota

# Reindent all .sh files in a folder
cd /root/scripts
/go/reindent all

# Preview the changes without writing anything
shfmt -d -i 4 /go/quota

Output

Outcome What you get
File reformatted Nothing. shfmt -w is silent on success.
Syntax error in the script The shfmt error message. That file is left unchanged.
shfmt is not installed shfmt: command not found.
all with no .sh files An error from shfmt about the literal name *.sh.
The path doesn’t exist Nothing at all.

Notes on the output:

  • A path that doesn’t exist, or isn’t a regular file, is skipped silently, and the exit status is still 0. Check the result yourself.
  • Every run is logged with a timestamp and its arguments to /var/log/go/reindent.log.

See the full reference at /go/reindent and the GoAdmio command index.

GoAdmio is free and open source, with no license fees and no account limits. Read the GoAdmio docs, or see why it is a free cPanel alternative at goadmio.com.

By:

Posted in:


Leave a Reply

Your email address will not be published. Required fields are marked *