From 2d40ec3a03f4684f6fabba7dee2981c992a13785 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 1 Apr 2024 15:19:49 -0400 Subject: Rename .bash files to .sh I was already using .sh to refer to shell scripts. When I added .bash, I didn't realize that the linter was set to act on .sh files and not .bash files, so all of these bash scripts escaped the linter. This commit renames them to .sh, removes the .bash extension support from Biz.Namespace, and fixes all the reported shellcheck errors. --- Biz/Ide/ftags.bash | 21 -------- Biz/Ide/ftags.sh | 21 ++++++++ Biz/Ide/hoog.bash | 17 ------- Biz/Ide/hoog.sh | 17 +++++++ Biz/Ide/hooks/commit-msg.bash | 2 - Biz/Ide/hooks/commit-msg.sh | 2 + Biz/Ide/hooks/post-applypatch.bash | 6 --- Biz/Ide/hooks/post-applypatch.sh | 6 +++ Biz/Ide/hooks/post-checkout.bash | 19 ------- Biz/Ide/hooks/post-checkout.sh | 19 +++++++ Biz/Ide/hooks/post-commit.bash | 6 --- Biz/Ide/hooks/post-commit.sh | 6 +++ Biz/Ide/hooks/post-merge.bash | 6 --- Biz/Ide/hooks/post-merge.sh | 6 +++ Biz/Ide/hooks/post-rewrite.bash | 6 --- Biz/Ide/hooks/post-rewrite.sh | 6 +++ Biz/Ide/hooks/pre-auto-gc.bash | 6 --- Biz/Ide/hooks/pre-auto-gc.sh | 6 +++ Biz/Ide/hooks/pre-commit.bash | 21 -------- Biz/Ide/hooks/pre-commit.sh | 21 ++++++++ Biz/Ide/hooks/pre-push.bash | 55 --------------------- Biz/Ide/hooks/pre-push.sh | 54 ++++++++++++++++++++ Biz/Ide/hooks/reference-transaction.bash | 12 ----- Biz/Ide/hooks/reference-transaction.sh | 12 +++++ Biz/Ide/mktags.bash | 41 --------------- Biz/Ide/mktags.sh | 41 +++++++++++++++ Biz/Ide/ns.bash | 26 ---------- Biz/Ide/ns.sh | 26 ++++++++++ Biz/Ide/push.bash | 19 ------- Biz/Ide/push.sh | 19 +++++++ Biz/Ide/repl.bash | 85 -------------------------------- Biz/Ide/repl.sh | 85 ++++++++++++++++++++++++++++++++ Biz/Ide/run.bash | 6 --- Biz/Ide/run.sh | 6 +++ Biz/Ide/ship.bash | 23 --------- Biz/Ide/ship.sh | 25 ++++++++++ Biz/Ide/tidy.bash | 2 - Biz/Ide/tidy.sh | 2 + Biz/Ide/tips.bash | 13 ----- Biz/Ide/tips.sh | 13 +++++ Biz/Ide/version.bash | 15 ------ Biz/Ide/version.sh | 15 ++++++ 42 files changed, 408 insertions(+), 407 deletions(-) delete mode 100755 Biz/Ide/ftags.bash create mode 100755 Biz/Ide/ftags.sh delete mode 100755 Biz/Ide/hoog.bash create mode 100755 Biz/Ide/hoog.sh delete mode 100755 Biz/Ide/hooks/commit-msg.bash create mode 100755 Biz/Ide/hooks/commit-msg.sh delete mode 100755 Biz/Ide/hooks/post-applypatch.bash create mode 100755 Biz/Ide/hooks/post-applypatch.sh delete mode 100755 Biz/Ide/hooks/post-checkout.bash create mode 100755 Biz/Ide/hooks/post-checkout.sh delete mode 100755 Biz/Ide/hooks/post-commit.bash create mode 100755 Biz/Ide/hooks/post-commit.sh delete mode 100755 Biz/Ide/hooks/post-merge.bash create mode 100755 Biz/Ide/hooks/post-merge.sh delete mode 100755 Biz/Ide/hooks/post-rewrite.bash create mode 100755 Biz/Ide/hooks/post-rewrite.sh delete mode 100755 Biz/Ide/hooks/pre-auto-gc.bash create mode 100755 Biz/Ide/hooks/pre-auto-gc.sh delete mode 100755 Biz/Ide/hooks/pre-commit.bash create mode 100755 Biz/Ide/hooks/pre-commit.sh delete mode 100755 Biz/Ide/hooks/pre-push.bash create mode 100755 Biz/Ide/hooks/pre-push.sh delete mode 100755 Biz/Ide/hooks/reference-transaction.bash create mode 100755 Biz/Ide/hooks/reference-transaction.sh delete mode 100755 Biz/Ide/mktags.bash create mode 100755 Biz/Ide/mktags.sh delete mode 100755 Biz/Ide/ns.bash create mode 100755 Biz/Ide/ns.sh delete mode 100755 Biz/Ide/push.bash create mode 100755 Biz/Ide/push.sh delete mode 100755 Biz/Ide/repl.bash create mode 100755 Biz/Ide/repl.sh delete mode 100755 Biz/Ide/run.bash create mode 100755 Biz/Ide/run.sh delete mode 100755 Biz/Ide/ship.bash create mode 100755 Biz/Ide/ship.sh delete mode 100755 Biz/Ide/tidy.bash create mode 100755 Biz/Ide/tidy.sh delete mode 100755 Biz/Ide/tips.bash create mode 100755 Biz/Ide/tips.sh delete mode 100755 Biz/Ide/version.bash create mode 100755 Biz/Ide/version.sh (limited to 'Biz/Ide') diff --git a/Biz/Ide/ftags.bash b/Biz/Ide/ftags.bash deleted file mode 100755 index 02d78c5..0000000 --- a/Biz/Ide/ftags.bash +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# search tags with fzf -# - set -euo pipefail - tags=${CODEROOT:?}/tags - tag_search=$( - awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' "$tags" \ - | cut -c1-80 \ - | fzf-tmux \ - --nth=1,2 \ - --preview-window=right \ - --bind="pgdn:preview-page-down" \ - --bind="pgup:preview-page-up" \ - --preview "rg --pretty --context 2 --word-regexp -F {+2}" - ) - ${EDITOR:-vim} \ - "$(cut -f3 <<< "$tag_search")" \ - -c "set nocst" \ - -c "silent tag $(cut -f2 <<< "$tag_search")" -## diff --git a/Biz/Ide/ftags.sh b/Biz/Ide/ftags.sh new file mode 100755 index 0000000..02d78c5 --- /dev/null +++ b/Biz/Ide/ftags.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# search tags with fzf +# + set -euo pipefail + tags=${CODEROOT:?}/tags + tag_search=$( + awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' "$tags" \ + | cut -c1-80 \ + | fzf-tmux \ + --nth=1,2 \ + --preview-window=right \ + --bind="pgdn:preview-page-down" \ + --bind="pgup:preview-page-up" \ + --preview "rg --pretty --context 2 --word-regexp -F {+2}" + ) + ${EDITOR:-vim} \ + "$(cut -f3 <<< "$tag_search")" \ + -c "set nocst" \ + -c "silent tag $(cut -f2 <<< "$tag_search")" +## diff --git a/Biz/Ide/hoog.bash b/Biz/Ide/hoog.bash deleted file mode 100755 index 976f0d4..0000000 --- a/Biz/Ide/hoog.bash +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# -# search hoogle with fzf -# - set -euo pipefail - HOOG="hoogle search --count=200" - export FZF_DEFAULT_COMMAND="$HOOG $*" - result=$(fzf-tmux \ - --preview-window=down \ - --preview "hoogle search --link --info {+2}" \ - --bind "change:reload:$HOOG {q} || true" \ - --ansi \ - | cut -d' ' -f 1,2 \ - | sed -e 's/ /./g' - ) - hoogle search --info "$result" -## diff --git a/Biz/Ide/hoog.sh b/Biz/Ide/hoog.sh new file mode 100755 index 0000000..976f0d4 --- /dev/null +++ b/Biz/Ide/hoog.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# +# search hoogle with fzf +# + set -euo pipefail + HOOG="hoogle search --count=200" + export FZF_DEFAULT_COMMAND="$HOOG $*" + result=$(fzf-tmux \ + --preview-window=down \ + --preview "hoogle search --link --info {+2}" \ + --bind "change:reload:$HOOG {q} || true" \ + --ansi \ + | cut -d' ' -f 1,2 \ + | sed -e 's/ /./g' + ) + hoogle search --info "$result" +## diff --git a/Biz/Ide/hooks/commit-msg.bash b/Biz/Ide/hooks/commit-msg.bash deleted file mode 100755 index 64e400d..0000000 --- a/Biz/Ide/hooks/commit-msg.bash +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/commit-msg.sh b/Biz/Ide/hooks/commit-msg.sh new file mode 100755 index 0000000..64e400d --- /dev/null +++ b/Biz/Ide/hooks/commit-msg.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/post-applypatch.bash b/Biz/Ide/hooks/post-applypatch.bash deleted file mode 100755 index 5071dc5..0000000 --- a/Biz/Ide/hooks/post-applypatch.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -## START BRANCHLESS CONFIG - -git branchless hook post-applypatch "$@" - -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-applypatch.sh b/Biz/Ide/hooks/post-applypatch.sh new file mode 100755 index 0000000..5071dc5 --- /dev/null +++ b/Biz/Ide/hooks/post-applypatch.sh @@ -0,0 +1,6 @@ +#!/bin/sh +## START BRANCHLESS CONFIG + +git branchless hook post-applypatch "$@" + +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-checkout.bash b/Biz/Ide/hooks/post-checkout.bash deleted file mode 100755 index 982cb4b..0000000 --- a/Biz/Ide/hooks/post-checkout.bash +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -set -e -mktags=${CODEROOT:?}/Biz/Ide/mktags -old=$1 -new=$2 -# filter out only the changed haskell files -changed=($(git diff --diff-filter=d --name-only $old $new -- '*.hs')) -if [[ ! -r tags ]] || [[ ! -r TAGS ]] -then - $mktags "$CODEROOT"/**/* -elif [[ ${#changed[@]} -gt 0 ]] -then - $mktags $changed -fi -direnv reload -## START BRANCHLESS CONFIG - -git branchless hook post-checkout "$@" -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-checkout.sh b/Biz/Ide/hooks/post-checkout.sh new file mode 100755 index 0000000..e4a0d67 --- /dev/null +++ b/Biz/Ide/hooks/post-checkout.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -e +mktags=${CODEROOT:?}/Biz/Ide/mktags.sh +old=$1 +new=$2 +# filter out only the changed haskell files +mapfile -t changed < <(git diff --diff-filter=d --name-only "$old" "$new" -- '*.hs') +if [[ ! -r tags ]] || [[ ! -r TAGS ]] +then + $mktags "$CODEROOT"/**/* +elif [[ ${#changed[@]} -gt 0 ]] +then + $mktags "${changed[@]}" +fi +direnv reload +## START BRANCHLESS CONFIG + +git branchless hook post-checkout "$@" +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-commit.bash b/Biz/Ide/hooks/post-commit.bash deleted file mode 100755 index cd1f195..0000000 --- a/Biz/Ide/hooks/post-commit.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -## START BRANCHLESS CONFIG - -git branchless hook post-commit "$@" - -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-commit.sh b/Biz/Ide/hooks/post-commit.sh new file mode 100755 index 0000000..cd1f195 --- /dev/null +++ b/Biz/Ide/hooks/post-commit.sh @@ -0,0 +1,6 @@ +#!/bin/sh +## START BRANCHLESS CONFIG + +git branchless hook post-commit "$@" + +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-merge.bash b/Biz/Ide/hooks/post-merge.bash deleted file mode 100755 index 94f0f60..0000000 --- a/Biz/Ide/hooks/post-merge.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD -## START BRANCHLESS CONFIG - -git branchless hook post-merge "$@" -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-merge.sh b/Biz/Ide/hooks/post-merge.sh new file mode 100755 index 0000000..d2cfa63 --- /dev/null +++ b/Biz/Ide/hooks/post-merge.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +"${CODEROOT:?}"/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD +## START BRANCHLESS CONFIG + +git branchless hook post-merge "$@" +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-rewrite.bash b/Biz/Ide/hooks/post-rewrite.bash deleted file mode 100755 index 8b3237a..0000000 --- a/Biz/Ide/hooks/post-rewrite.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -## START BRANCHLESS CONFIG - -git branchless hook post-rewrite "$@" - -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/post-rewrite.sh b/Biz/Ide/hooks/post-rewrite.sh new file mode 100755 index 0000000..8b3237a --- /dev/null +++ b/Biz/Ide/hooks/post-rewrite.sh @@ -0,0 +1,6 @@ +#!/bin/sh +## START BRANCHLESS CONFIG + +git branchless hook post-rewrite "$@" + +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/pre-auto-gc.bash b/Biz/Ide/hooks/pre-auto-gc.bash deleted file mode 100755 index c92a844..0000000 --- a/Biz/Ide/hooks/pre-auto-gc.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -## START BRANCHLESS CONFIG - -git branchless hook pre-auto-gc "$@" - -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/pre-auto-gc.sh b/Biz/Ide/hooks/pre-auto-gc.sh new file mode 100755 index 0000000..c92a844 --- /dev/null +++ b/Biz/Ide/hooks/pre-auto-gc.sh @@ -0,0 +1,6 @@ +#!/bin/sh +## START BRANCHLESS CONFIG + +git branchless hook pre-auto-gc "$@" + +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/pre-commit.bash b/Biz/Ide/hooks/pre-commit.bash deleted file mode 100755 index 560eee7..0000000 --- a/Biz/Ide/hooks/pre-commit.bash +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# - prevent frozen code from being checked in -# - guard against lint errors -## - set -e - changed=($(git diff-index --cached --name-only HEAD)) - for ns in ${changed[@]} - do - version=$(${CODEROOT:?}/Biz/Ide/version $ns) - if [[ $version -eq -1 ]]; then - echo "info: version: $ns: deleted" - elif [[ $version -lt 1 ]]; then - echo "fail: version: $ns: $version" - exit 1 - else - echo "info: version: $ns: $version" - fi - done - lint "${changed[@]}" -## diff --git a/Biz/Ide/hooks/pre-commit.sh b/Biz/Ide/hooks/pre-commit.sh new file mode 100755 index 0000000..e7c34ab --- /dev/null +++ b/Biz/Ide/hooks/pre-commit.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# +# - prevent frozen code from being checked in +# - guard against lint errors +## + set -e + mapfile -t changed < <(git diff-index --cached --name-only HEAD) + for ns in "${changed[@]}" + do + version=$("${CODEROOT:?}"/Biz/Ide/version "$ns") + if [[ $version -eq -1 ]]; then + echo "info: version: $ns: deleted" + elif [[ $version -lt 1 ]]; then + echo "fail: version: $ns: $version" + exit 1 + else + echo "info: version: $ns: $version" + fi + done + lint "${changed[@]}" +## diff --git a/Biz/Ide/hooks/pre-push.bash b/Biz/Ide/hooks/pre-push.bash deleted file mode 100755 index 5abd3ee..0000000 --- a/Biz/Ide/hooks/pre-push.bash +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash -# -# A simple ci that saves its results in a git note, formatted according to -# RFC-2822, more or less. -# -# To run this manually, exec the script. It will expect to read a line of -# inputs, you can just enter 'HEAD' and it will -# -## - set -uo pipefail - [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } -## - at=$(date -R) - user=$(git config --get user.name) - mail=$(git config --get user.email) -## - commit=$(git notes --ref=ci show HEAD || true) - if [[ -n "$commit" ]] - then - lint_ok=$() - if grep -q "Lint-is: good" <<< $commit - then - exit 0 - fi - if grep -q "Test-is: good" <<< $commit - then - exit 0 - fi - fi -## - if lint "${CODEROOT:?}"/**/* - then - lint_result="good" - else - lint_result="fail" - exit 1 - fi -## - if bild ${BILD_ARGS:-""} --test "${CODEROOT:?}"/**/* - then - test_result="good" - else - test_result="fail" - exit 1 - fi -## - read -r -d '' note < -Test-at: $at -EOF -## - git notes --ref=ci append -m "$note" -## diff --git a/Biz/Ide/hooks/pre-push.sh b/Biz/Ide/hooks/pre-push.sh new file mode 100755 index 0000000..16f11d1 --- /dev/null +++ b/Biz/Ide/hooks/pre-push.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# +# A simple ci that saves its results in a git note, formatted according to +# RFC-2822, more or less. +# +# To run this manually, exec the script. It will expect to read a line of +# inputs, you can just enter 'HEAD' and it will +# +## + set -uo pipefail + [[ -n $(git status -s) ]] && { echo fail: dirty worktree; exit 1; } +## + at=$(date -R) + user=$(git config --get user.name) + mail=$(git config --get user.email) +## + commit=$(git notes --ref=ci show HEAD || true) + if [[ -n "$commit" ]] + then + if grep -q "Lint-is: good" <<< "$commit" + then + exit 0 + fi + if grep -q "Test-is: good" <<< "$commit" + then + exit 0 + fi + fi +## + if lint "${CODEROOT:?}"/**/* + then + lint_result="good" + else + lint_result="fail" + exit 1 + fi +## + if bild "${BILD_ARGS:-""}" --test "${CODEROOT:?}"/**/* + then + test_result="good" + else + test_result="fail" + exit 1 + fi +## + read -r -d '' note < +Test-at: $at +EOF +## + git notes --ref=ci append -m "$note" +## diff --git a/Biz/Ide/hooks/reference-transaction.bash b/Biz/Ide/hooks/reference-transaction.bash deleted file mode 100755 index ea0cce6..0000000 --- a/Biz/Ide/hooks/reference-transaction.bash +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -## START BRANCHLESS CONFIG - -# Avoid canceling the reference transaction in the case that `branchless` fails -# for whatever reason. -git branchless hook reference-transaction "$@" || ( -echo 'branchless: Failed to process reference transaction!' -echo 'branchless: Some events (e.g. branch updates) may have been lost.' -echo 'branchless: This is a bug. Please report it.' -) - -## END BRANCHLESS CONFIG diff --git a/Biz/Ide/hooks/reference-transaction.sh b/Biz/Ide/hooks/reference-transaction.sh new file mode 100755 index 0000000..ea0cce6 --- /dev/null +++ b/Biz/Ide/hooks/reference-transaction.sh @@ -0,0 +1,12 @@ +#!/bin/sh +## START BRANCHLESS CONFIG + +# Avoid canceling the reference transaction in the case that `branchless` fails +# for whatever reason. +git branchless hook reference-transaction "$@" || ( +echo 'branchless: Failed to process reference transaction!' +echo 'branchless: Some events (e.g. branch updates) may have been lost.' +echo 'branchless: This is a bug. Please report it.' +) + +## END BRANCHLESS CONFIG diff --git a/Biz/Ide/mktags.bash b/Biz/Ide/mktags.bash deleted file mode 100755 index c83f319..0000000 --- a/Biz/Ide/mktags.bash +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# -# script to generate tags automatically if there are none. -# - set -euo pipefail - files=$@ - vimtags=${CODEROOT:?}/tags - emacstags=${CODEROOT:?}/TAGS -# - if [[ ! -r $emacstags ]]; then - echo Generating emacs TAGS from scratch... - fast-tags -e -R ${CODEROOT:?} - ctags -e \ - --append=yes \ - --recurse=yes \ - --exclude="$CODEROOT/_/*" \ - ${CODEROOT:?} - else - fast-tags -e $files - ctags -e \ - --append=yes \ - --exclude="_/*" \ - $files - fi -# - if [[ ! -r $vimtags ]]; then - echo Generating vim tags from scratch... - fast-tags "${flags[@]}" -R ${CODEROOT:?} - ctags "${flags[@]}" \ - --append=yes \ - --recurse=yes \ - --exclude="${CODEROOT:?}/_/*" \ - ${CODEROOT:?} - else - fast-tags "${flags[@]}" $files - ctags "${flags[@]}" \ - --append=yes \ - --exclude="_/*" \ - $files - fi -## diff --git a/Biz/Ide/mktags.sh b/Biz/Ide/mktags.sh new file mode 100755 index 0000000..aae1505 --- /dev/null +++ b/Biz/Ide/mktags.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# +# script to generate tags automatically if there are none. +# + set -euo pipefail + files="$*" + vimtags=${CODEROOT:?}/tags + emacstags=${CODEROOT:?}/TAGS +# + if [[ ! -r $emacstags ]]; then + echo Generating emacs TAGS from scratch... + fast-tags -e -R "${CODEROOT:?}" + ctags -e \ + --append=yes \ + --recurse=yes \ + --exclude="$CODEROOT/_/*" \ + "${CODEROOT:?}" + else + fast-tags -e "$files" + ctags -e \ + --append=yes \ + --exclude="_/*" \ + "$files" + fi +# + if [[ ! -r $vimtags ]]; then + echo Generating vim tags from scratch... + fast-tags -R "${CODEROOT:?}" + ctags \ + --append=yes \ + --recurse=yes \ + --exclude="${CODEROOT:?}/_/*" \ + "${CODEROOT:?}" + else + fast-tags "$files" + ctags \ + --append=yes \ + --exclude="_/*" \ + "$files" + fi +## diff --git a/Biz/Ide/ns.bash b/Biz/Ide/ns.bash deleted file mode 100755 index e988bfe..0000000 --- a/Biz/Ide/ns.bash +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -fd --exclude=_ -t f . ${CODEROOT:?} | sed "s,${CODEROOT:?}/*,,g" \ - | fzf \ - --bind "alt-space:execute(bild {} && read -p [fin])" \ - --bind "alt-enter:execute(vim {})" \ - --bind "alt-l:execute(lint {} && read -p [fin])" \ - --bind "enter:execute(repl {})" \ - --bind "ctrl-space:execute(ship {} && read -p [fin])" \ - --bind "alt-t:execute(bild {} && run {} test && read -p [fin])" \ - --bind "ctrl-/:change-preview-window(90%|hidden|)" \ - --bind "alt-0:change-preview(bat -p --color=always {})" \ - --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \ - --bind "alt-2:change-preview(git log --color=always {})" \ - --bind "alt-3:change-preview(git log --color=always -p {})" \ - --bind "alt-4:change-preview(git blame -c --date=short {})" \ - --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" \ - --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" \ - --bind "backward-eof:abort" \ - --bind "pgup:preview-page-up" \ - --bind "pgdn:preview-page-down" \ - --header="repl: enter | edit: alt-enter | bild: alt-space | test: alt-t | lint: alt-l | ship: ctrl-space" \ - --header-first \ - --preview-window="border-sharp,88" \ - --preview "bat -p --color=always {}" -### diff --git a/Biz/Ide/ns.sh b/Biz/Ide/ns.sh new file mode 100755 index 0000000..555380e --- /dev/null +++ b/Biz/Ide/ns.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +fd --exclude=_ -t f . "${CODEROOT:?}" | sed "s,${CODEROOT:?}/*,,g" \ + | fzf \ + --bind "alt-space:execute(bild {} && read -p [fin])" \ + --bind "alt-enter:execute(vim {})" \ + --bind "alt-l:execute(lint {} && read -p [fin])" \ + --bind "enter:execute(repl {})" \ + --bind "ctrl-space:execute(ship {} && read -p [fin])" \ + --bind "alt-t:execute(bild {} && run {} test && read -p [fin])" \ + --bind "ctrl-/:change-preview-window(90%|hidden|)" \ + --bind "alt-0:change-preview(bat -p --color=always {})" \ + --bind "alt-1:change-preview(git log --color=always --date=relative --abbrev-commit --pretty=format:'%Cred%h%Creset %s / %an %Creset%C(yellow)%d%Creset%Cgreen(%cr)%Creset' -- {})" \ + --bind "alt-2:change-preview(git log --color=always {})" \ + --bind "alt-3:change-preview(git log --color=always -p {})" \ + --bind "alt-4:change-preview(git blame -c --date=short {})" \ + --bind "alt-5:change-preview(git log --pretty=short {} | git shortlog -nse)" \ + --bind "alt-6:change-preview(git log --pretty=short {} | git shortlog)" \ + --bind "backward-eof:abort" \ + --bind "pgup:preview-page-up" \ + --bind "pgdn:preview-page-down" \ + --header="repl: enter | edit: alt-enter | bild: alt-space | test: alt-t | lint: alt-l | ship: ctrl-space" \ + --header-first \ + --preview-window="border-sharp,88" \ + --preview "bat -p --color=always {}" +### diff --git a/Biz/Ide/push.bash b/Biz/Ide/push.bash deleted file mode 100755 index 2238e06..0000000 --- a/Biz/Ide/push.bash +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Eventually convert to haskell, see: -# - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs -# - http://www.haskellforall.com/2018/08/nixos-in-production.html -prefix=$(echo $PWD | sed -e "s|^${CODEROOT:?}/*||g") -if [[ "$prefix" == "" ]] -then - target="$1" -else - target="$prefix.$1" -fi -what=$(realpath "${CODEROOT:?}/_/nix/$target") -# hack: get the domain from the activation script. there does not seem -# to be a way to get it from nix-instantiate -where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") -nix copy --to ssh://root@$where $what -ssh root@$where $what/bin/switch-to-configuration switch -ssh root@$where nix-env --profile /nix/var/nix/profiles/system --set $what -printf "${GRN}good: push: $target${NC}\n" diff --git a/Biz/Ide/push.sh b/Biz/Ide/push.sh new file mode 100755 index 0000000..6729c2f --- /dev/null +++ b/Biz/Ide/push.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Eventually convert to haskell, see: +# - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs +# - http://www.haskellforall.com/2018/08/nixos-in-production.html +prefix=${PWD/$CODEROOT} +if [[ "$prefix" == "" ]] +then + target="$1" +else + target="$prefix.$1" +fi +what=$(realpath "${CODEROOT:?}/_/nix/$target") +# hack: get the domain from the activation script. there does not seem +# to be a way to get it from nix-instantiate +where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") +nix copy --to ssh://root@"$where" "$what" +ssh root@"$where" "$what"/bin/switch-to-configuration switch +ssh root@"$where" nix-env --profile /nix/var/nix/profiles/system --set "$what" +echo "${GRN}good: push: $target${NC}" diff --git a/Biz/Ide/repl.bash b/Biz/Ide/repl.bash deleted file mode 100755 index a14b0b8..0000000 --- a/Biz/Ide/repl.bash +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/env bash -### -### a simple complement to bild which only deals with launching repls -### -### > repl [opts] -### -### Starts a repl/shell for one or more targets. (Currently, all targets must -### have the same extension for this to work.) Repls started with this script -### should bind to `localhost:$PORT`. -### -### Options: -### --bash start bash instead of the target language repl -help() { - sed -rn 's/^### ?//;T;p' "$0" -} -if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then - help - exit 1 -fi -## - set -e - CMD= - if [[ "$1" == "--bash" ]]; then - CMD="bash" - shift - fi - targets=${@:?} - json=$(bild --plan ${targets[@]}) - langdeps=$(jq --raw-output '.[].langdeps | join(" ")' <<< $json) - sysdeps=$(jq --raw-output '.[].sysdeps | join(" ")' <<< $json) - rundeps=$(jq --raw-output '.[].rundeps | join(" ")' <<< $json) - exts=$(jq --raw-output '.[].namespace.ext' <<< $json | sort | uniq) - packageSet=$(jq --raw-output '.[].packageSet' <<< $json) - module=$(jq --raw-output '.[].mainModule' <<< $json) - BILD="(import ${CODEROOT:?}/Biz/Bild.nix {})" - for lib in ${sysdeps[@]}; do - flags+=(--packages "$BILD.pkgs.${lib}") - flags+=(--packages "$BILD.pkgs.pkg-config") - done - for lib in ${rundeps[@]}; do - flags+=(--packages "$BILD.pkgs.${lib}") - done - case $exts in - C) - flags+=(--packages "$BILD.pkgs.gcc") - command="bash" - ;; - Hs) - if [ -z ${var+PORT} ]; then - echo "warn: repl: ghci does not support binding to a port" - fi - flags+=(--packages "$BILD.bild.haskell.ghcWith (h: with h; [$langdeps])") - command=${CMD:-"ghci -i${CODEROOT:?} -ghci-script ${CODEROOT:?}/.ghci ${targets[@]}"} - ;; - Scm) - for lib in ${langdeps[@]}; do - flags+=(--packages "$BILD.guile-${lib}") - done - flags+=(--packages "$BILD.guile") - command=${CMD:-"guile -L ${CODEROOT:?} -C ${CODEROOT:?}/_/int --r7rs --listen=${PORT:-37146}"} - ;; - Lisp) - flags+=(--packages "$BILD.bild.$packageSet (p: with p; [asdf swank $langdeps])") - command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"} - ;; - Rs) - flags+=(--packages "$BILD.nixpkgs.rustc") - command=bash - ;; - Py) - langdeps="$langdeps mypy" - flags+=(--packages ruff) - flags+=(--packages "$BILD.bild.python.pythonWith (p: with p; [$langdeps])") - PYTHONPATH=$CODEROOT:$PYTHONPATH - pycommand="python -i $CODEROOT/Biz/Repl.py $module ${targets[@]}" - command=${CMD:-"$pycommand"} - ;; - *) - echo "unsupported targets: ${targets[@]}" - exit 1 - ;; - esac -## - nix-shell "${flags[@]}" --command "$command" -## diff --git a/Biz/Ide/repl.sh b/Biz/Ide/repl.sh new file mode 100755 index 0000000..78fe1eb --- /dev/null +++ b/Biz/Ide/repl.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +### +### a simple complement to bild which only deals with launching repls +### +### > repl [opts] +### +### Starts a repl/shell for one or more targets. (Currently, all targets must +### have the same extension for this to work.) Repls started with this script +### should bind to `localhost:$PORT`. +### +### Options: +### --bash start bash instead of the target language repl +help() { + sed -rn 's/^### ?//;T;p' "$0" +} +if [[ $# == 0 ]] || [[ "$1" == "-h" ]]; then + help + exit 1 +fi +## + set -e + CMD= + if [[ "$1" == "--bash" ]]; then + CMD="bash" + shift + fi + targets="${*:?}" + json=$(bild --plan "${targets[@]}") + mapfile -t langdeps < <(jq --raw-output '.[].langdeps | select(length > 0) | join("\n")' <<< "$json") + mapfile -t sysdeps < <(jq --raw-output '.[].sysdeps | select(length > 0) | join("\n")' <<< "$json") + mapfile -t rundeps < <(jq --raw-output '.[].rundeps | select(length > 0) | join("\n")' <<< "$json") + exts=$(jq --raw-output '.[].namespace.ext' <<< "$json" | sort | uniq) + packageSet=$(jq --raw-output '.[].packageSet' <<< "$json") + module=$(jq --raw-output '.[].mainModule' <<< "$json") + BILD="(import ${CODEROOT:?}/Biz/Bild.nix {})" + declare -a flags=(--packages "$BILD.pkgs.pkg-config") + for lib in "${sysdeps[@]}"; do + flags+=(--packages "$BILD.pkgs.${lib}") + done + for lib in "${rundeps[@]}"; do + flags+=(--packages "$BILD.pkgs.${lib}") + done + case $exts in + C) + flags+=(--packages "$BILD.pkgs.gcc") + command="bash" + ;; + Hs) + if [ -z ${var+PORT} ]; then + echo "warn: repl: ghci does not support binding to a port" + fi + flags+=(--packages "$BILD.bild.haskell.ghcWith (h: with h; [${langdeps[*]}])") + command=${CMD:-"ghci -i${CODEROOT:?} -ghci-script ${CODEROOT:?}/.ghci ${targets[@]}"} + ;; + Scm) + for lib in "${langdeps[@]}"; do + flags+=(--packages "$BILD.guile-${lib}") + done + flags+=(--packages "$BILD.guile") + command=${CMD:-"guile -L ${CODEROOT:?} -C ${CODEROOT:?}/_/int --r7rs --listen=${PORT:-37146}"} + ;; + Lisp) + flags+=(--packages "$BILD.bild.$packageSet (p: with p; [asdf swank ${langdeps[*]}])") + command=${CMD:-"sbcl --eval '(require :asdf)' --eval '(require :swank)' --eval '(swank:create-server :port ${PORT:-4005})' --load $targets"} + ;; + Rs) + flags+=(--packages "$BILD.nixpkgs.rustc") + command=bash + ;; + Py) + langdeps+=("mypy") + flags+=(--packages ruff) + flags+=(--packages "$BILD.bild.python.pythonWith (p: with p; [${langdeps[*]}])") + PYTHONPATH=$CODEROOT:$PYTHONPATH + pycommand="python -i $CODEROOT/Biz/Repl.py $module ${targets[*]}" + command=${CMD:-"$pycommand"} + ;; + *) + echo "unsupported targets: ${targets[*]}" + exit 1 + ;; + esac +## + nix-shell "${flags[@]}" --command "$command" +## diff --git a/Biz/Ide/run.bash b/Biz/Ide/run.bash deleted file mode 100755 index f7b9d36..0000000 --- a/Biz/Ide/run.bash +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -set -eu -target=$1 -shift -out=$(rg --only-matching ": out (\w*)" -r '$1' $target) -exec "${CODEROOT:?}/_/bin/$out" "$@" diff --git a/Biz/Ide/run.sh b/Biz/Ide/run.sh new file mode 100755 index 0000000..8acb519 --- /dev/null +++ b/Biz/Ide/run.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -eu +target=$1 +shift +out=$(rg --only-matching ": out (\w*)" -r '$1' "$target") +exec "${CODEROOT:?}/_/bin/$out" "$@" diff --git a/Biz/Ide/ship.bash b/Biz/Ide/ship.bash deleted file mode 100755 index 33197c8..0000000 --- a/Biz/Ide/ship.bash +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# -# ship ... -# -# lint, bild, test, and push one or more targets. if no targets are supplied, -# ship everything we know how to ship -## - set -eu - stuff=(${@}) - if [[ ${#stuff[@]} -eq 0 ]] - then - stuff=$(fd -t l . "$CODEROOT/_" \ - | fzf --multi \ - | sed "s,$CODEROOT/_/nix/,,g" - ) - fi - lint ${stuff[@]} - bild --test ${stuff[@]} - for thing in ${stuff[@]} - do - push $thing - done -## diff --git a/Biz/Ide/ship.sh b/Biz/Ide/ship.sh new file mode 100755 index 0000000..8783e9b --- /dev/null +++ b/Biz/Ide/ship.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# +# ship ... +# +# lint, bild, test, and push one or more targets. if no targets are supplied, +# ship everything we know how to ship +## + set -eu + stuff=("${@}") + if [[ ${#stuff[@]} -eq 0 ]] + then + mapfile -t stuff < <(fd -t l . "$CODEROOT/_/nix/" \ + | sed "s,$CODEROOT/_/nix/,,g" \ + | fzf --multi --prompt="ship _/nix/" \ + --preview="file $CODEROOT/_/nix/{}" \ + --preview-window=bottom,wrap + ) + fi + lint "${stuff[@]}" + bild --test "${stuff[@]}" + for thing in "${stuff[@]}" + do + push.sh "$thing" + done +## diff --git a/Biz/Ide/tidy.bash b/Biz/Ide/tidy.bash deleted file mode 100755 index ec666ba..0000000 --- a/Biz/Ide/tidy.bash +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -rm -f $CODEROOT/_/bin/* diff --git a/Biz/Ide/tidy.sh b/Biz/Ide/tidy.sh new file mode 100755 index 0000000..81a07c4 --- /dev/null +++ b/Biz/Ide/tidy.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +rm -f "$CODEROOT"/_/bin/* diff --git a/Biz/Ide/tips.bash b/Biz/Ide/tips.bash deleted file mode 100755 index ba458ac..0000000 --- a/Biz/Ide/tips.bash +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -echo "" -echo "bizdev" | figlet | lolcat -echo "" -echo " bild.bash compile code" -echo " repl.bash start a repl" -echo " deps.bash manage dependencies with niv" -echo " tips.bash show this message" -echo " lint.bash auto-lint all changed files" -echo " push.bash send a namespace to the cloud" -echo " ship.bash lint, bild, and push one (or all) namespace(s)" -echo " tidy.bash cleanup common working files" -echo "" diff --git a/Biz/Ide/tips.sh b/Biz/Ide/tips.sh new file mode 100755 index 0000000..895e54e --- /dev/null +++ b/Biz/Ide/tips.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +echo "" +echo "bizdev" | figlet | lolcat +echo "" +echo " bild.sh compile code" +echo " repl.sh start a repl" +echo " deps.sh manage dependencies with niv" +echo " tips.sh show this message" +echo " lint.sh auto-lint all changed files" +echo " push.sh send a namespace to the cloud" +echo " ship.sh lint, bild, and push one (or all) namespace(s)" +echo " tidy.sh cleanup common working files" +echo "" diff --git a/Biz/Ide/version.bash b/Biz/Ide/version.bash deleted file mode 100755 index 5b017d9..0000000 --- a/Biz/Ide/version.bash +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -# -# simple implementation of kelvin versioning -## - ns=$1 - if [[ -e "$1" ]]; then - commits=$(git log --oneline --follow $ns | wc -l) - # gold melts at 1337 kelvin, so we start with this - # bc we are forging gold here - version=$(bc -l <<< "1337 - $commits") - echo $version - else - echo -1 # signal that file doesn't exist - fi -## diff --git a/Biz/Ide/version.sh b/Biz/Ide/version.sh new file mode 100755 index 0000000..60f9c91 --- /dev/null +++ b/Biz/Ide/version.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# +# simple implementation of kelvin versioning +## + ns=$1 + if [[ -e "$1" ]]; then + commits=$(git log --oneline --follow "$ns" | wc -l) + # gold melts at 1337 kelvin, so we start with this + # bc we are forging gold here + version=$(bc -l <<< "1337 - $commits") + echo "$version" + else + echo -1 # signal that file doesn't exist + fi +## -- cgit v1.2.3