lätt till last

This commit is contained in:
xenia 2023-08-09 19:55:23 +02:00
parent 7f776f8053
commit b373aca070
2 changed files with 37 additions and 9 deletions

View File

@ -1,33 +1,61 @@
set -e
log() {
printf '\e[1m\e[38;5;87m==>\e[0m\e[1m %s.\e[0m\n' "$*"
printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}"
}
exitHook() {
log "Stopping postgres"
log "Stoppar brevekorren"
pg_ctl stop --pgdata=./matabas-db
}
log "Checking for existing postgres directory"
log "Letar efter existerande brevekorresmapp"
[ -d ./matabas-db ] || {
log "Non-existent, creating postgres directory (./matabas-db)"
log "Finns ej, skapar brevekorresmapp (./matabas-db)"
pg_ctl initdb --pgdata=./matabas-db
}
[ -f matabas-db/matabas.log ] && {
log "Moving logs from last session into log archive (./matabas-db/matabas.log.old)"
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 "Starting postgres"
log "Startar brevekorren"
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -k /tmp"
trap exitHook EXIT
log "Creating database"
log "Skapar matabas"
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Database already exists, not overwriting"
log "Environment ready!"
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

View File

@ -14,7 +14,7 @@
default = pkgs.hello;
};
devShells.default = pkgs.mkShell {
packages = [ packages.default pkgs.postgresql_15_jit ];
packages = [ packages.default pkgs.postgresql_15_jit pkgs.cargo ];
shellHook = builtins.readFile ./build/devShellHook.sh ;
};
}