summaryrefslogtreecommitdiff
path: root/Biz
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2021-12-21 21:12:41 -0500
committerBen Sima <ben@bsima.me>2021-12-21 21:12:41 -0500
commit9a10f244693f4d0c17f4e758e64dbdc014299c9f (patch)
treee293cfae8637e54774c4a430b32b12dfcb3a1e2b /Biz
parentcf3fa3bdfab272151a734fe1b8725226b72f8521 (diff)
Enable shellcheck lint and fix its warnings
Diffstat (limited to 'Biz')
-rw-r--r--Biz/Bild/ShellHook.sh171
-rwxr-xr-xBiz/Ide/ftags.sh4
-rwxr-xr-xBiz/Ide/hoog.sh2
-rw-r--r--Biz/Lint.hs15
4 files changed, 98 insertions, 94 deletions
diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh
index 96c2e56..1cdb8ca 100644
--- a/Biz/Bild/ShellHook.sh
+++ b/Biz/Bild/ShellHook.sh
@@ -1,88 +1,89 @@
-function help() {
- echo ""
- echo "bizdev" | figlet | lolcat
- echo ""
- echo " bild compile code"
- echo " repl start a repl"
- echo " ci run all builds and tests"
- echo " deps manage dependencies with niv"
- echo " help show this message"
- echo " lint auto-lint all changed files"
- echo " pie product improvement engine"
- echo " push send a namespace to the cloud"
- echo " ship lint, bild, and push one (or all) namespace(s)"
-}
-
+#!/usr/bin/env bash
+##
+ function help() {
+ echo ""
+ echo "bizdev" | figlet | lolcat
+ echo ""
+ echo " bild compile code"
+ echo " repl start a repl"
+ echo " ci run all builds and tests"
+ echo " deps manage dependencies with niv"
+ echo " help show this message"
+ echo " lint auto-lint all changed files"
+ echo " pie product improvement engine"
+ echo " push send a namespace to the cloud"
+ echo " ship lint, bild, and push one (or all) namespace(s)"
+ }
+#
# color codes for use with printf
-export RED='\033[0;31m'
-export GRN='\033[0;32m'
-export YEL='\033[0;33m'
-export NC='\033[0m' # No Color
-
-alias runghc="runghc --ghc-arg=-i$BIZ_ROOT"
-
-alias guile="guile -L $BIZ_ROOT"
-
-alias tree="tree -I _ -F"
-
+ export RED='\033[0;31m'
+ export GRN='\033[0;32m'
+ export YEL='\033[0;33m'
+ export NC='\033[0m' # No Color
+#
+ alias runghc="runghc --ghc-arg=-i\$BIZ_ROOT"
+ alias guile="guile -L \$BIZ_ROOT"
+ alias tree="tree -I _ -F"
# link git hooks
-rm -f $BIZ_ROOT/.git/hooks/{post-checkout,post-merge,pre-commit,pre-push}
-ln -s $BIZ_ROOT/Biz/Ide/post-checkout $BIZ_ROOT/.git/hooks/post-checkout
-ln -s $BIZ_ROOT/Biz/Ide/post-merge $BIZ_ROOT/.git/hooks/post-merge
-ln -s $BIZ_ROOT/Biz/Ide/pre-commit $BIZ_ROOT/.git/hooks/pre-commit
-ln -s $BIZ_ROOT/Biz/Ide/pre-push $BIZ_ROOT/.git/hooks/pre-push
-
-function deps() {
- niv --sources-file $BIZ_ROOT/Biz/Bild/Sources.json $@
-}
-
-function pie() {
- runghc Biz.Pie $@
-}
-
-function run-sentry() {
- urls=(
- http://que.run
- https://dragons.dev
- https://simatime.com
- https://tv.simatime.com
- https://bsima.me
- # https://herocomics.app
- )
- for url in ${urls[@]}
- do
- code=$(curl -L --max-time 10 --silent --show-error --insecure \
- --output /dev/null \
- --write-out "%{http_code}" "$url")
- case "$code" in
- 2[0-9][0-9]) printf "${GRN}$code $url${NC}\n";;
- 3[0-9][0-9]) printf "${YEL}$code $url${NC}\n";;
- 4[0-9][0-9]) printf "${YEL}$code $url${NC}\n";;
- 5[0-9][0-9]) printf "${RED}$code $url${NC}\n";;
- *) printf "${RED}$code $url${NC}\n";;
- esac
- done
-}
-
-function sentry() {
- while true
- do
- clear
- printf "%s sentry\n\n" "$(date +%Y.%m.%d..%H.%M)"
- run-sentry
- sleep 120
- done
-}
-
+ rm -f "$BIZ_ROOT/.git/hooks/{post-checkout,post-merge,pre-commit,pre-push}"
+ ln -s "$BIZ_ROOT/Biz/Ide/post-checkout" "$BIZ_ROOT/.git/hooks/post-checkout"
+ ln -s "$BIZ_ROOT/Biz/Ide/post-merge" "$BIZ_ROOT/.git/hooks/post-merge"
+ ln -s "$BIZ_ROOT/Biz/Ide/pre-commit" "$BIZ_ROOT/.git/hooks/pre-commit"
+ ln -s "$BIZ_ROOT/Biz/Ide/pre-push" "$BIZ_ROOT/.git/hooks/pre-push"
+#
+ function deps() {
+ niv --sources-file "$BIZ_ROOT/Biz/Bild/Sources.json" "$@"
+ }
+#
+ function pie() {
+ runghc Biz.Pie "$@"
+ }
+#
+ function run-sentry() {
+ urls=(
+ http://que.run
+ https://dragons.dev
+ https://simatime.com
+ https://tv.simatime.com
+ https://bsima.me
+ # https://herocomics.app
+ )
+ for url in "${urls[@]}"
+ do
+ code=$(curl -L --max-time 10 --silent --show-error --insecure \
+ --output /dev/null \
+ --write-out "%{http_code}" "$url")
+ case "$code" in
+ 2[0-9][0-9]) color=${GRN};;
+ 3[0-9][0-9]) color=${YEL};;
+ 4[0-9][0-9]) color=${YEL};;
+ 5[0-9][0-9]) color=${RED};;
+ *) color=${RED};;
+ esac
+ printf "%b%s %s%b\n" "$color" "$code" "$url" "$NC"
+ done
+ }
+#
+ function sentry() {
+ while true
+ do
+ clear
+ printf "%s sentry\n\n" "$(date +%Y.%m.%d..%H.%M)"
+ run-sentry
+ sleep 120
+ done
+ }
+#
# Poor man's ci
-function run-ci() {
- lint **/* && bild --test **/*
-}
-
-function ci() {
- time run-ci
-}
-
-export PS1='\n$(r=$? && [ $r -eq 0 ] && printf "biz" || printf "%3.*s" $r $r)> '
-
-help
+ function run-ci() {
+ lint ./**/* && bild --test ./**/*
+ }
+#
+ function ci() {
+ time run-ci
+ }
+# shellcheck disable=SC2154
+ export PS1='\n$(r=$? && [ $r -eq 0 ] && printf "biz" || printf "%3.*s" $r $r)> '
+#
+ help
+##
diff --git a/Biz/Ide/ftags.sh b/Biz/Ide/ftags.sh
index 4b8396b..77646da 100755
--- a/Biz/Ide/ftags.sh
+++ b/Biz/Ide/ftags.sh
@@ -5,7 +5,7 @@
set -euo pipefail
tags=$BIZ_ROOT/tags
tag_search=$(
- awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' $tags \
+ awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' "$tags" \
| cut -c1-80 \
| fzf \
--nth=1,2 \
@@ -13,7 +13,7 @@
--preview "rg --ignore-case --pretty --context 2 --word-regexp {+2}"
)
${EDITOR:-vim} \
- $(cut -f3 <<< "$tag_search") \
+ "$(cut -f3 <<< "$tag_search")" \
-c "set nocst" \
-c "silent tag $(cut -f2 <<< "$tag_search")"
##
diff --git a/Biz/Ide/hoog.sh b/Biz/Ide/hoog.sh
index 5379e54..3945f90 100755
--- a/Biz/Ide/hoog.sh
+++ b/Biz/Ide/hoog.sh
@@ -4,7 +4,7 @@
#
set -euo pipefail
HOOG="hoogle search --count=200"
- export FZF_DEFAULT_COMMAND="$HOOG $@"
+ export FZF_DEFAULT_COMMAND="$HOOG $*"
fzf \
--preview-window=down \
--preview "hoogle search --link --info {+2}" \
diff --git a/Biz/Lint.hs b/Biz/Lint.hs
index 38c7403..8d5a757 100644
--- a/Biz/Lint.hs
+++ b/Biz/Lint.hs
@@ -87,13 +87,13 @@ printResult r@(NoOp path_) =
>> pure r
changedFiles :: IO [FilePath]
-changedFiles = mergeBase +> changed
+changedFiles =
+ git ["merge-base", "HEAD", "origin/master"]
+ /> filter (/= '\n')
+ +> (\mb -> git ["diff", "--name-only", "--diff-filter=d", mb])
+ /> String.lines
where
git args = Process.readProcess "git" args ""
- mergeBase = git ["merge-base", "HEAD", "origin/master"] /> filter (/= '\n')
- changed mb =
- String.lines
- </ git ["diff", "--name-only", "--diff-filter=d", mb]
data Linter = Linter
{ exe :: Text,
@@ -126,6 +126,9 @@ pylint =
fixArgs = Nothing
}
+shellcheck :: Linter
+shellcheck = Linter {exe = "shellcheck", args = [], fixArgs = Nothing}
+
data Status = Good | Bad String
deriving (Show)
@@ -152,7 +155,7 @@ runOne shouldFix root cwd path_ = results +> traverse_ printResult >> results
lint shouldFix hlint path_
]
Just (Namespace _ Py) -> [lint shouldFix pylint path_]
- Just (Namespace _ Sh) -> [pure <| NoOp path_] -- [lint "shellcheck" [] path_]
+ Just (Namespace _ Sh) -> [lint shouldFix shellcheck path_]
Just (Namespace _ Nix) -> [pure <| NoOp path_]
Just (Namespace _ Scm) -> [pure <| NoOp path_]
Just _ -> [pure <. Warn <| "no linter for " <> Text.pack path_]