From 904de577261e7024373e7a42fd763184764238f9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 10 Oct 2023 13:15:59 -0400 Subject: Don't swallow namespace-parsing errors Previously, if there was a problem with the inputs and bild failed to determine the namespace, 'fromPath' would return 'Nothing' and then 'catMaybes' would drop the error-causing input altogether. In the one time that I had a bad input, this made debugging incredibly difficult. It's always a bad idea to swallow errors silently, so instead lets just kill the program if we have bad inputs. --- Biz/Ide/ftags | 21 ---------- Biz/Ide/ftags.bash | 21 ++++++++++ Biz/Ide/hoog | 17 -------- Biz/Ide/hoog.bash | 17 ++++++++ Biz/Ide/hooks/commit-msg | 2 - Biz/Ide/hooks/commit-msg.bash | 2 + Biz/Ide/hooks/post-checkout | 15 ------- Biz/Ide/hooks/post-checkout.bash | 15 +++++++ Biz/Ide/hooks/post-merge | 2 - Biz/Ide/hooks/post-merge.bash | 2 + Biz/Ide/hooks/pre-commit | 21 ---------- Biz/Ide/hooks/pre-commit.bash | 21 ++++++++++ Biz/Ide/hooks/pre-push | 58 --------------------------- Biz/Ide/hooks/pre-push.bash | 58 +++++++++++++++++++++++++++ Biz/Ide/mktags | 41 ------------------- Biz/Ide/mktags.bash | 41 +++++++++++++++++++ Biz/Ide/ns | 26 ------------ Biz/Ide/ns.bash | 26 ++++++++++++ Biz/Ide/push | 19 --------- Biz/Ide/push.bash | 19 +++++++++ Biz/Ide/repl | 87 ---------------------------------------- Biz/Ide/repl.bash | 87 ++++++++++++++++++++++++++++++++++++++++ Biz/Ide/run | 6 --- Biz/Ide/run.bash | 6 +++ Biz/Ide/ship | 23 ----------- Biz/Ide/ship.bash | 23 +++++++++++ Biz/Ide/tidy | 2 - Biz/Ide/tidy.bash | 2 + Biz/Ide/tips | 13 ------ Biz/Ide/tips.bash | 13 ++++++ Biz/Ide/version | 15 ------- Biz/Ide/version.bash | 15 +++++++ 32 files changed, 368 insertions(+), 368 deletions(-) delete mode 100755 Biz/Ide/ftags create mode 100755 Biz/Ide/ftags.bash delete mode 100755 Biz/Ide/hoog create mode 100755 Biz/Ide/hoog.bash delete mode 100755 Biz/Ide/hooks/commit-msg create mode 100755 Biz/Ide/hooks/commit-msg.bash delete mode 100755 Biz/Ide/hooks/post-checkout create mode 100755 Biz/Ide/hooks/post-checkout.bash delete mode 100755 Biz/Ide/hooks/post-merge create mode 100755 Biz/Ide/hooks/post-merge.bash delete mode 100755 Biz/Ide/hooks/pre-commit create mode 100755 Biz/Ide/hooks/pre-commit.bash delete mode 100755 Biz/Ide/hooks/pre-push create mode 100755 Biz/Ide/hooks/pre-push.bash delete mode 100755 Biz/Ide/mktags create mode 100755 Biz/Ide/mktags.bash delete mode 100755 Biz/Ide/ns create mode 100755 Biz/Ide/ns.bash delete mode 100755 Biz/Ide/push create mode 100755 Biz/Ide/push.bash delete mode 100755 Biz/Ide/repl create mode 100755 Biz/Ide/repl.bash delete mode 100755 Biz/Ide/run create mode 100755 Biz/Ide/run.bash delete mode 100755 Biz/Ide/ship create mode 100755 Biz/Ide/ship.bash delete mode 100755 Biz/Ide/tidy create mode 100755 Biz/Ide/tidy.bash delete mode 100755 Biz/Ide/tips create mode 100755 Biz/Ide/tips.bash delete mode 100755 Biz/Ide/version create mode 100755 Biz/Ide/version.bash (limited to 'Biz/Ide') diff --git a/Biz/Ide/ftags b/Biz/Ide/ftags deleted file mode 100755 index 02d78c5..0000000 --- a/Biz/Ide/ftags +++ /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.bash b/Biz/Ide/ftags.bash new file mode 100755 index 0000000..02d78c5 --- /dev/null +++ b/Biz/Ide/ftags.bash @@ -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 b/Biz/Ide/hoog deleted file mode 100755 index 976f0d4..0000000 --- a/Biz/Ide/hoog +++ /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.bash b/Biz/Ide/hoog.bash new file mode 100755 index 0000000..976f0d4 --- /dev/null +++ b/Biz/Ide/hoog.bash @@ -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 b/Biz/Ide/hooks/commit-msg deleted file mode 100755 index 64e400d..0000000 --- a/Biz/Ide/hooks/commit-msg +++ /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.bash b/Biz/Ide/hooks/commit-msg.bash new file mode 100755 index 0000000..64e400d --- /dev/null +++ b/Biz/Ide/hooks/commit-msg.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +gitlint --ignore-stdin --staged --msg-filename "$1" run-hook diff --git a/Biz/Ide/hooks/post-checkout b/Biz/Ide/hooks/post-checkout deleted file mode 100755 index 73488b0..0000000 --- a/Biz/Ide/hooks/post-checkout +++ /dev/null @@ -1,15 +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 diff --git a/Biz/Ide/hooks/post-checkout.bash b/Biz/Ide/hooks/post-checkout.bash new file mode 100755 index 0000000..73488b0 --- /dev/null +++ b/Biz/Ide/hooks/post-checkout.bash @@ -0,0 +1,15 @@ +#!/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 diff --git a/Biz/Ide/hooks/post-merge b/Biz/Ide/hooks/post-merge deleted file mode 100755 index c21211f..0000000 --- a/Biz/Ide/hooks/post-merge +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/post-merge.bash b/Biz/Ide/hooks/post-merge.bash new file mode 100755 index 0000000..c21211f --- /dev/null +++ b/Biz/Ide/hooks/post-merge.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +exec ${CODEROOT:?}/Biz/Ide/hooks/post-checkout 'HEAD@{1}' HEAD diff --git a/Biz/Ide/hooks/pre-commit b/Biz/Ide/hooks/pre-commit deleted file mode 100755 index 2b4575c..0000000 --- a/Biz/Ide/hooks/pre-commit +++ /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 == -1 )); then - echo "info: version: $ns: deleted" - elif (( $version < 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.bash b/Biz/Ide/hooks/pre-commit.bash new file mode 100755 index 0000000..2b4575c --- /dev/null +++ b/Biz/Ide/hooks/pre-commit.bash @@ -0,0 +1,21 @@ +#!/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 == -1 )); then + echo "info: version: $ns: deleted" + elif (( $version < 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 b/Biz/Ide/hooks/pre-push deleted file mode 100755 index 0c313cb..0000000 --- a/Biz/Ide/hooks/pre-push +++ /dev/null @@ -1,58 +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. -# -## - 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) -## - while read local_ref local_sha remote_ref remote_sha - do - if [[ $local_ref =~ notes ]]; then - exit 0 - fi - commit=$(git notes --ref=ci show $local_ref || 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 --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" - done -## diff --git a/Biz/Ide/hooks/pre-push.bash b/Biz/Ide/hooks/pre-push.bash new file mode 100755 index 0000000..0c313cb --- /dev/null +++ b/Biz/Ide/hooks/pre-push.bash @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# a simple ci that saves its results in a git note, formatted according to +# RFC-2822, more or less. +# +## + 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) +## + while read local_ref local_sha remote_ref remote_sha + do + if [[ $local_ref =~ notes ]]; then + exit 0 + fi + commit=$(git notes --ref=ci show $local_ref || 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 --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" + done +## diff --git a/Biz/Ide/mktags b/Biz/Ide/mktags deleted file mode 100755 index c83f319..0000000 --- a/Biz/Ide/mktags +++ /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.bash b/Biz/Ide/mktags.bash new file mode 100755 index 0000000..c83f319 --- /dev/null +++ b/Biz/Ide/mktags.bash @@ -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 "${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/ns b/Biz/Ide/ns deleted file mode 100755 index e988bfe..0000000 --- a/Biz/Ide/ns +++ /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.bash b/Biz/Ide/ns.bash new file mode 100755 index 0000000..e988bfe --- /dev/null +++ b/Biz/Ide/ns.bash @@ -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 b/Biz/Ide/push deleted file mode 100755 index 2238e06..0000000 --- a/Biz/Ide/push +++ /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.bash b/Biz/Ide/push.bash new file mode 100755 index 0000000..2238e06 --- /dev/null +++ b/Biz/Ide/push.bash @@ -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=$(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/repl b/Biz/Ide/repl deleted file mode 100755 index b10f0f0..0000000 --- a/Biz/Ide/repl +++ /dev/null @@ -1,87 +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 --json ${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.bash b/Biz/Ide/repl.bash new file mode 100755 index 0000000..b10f0f0 --- /dev/null +++ b/Biz/Ide/repl.bash @@ -0,0 +1,87 @@ +#!/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 --json ${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/run b/Biz/Ide/run deleted file mode 100755 index f7b9d36..0000000 --- a/Biz/Ide/run +++ /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.bash b/Biz/Ide/run.bash new file mode 100755 index 0000000..f7b9d36 --- /dev/null +++ b/Biz/Ide/run.bash @@ -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 b/Biz/Ide/ship deleted file mode 100755 index 33197c8..0000000 --- a/Biz/Ide/ship +++ /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.bash b/Biz/Ide/ship.bash new file mode 100755 index 0000000..33197c8 --- /dev/null +++ b/Biz/Ide/ship.bash @@ -0,0 +1,23 @@ +#!/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/tidy b/Biz/Ide/tidy deleted file mode 100755 index ec666ba..0000000 --- a/Biz/Ide/tidy +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -rm -f $CODEROOT/_/bin/* diff --git a/Biz/Ide/tidy.bash b/Biz/Ide/tidy.bash new file mode 100755 index 0000000..ec666ba --- /dev/null +++ b/Biz/Ide/tidy.bash @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +rm -f $CODEROOT/_/bin/* diff --git a/Biz/Ide/tips b/Biz/Ide/tips deleted file mode 100755 index 21808eb..0000000 --- a/Biz/Ide/tips +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -echo "" -echo "bizdev" | figlet | lolcat -echo "" -echo " bild compile code" -echo " repl start a repl" -echo " deps manage dependencies with niv" -echo " tips show this message" -echo " lint auto-lint all changed files" -echo " push send a namespace to the cloud" -echo " ship lint, bild, and push one (or all) namespace(s)" -echo " tidy cleanup common working files" -echo "" diff --git a/Biz/Ide/tips.bash b/Biz/Ide/tips.bash new file mode 100755 index 0000000..ba458ac --- /dev/null +++ b/Biz/Ide/tips.bash @@ -0,0 +1,13 @@ +#!/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/version b/Biz/Ide/version deleted file mode 100755 index 5b017d9..0000000 --- a/Biz/Ide/version +++ /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.bash b/Biz/Ide/version.bash new file mode 100755 index 0000000..5b017d9 --- /dev/null +++ b/Biz/Ide/version.bash @@ -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