set -e log() { printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}" } exitHook() { log "Stoppar brevekorren" pg_ctl stop --pgdata=./matabas-db } log "Letar efter existerande brevekorresmapp" [ -d ./matabas-db ] || { log "Finns ej, skapar brevekorresmapp (./matabas-db)" pg_ctl initdb --pgdata=./matabas-db } [ -f matabas-db/matabas.log ] && { log "Flyttar journalen från senaste sittningen till journalarkivet (./matabas-db/matabas.log.old)" cat matabas-db/matabas.log >> matabas-db/matabas.log.old rm -f matabas-db/matabas.log } log "Startar brevekorren" pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp" trap exitHook EXIT log "Skapar matabas" createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över" log "Försvensknar miljön" _cargo() { cuh="$1" shift case "$cuh" in kör|spring) cargo run "$@" ;; ny) cargo new "$@" ;; pröva) cargo test "$@" ;; bygg) cargo build "$@" ;; enna) cargo init "$@" ;; *) echo "vafan gö du" ;; esac } alias 'last=_cargo' alias cargo=exit log "Redo" "!" set +e