2026-05-03 03:15:01 +02:00

73 lines
2.5 KiB
Bash
Executable File

NEM_SCRIPT_DIR="$HOME/.local/share/nem"
nem(){
LOGLEVEL=${LOGLVL:-2}
FORCE="false"
enter_nix_shell="true"
NEM_TEMP_FILE="/tmp/nem_temp_file"
KEEP_OPEN="false"
for arg in "$@"; do
case "$arg" in
open)
bash $NEM_SCRIPT_DIR/nem_mgr.sh "open_environment" "$2" "$FORCE" "$LOGLEVEL" 3> "$NEM_TEMP_FILE"
nix_shell_file=$(cat "$NEM_TEMP_FILE")
if [[ -n "$nix_shell_file" && "$enter_nix_shell" == "true" ]]; then
extra_params=()
nix_params_file="$NEM_SCRIPT_DIR/environments/$2/nix-shell-parameters"
# echo "Using nix shell file: $nix_shell_file"
if [[ -f "$nix_params_file" ]]; then
# Read parameters into an array safely
extra_params=("${(@f)$(<"$nix_params_file")}")
echo "Using nix parameters: $extra_params"
fi
nix-shell "${extra_params[@]}" "$nix_shell_file"
if [[ "$KEEP_OPEN" == "true" ]]; then
echo "Template enviorment stays open."
else
nem "close" "$2" "$FORCE" "$LOGLEVEL"
fi
fi
rm -f "$NEM_TEMP_FILE"
break
;;
close)
bash $NEM_SCRIPT_DIR/nem_mgr.sh "cleanup_structure" "$2" "$FORCE" "$LOGLEVEL"
break
;;
-q| --quiet)
LOGLEVEL=1
shift
;;
-k| --keep-open)
KEEP_OPEN="true"
shift
;;
-n | --no-shell)
enter_nix_shell="false"
shift
;;
-qq| --quiet-quiet)
LOGLEVEL=0
shift
;;
-f| --force)
FORCE="true"
shift
;;
-h| --help | *)
echo "Usage: $0 [options] {open|close} <env_name>"
echo " open: Open the environment and enter nix shell."
echo " close: Clean up the environment."
echo "Options:"
echo " -f, --force: Force cleanup of unchanged files."
echo " -n, --no-shell: Do not enter nix shell after opening."
echo " -k, --keep-open: Keep enviorment directory after exiting nix shell."
break
;;
esac
done
}