From 9dcfb66c99909d1b51a76bdaf75ddbdb030fe270 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 14 Jun 2021 10:39:17 -0400 Subject: Move commands and add ns function --- .envrc | 2 ++ Biz/Bild/ShellHook.sh | 57 ++++----------------------------------------------- Biz/Ide/bild | 2 ++ Biz/Ide/lint | 2 ++ Biz/Ide/ns | 27 ++++++++++++++++++++++++ Biz/Ide/push | 19 +++++++++++++++++ Biz/Ide/ship | 18 ++++++++++++++++ 7 files changed, 74 insertions(+), 53 deletions(-) create mode 100755 Biz/Ide/bild create mode 100755 Biz/Ide/lint create mode 100755 Biz/Ide/ns create mode 100755 Biz/Ide/push create mode 100755 Biz/Ide/ship diff --git a/.envrc b/.envrc index f68e357..19be922 100644 --- a/.envrc +++ b/.envrc @@ -1,5 +1,7 @@ export BIZ_ROOT=$PWD +PATH_add $BIZ_ROOT/Biz/Ide + # for some reason I need this to get ':e' in ghci to load my vimrc export EDITOR=vim export GUILE_LOAD_PATH=$BIZ_ROOT diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh index c996dee..59786e4 100644 --- a/Biz/Bild/ShellHook.sh +++ b/Biz/Bild/ShellHook.sh @@ -14,10 +14,10 @@ function help() { } # color codes for use with printf -RED='\033[0;31m' -GRN='\033[0;32m' -YEL='\033[0;33m' -NC='\033[0m' # No Color +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" @@ -31,65 +31,16 @@ 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/Lint.py $BIZ_ROOT/.git/hooks/pre-commit -function bild() { - timeout 5m runghc Biz.Bild $@ -} - function deps() { niv --sources-file $BIZ_ROOT/Biz/Bild/Sources.json $@ } alias ghci="ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci" -function lint { - runghc Biz.Lint $@ -} - function pie() { runghc Biz.Pie $@ } -# TODO: 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 -function push() { - prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g") - if [[ "$prefix" == "" ]] - then - target="$1" - else - target="$prefix.$1" - fi - what=$(realpath "$BIZ_ROOT/_/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}" -} - -# TODO: convert to haskell -function ship() { - stuff=(${@}) - if [[ ${#stuff[@]} -eq 0 ]] - then - stuff=( - Biz/Cloud.nix - Biz/Dev.nix - Biz/Que/Prod.nix - # Hero/Prod.nix # disabled bc herocomcis.app domain is broken - ) - fi - lint \ - && bild --test ${stuff[@]} \ - && for thing in ${stuff[@]} - do - push $thing - done -} - function run-sentry() { urls=( http://que.run diff --git a/Biz/Ide/bild b/Biz/Ide/bild new file mode 100755 index 0000000..0dd4afb --- /dev/null +++ b/Biz/Ide/bild @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +timeout 5m runghc -i$BIZ_ROOT Biz.Bild $@ diff --git a/Biz/Ide/lint b/Biz/Ide/lint new file mode 100755 index 0000000..3f98dcb --- /dev/null +++ b/Biz/Ide/lint @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +runghc -i$BIZ_ROOT Biz.Lint $@ diff --git a/Biz/Ide/ns b/Biz/Ide/ns new file mode 100755 index 0000000..2791903 --- /dev/null +++ b/Biz/Ide/ns @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +if [[ $NS == "" ]] +then + export NS=$(fd --exclude=_ -t f . $BIZ_ROOT | fzf) +fi + +if [[ $VERB == "" ]] +then + export VERB=$(fzf <<< $(sed 's/ /\n/g' <<< "edit bild push ship lint")) +fi + +$VERB $NS + +read -p "n to change ns, v to change verb, enter to continue, or ^C to exit" -n 1 input + +if [[ $input == "v" ]] +then + unset VERB + $0 +elif [[ $input == "n" ]] +then + unset NS + $0 +else + $0 +fi diff --git a/Biz/Ide/push b/Biz/Ide/push new file mode 100755 index 0000000..a0109e8 --- /dev/null +++ b/Biz/Ide/push @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# TODO: 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|^$BIZ_ROOT/*||g") +if [[ "$prefix" == "" ]] +then + target="$1" +else + target="$prefix.$1" +fi +what=$(realpath "$BIZ_ROOT/_/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}" diff --git a/Biz/Ide/ship b/Biz/Ide/ship new file mode 100755 index 0000000..9a17d99 --- /dev/null +++ b/Biz/Ide/ship @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# TODO: convert to haskell +stuff=(${@}) +if [[ ${#stuff[@]} -eq 0 ]] +then + stuff=( + Biz/Cloud.nix + Biz/Dev.nix + Biz/Que/Prod.nix + # Hero/Prod.nix # disabled bc herocomcis.app domain is broken + ) +fi +lint \ + && bild --test ${stuff[@]} \ + && for thing in ${stuff[@]} + do + push $thing + done -- cgit v1.2.3