Added devenv and moved config files

This commit is contained in:
marc
2022-11-25 20:16:46 +01:00
parent ebbbd0d179
commit 69e1dc2eb4
38 changed files with 184 additions and 11 deletions

88
data/devenv/devenv.sh Normal file
View File

@@ -0,0 +1,88 @@
#!/usr/bin/env sh
SANDBOXES_DIR=$HOME/sandbox
TEMPLATES_DIR=$XDG_DATA_HOME/devenv/templates
list_templates() {
echo "The available templates are:"
ls $TEMPLATES_DIR
}
check_template () {
TEMPLATE=$1
if [ -z "$TEMPLATE" ]; then
echo "No template given"
list_templates
exit 1
elif [ ! -e "$TEMPLATES_DIR/$TEMPLATE" ]; then
echo "The given template '$TEMPLATE' doesn't exist!"
list_templates
exit 1
fi
}
devenv_install() {
install -m 644 $TEMPLATES_DIR/$TEMPLATE/* ./
echo "use flake . --impure" > .envrc
direnv allow
}
devenv_init() {
TEMPLATE=$1
check_template $TEMPLATE
devenv_install
}
devenv_sandbox() {
DIRECTORY=$1
if [ -z "$DIRECTORY" ]; then
show_help_sandbox
exit 1
fi
SANDBOX_DIR="$SANDBOXES_DIR/$DIRECTORY"
TEMPLATE=$2
if [ -z "$TEMPLATE" ]; then
TEMPLATE=$DIRECTORY
fi
check_template $TEMPLATE
if [ ! -e $SANDBOX_DIR ]; then
echo "Creating sandbox at $SANDBOX_DIR with template $TEMPLATE"
mkdir -p $SANDBOX_DIR
cd $SANDBOX_DIR
devenv_init $TEMPLATE
else
cd $SANDBOX_DIR
fi
}
show_help_sandbox() {
echo "Usage: devenv sandbox <directory> [<template>]"
echo ""
echo " directory: The sandbox directory to go to."
echo " template: If the directory doesn't exist, the template to use for that sandbox"
echo " Defaults to directory if not given."
echo ""
}
show_help() {
echo "Usage: devenv <action>"
echo "Available actions:"
echo ""
echo " init: Initialize a dev env in the current directory"
echo " sandbox: Go to a sandbox directory using a template"
echo ""
}
case "$1" in
init)
shift
devenv_init $@
;;
sandbox)
shift
devenv_sandbox $@
;;
*)
show_help
;;
esac