Sign inSign up

ismv/shfmt

By ismv

Updated about 4 years ago

Image
1

174

ismv/shfmt repository overview

Shell Linter and formatter

Docker Image CI Docker Pulls

Usage

lint  # Lint all shell scripts
lint file1 file2 file3  # Lint files with name passed in args
format  # Reformat all shell scripts (Will exit 1 if something formatted)
format file1 file2 file3  # Reformat files with name passed in args
minify  # Minify all shell scripts (Will exit 1 if something formatted)
minify file1 file2 file3  # Minify files with name passed in args

Examples

Initial bash script
#!/bin/bash
MY_DIRECTORIES="/home /var/log"
echo "Top Ten Disk Space Usage"
for DIR in $MY_DIRECTORIES
do
echo "The $DIR Directory:"
du -S $DIR 2>/dev/null |
sort -rn |
sed '{11,$D; =}' |
sed 'N; s/\n/ /' |
awk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
done
exit
lint (with exit-code: 1)
--- example.sh.orig
+++ example.sh
@@ -1,13 +1,12 @@
 #!/bin/bash
 MY_DIRECTORIES="/home /var/log"
 echo "Top Ten Disk Space Usage"
-for DIR in $MY_DIRECTORIES
-do
-echo "The $DIR Directory:"
-du -S $DIR 2>/dev/null |
-sort -rn |
-sed '{11,$D; =}' |
-sed 'N; s/\n/ /' |
-awk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
+for DIR in $MY_DIRECTORIES; do
+    echo "The $DIR Directory:"
+    du -S $DIR 2>/dev/null |
+        sort -rn |
+        sed '{11,$D; =}' |
+        sed 'N; s/\n/ /' |
+        awk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
 done
 exit
format
#!/bin/bash
MY_DIRECTORIES="/home /var/log"
echo "Top Ten Disk Space Usage"
for DIR in $MY_DIRECTORIES; do
    echo "The $DIR Directory:"
    du -S $DIR 2>/dev/null |
        sort -rn |
        sed '{11,$D; =}' |
        sed 'N; s/\n/ /' |
        awk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
done
exit
minify
MY_DIRECTORIES="/home /var/log"
echo "Top Ten Disk Space Usage"
for DIR in $MY_DIRECTORIES;do
echo "The $DIR Directory:"
du -S $DIR 2>/dev/null|sort -rn|sed '{11,$D; =}'|sed 'N; s/\n/ /'|awk '{printf $1 ":" "\t" $2 "\t" $3 "\n"}'
done
exit

Tag summary

Content type

Image

Digest

Size

3.8 MB

Last updated

about 4 years ago

docker pull ismv/shfmt