#!/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 [