Added shfmt
authoradithyasunil26 <adithyasunil26@gmail.com>
Fri, 8 Jan 2021 08:06:44 +0000 (12:06 +0400)
committerAJ ONeal <aj@therootcompany.com>
Sat, 9 Jan 2021 22:02:23 +0000 (22:02 +0000)
shfmt/README.md [new file with mode: 0644]
shfmt/install.ps1 [new file with mode: 0644]
shfmt/install.sh [new file with mode: 0644]
shfmt/releases.js [new file with mode: 0644]

diff --git a/shfmt/README.md b/shfmt/README.md
new file mode 100644 (file)
index 0000000..9b9f2ff
--- /dev/null
@@ -0,0 +1,71 @@
+---
+title: shfmt
+homepage: https://github.com/mvdan/sh
+tagline: |
+  shfmt: Format shell programs
+---
+
+To update or switch versions, run `webi shfmt@stable` or `webi shfmt@beta`, etc.
+
+# Cheat Sheet
+
+> shfmt is a shell parser, formatter and interpretter that supports POSIX Shell, Bash and mksh.
+
+Usage: `shfmt <flags> <filepath>`
+
+Note: If given path is directory, all shell scripts in the directory will be used. 
+
+## Flags:
+
+*-version*
+       Show version and exit.
+
+*-l*
+       List files whose formatting differs from shfmt's.
+
+*-w*
+       Write result to file instead of stdout.
+
+*-d*
+       Error with a diff when the formatting differs.
+
+*-s*
+       Simplify the code.
+
+*-mn*
+       Minify the code to reduce its size (implies -s).
+
+*-ln* <str>
+       Language variant to parse (bash/posix/mksh/bats, default "bash").
+
+*-p*
+       Shorthand for -ln=posix.
+
+*-filename* str
+       Provide a name for the standard input file.
+
+*-i* <uint>
+       Indent: 0 for tabs (default), >0 for number of spaces.
+
+*-bn*
+       Binary ops like && and | may start a line.
+
+*-ci*
+       Switch cases will be indented.
+
+*-sr*
+       Redirect operators will be followed by a space.
+
+*-kp*
+       Keep column alignment paddings.
+
+*-fn*
+       Function opening braces are placed on a separate line.
+
+*-f*
+       Recursively find all shell files and print the paths.
+
+*-tojson*
+       Print syntax tree to stdout as a typed JSON.
+
+See https://github.com/mvdan/sh for more info.
\ No newline at end of file
diff --git a/shfmt/install.ps1 b/shfmt/install.ps1
new file mode 100644 (file)
index 0000000..a4f1ae7
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env pwsh
+
+##################
+# Install shfmt #
+##################
+
+$pkg_cmd_name = "shfmt"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\shfmt.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\shfmt-v$Env:WEBI_VERSION\bin\shfmt.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\shfmt-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\shfmt-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    echo "Downloading shfmt from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd"))
+{
+    echo "Installing shfmt"
+    pushfmtd .local\tmp
+
+        Remove-Item -Path ".\shfmt-v*" -Recurse -ErrorAction Ignore
+        Remove-Item -Path ".\shfmt.exe" -Recurse -ErrorAction Ignore
+
+        echo "Unpacking $pkg_download"
+        & tar xf "$pkg_download"
+
+        echo "Install Location: $pkg_src_cmd"
+        New-Item "$pkg_src_bin" -ItemType Directory -Force
+        Move-Item -Path ".\shfmt-*\shfmt.exe" -Destination "$pkg_src_bin"
+
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/shfmt/install.sh b/shfmt/install.sh
new file mode 100644 (file)
index 0000000..90176a8
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+{
+       set -e
+       set -u
+
+       ##################
+       # Install shfmt #
+       ##################
+
+       pkg_cmd_name="shfmt"
+
+       pkg_dst_cmd="$HOME/.local/bin/shfmt"
+       pkg_dst="$pkg_dst_cmd"
+
+       pkg_src_cmd="$HOME/.local/opt/shfmt-v$WEBI_VERSION/bin/shfmt"
+       pkg_src_dir="$HOME/.local/opt/shfmt-v$WEBI_VERSION"
+       pkg_src="$pkg_src_cmd"
+
+       pkg_install() {
+               # ~/.local/opt/shfmt-v0.99.9/bin
+               mkdir -p "$(dirname $pkg_src_cmd)"
+               mv ./"$pkg_cmd_name"* "$pkg_src_cmd"
+       }
+
+       pkg_get_current_version() {
+               echo $(shfmt --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2)
+       }
+
+}
diff --git a/shfmt/releases.js b/shfmt/releases.js
new file mode 100644 (file)
index 0000000..e6cb017
--- /dev/null
@@ -0,0 +1,19 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'mvdan';
+var repo = 'sh';
+
+module.exports = function(request) {
+       return github(request, owner, repo).then(function(all) {
+               return all;
+       });
+};
+
+if (module === require.main) {
+       module.exports(require('@root/request')).then(function(all) {
+               all = require('../_webi/normalize.js')(all);
+               all.releases = all.releases.slice(0, 5);
+               console.info(JSON.stringify(all, null, 2));
+       });
+}