summaryrefslogtreecommitdiff
path: root/Biz/Bild/ShellHook.sh
blob: b9add2938aea73eb1cf5bda7d4eab35333c655b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/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 "   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"
# configure git hooks
  git config --local core.hooksPath "$BIZ_ROOT/Biz/Ide/hooks"
#
  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
  }
# shellcheck disable=SC2154
  export PS1='\n$(r=$? && [ $r -eq 0 ] && printf "biz" || printf "%3.*s" $r $r)> '
#
  help
##