From d0ba51f5842f0e19c43c7ea1b41a7f83c6ef99b6 Mon Sep 17 00:00:00 2001 From: Dave Rolsky Date: Sat, 11 May 2024 10:28:33 +0800 Subject: [PATCH] Use shfmt to format all shell code --- bootstrap/bootstrap-ubi.sh | 179 ++++++++++++++++++----------------- dev/bin/install-dev-tools.sh | 11 ++- precious.toml | 10 ++ 3 files changed, 106 insertions(+), 94 deletions(-) diff --git a/bootstrap/bootstrap-ubi.sh b/bootstrap/bootstrap-ubi.sh index a9c2893..0e6b035 100755 --- a/bootstrap/bootstrap-ubi.sh +++ b/bootstrap/bootstrap-ubi.sh @@ -22,26 +22,26 @@ if [ -z "$FILENAME" ]; then LIBC="" EXT="tar.gz" case "$KERNEL" in - Linux) - OS="Linux" - ;; - Darwin) - OS="Darwin" - ;; - FreeBSD) - OS="FreeBSD" - ;; - NetBSD) - OS="NetBSD" - ;; - MINGW*) - OS="Windows" - EXT="zip" - ;; - *) - echo "boostrap-ubi.sh: Cannot determine what binary to download for your kernel: $KERNEL" - exit 3 - ;; + Linux) + OS="Linux" + ;; + Darwin) + OS="Darwin" + ;; + FreeBSD) + OS="FreeBSD" + ;; + NetBSD) + OS="NetBSD" + ;; + MINGW*) + OS="Windows" + EXT="zip" + ;; + *) + echo "boostrap-ubi.sh: Cannot determine what binary to download for your kernel: $KERNEL" + exit 3 + ;; esac # I previous had uname -p but that reports all sorts of weird stuff. On one @@ -49,72 +49,73 @@ if [ -z "$FILENAME" ]; then # "i386". Why? I have no idea. ARCH=$(uname -m) case "$ARCH" in - i386|i486|i586|i686) - CPU="i786" - if [ "$OS" = "Linux" ]; then - LIBC="-musl" - fi - ;; - x86_64|amd64) - CPU="x86_64" - if [ "$OS" = "Linux" ]; then - LIBC="-musl" - fi - ;; - arm|armv5*|armv6*|armv7*) - CPU="arm" - if [ "$OS" = "Linux" ]; then - LIBC="-musl" - fi - ;; - aarch64|arm64) - CPU="aarch64" - if [ "$OS" = "Linux" ]; then - LIBC="-musl" - fi - ;; - mips) - CPU="mips" - ;; - mipsel|mipsle) - CPU="mipsel" - ;; - mips64) - CPU="mips64" - ;; - mips64el|mips64le) - CPU="mips64el" - ;; - powerpc|ppc) - CPU="powerpc" - if [ "$OS" = "Linux" ]; then - LIBC="-gnu" - fi - ;; - powerpc64|ppc64) - CPU="powerpc64" - if [ "$OS" = "Linux" ]; then - LIBC="-gnu" - fi - ;; - powerpc64le|ppc64le) - CPU="powerpc64le" - ;; - riscv64|rv64gc) - CPU="riscv64gc" - if [ "$OS" = "Linux" ]; then - LIBC="-gnu" - fi - ;; - s390x) - CPU="s390x" - if [ "$OS" = "Linux" ]; then - LIBC="-gnu" - fi - ;; - *) - echo "boostrap-ubi.sh: Cannot determine what binary to download for your CPU architecture: $ARCH" - exit 4 + i386 | i486 | i586 | i686) + CPU="i786" + if [ "$OS" = "Linux" ]; then + LIBC="-musl" + fi + ;; + x86_64 | amd64) + CPU="x86_64" + if [ "$OS" = "Linux" ]; then + LIBC="-musl" + fi + ;; + arm | armv5* | armv6* | armv7*) + CPU="arm" + if [ "$OS" = "Linux" ]; then + LIBC="-musl" + fi + ;; + aarch64 | arm64) + CPU="aarch64" + if [ "$OS" = "Linux" ]; then + LIBC="-musl" + fi + ;; + mips) + CPU="mips" + ;; + mipsel | mipsle) + CPU="mipsel" + ;; + mips64) + CPU="mips64" + ;; + mips64el | mips64le) + CPU="mips64el" + ;; + powerpc | ppc) + CPU="powerpc" + if [ "$OS" = "Linux" ]; then + LIBC="-gnu" + fi + ;; + powerpc64 | ppc64) + CPU="powerpc64" + if [ "$OS" = "Linux" ]; then + LIBC="-gnu" + fi + ;; + powerpc64le | ppc64le) + CPU="powerpc64le" + ;; + riscv64 | rv64gc) + CPU="riscv64gc" + if [ "$OS" = "Linux" ]; then + LIBC="-gnu" + fi + ;; + s390x) + CPU="s390x" + if [ "$OS" = "Linux" ]; then + LIBC="-gnu" + fi + ;; + *) + echo "boostrap-ubi.sh: Cannot determine what binary to download for your CPU architecture: $ARCH" + exit 4 + ;; esac FILENAME="ubi-$OS-$CPU$LIBC.$EXT" @@ -126,12 +127,12 @@ else URL="https://github.com/houseabsolute/ubi/releases/download/$TAG/$FILENAME" fi -TEMPDIR=$( mktemp -d ) +TEMPDIR=$(mktemp -d) trap 'rm -rf -- "$TEMPDIR"' EXIT LOCAL_FILE="$TEMPDIR/$FILENAME" echo "downloading $URL" -STATUS=$( curl --silent --output "$LOCAL_FILE" --write-out "%{http_code}" --location "$URL" ) +STATUS=$(curl --silent --output "$LOCAL_FILE" --write-out "%{http_code}" --location "$URL") if [ -z "$STATUS" ]; then >&2 echo "curl failed to download $URL and did not print a status code" exit 5 @@ -152,7 +153,7 @@ echo "" echo "boostrap-ubi.sh: ubi has been installed to $TARGET." set +e -TARGET_IS_IN_PATH=$( echo ":$PATH:" | grep --extended-regexp ":$TARGET:" 2> /dev/null ) +TARGET_IS_IN_PATH=$(echo ":$PATH:" | grep --extended-regexp ":$TARGET:" 2>/dev/null) if [ -z "$TARGET_IS_IN_PATH" ]; then echo "boostrap-ubi.sh: It looks like $TARGET is not in your PATH. You may want to add it to use ubi." fi diff --git a/dev/bin/install-dev-tools.sh b/dev/bin/install-dev-tools.sh index cf26dd2..32e7e85 100755 --- a/dev/bin/install-dev-tools.sh +++ b/dev/bin/install-dev-tools.sh @@ -2,19 +2,20 @@ set -eo pipefail -function run () { +function run() { echo "$1" eval "$1" } -function install_tools () { +function install_tools() { curl --silent --location \ - https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | + https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | sh run "rustup component add clippy" run "ubi --project houseabsolute/precious --in ~/bin" run "ubi --project houseabsolute/omegasort --in ~/bin" run "ubi --project koalaman/shellcheck --in ~/bin" + run "ubi --project mvdan/sh --in ~/bin --exe shfmt" run "npm install prettier@2.7.1" } @@ -25,7 +26,7 @@ fi mkdir -p "$HOME/bin" set +e -if echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >& /dev/null; then +if echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >&/dev/null; then path_has_home_bin=1 fi set -e @@ -38,7 +39,7 @@ install_tools echo "Tools were installed into $HOME/bin." if [ -z "$path_has_home_bin" ]; then - echo "You should add $HOME/bin to your PATH." + echo "You should add $HOME/bin to your PATH." fi exit 0 diff --git a/precious.toml b/precious.toml index 7702b88..7a62977 100644 --- a/precious.toml +++ b/precious.toml @@ -47,3 +47,13 @@ include = "**/*.sh" cmd = "shellcheck" ok_exit_codes = 0 lint_failure_exit_codes = 1 + +[commands.shfmt] +type = "both" +include = "**/*.sh" +cmd = [ "shfmt", "--simplify", "--indent", "4" ] +lint_flags = "--diff" +tidy_flags = "--write" +ok_exit_codes = 0 +lint_failure_exit_codes = 1 +