Add hr switch

This commit is contained in:
Sage 2026-01-21 14:10:08 +00:00
parent 169a75db16
commit 181ad4416a
2 changed files with 67 additions and 17 deletions

View file

@ -11,11 +11,10 @@ in {
options.mods.terminal.hr.enable = lib.mkEnableOption "Hefring (Work Tooling)";
config = lib.mkIf cfg.hr.enable {
home.packages = [hr];
programs.zsh.initExtra = builtins.readFile ./hr.sh;
systemd.user.services = {
google-db-proxy-test = {
enable = true;
Unit = {
Description = "Google Cloud SQL Proxy (Test)";
After = ["network.target"];
@ -30,7 +29,6 @@ in {
};
google-db-proxy-prod = {
enable = true;
Unit = {
Description = "Google Cloud SQL Proxy (Prod)";
After = ["network.target"];

View file

@ -1,8 +1,17 @@
#!/usr/bin/env bash
# Set default PROJECT_ID if not already set
if [[ -z "$PROJECT_ID" ]]; then
export PROJECT_ID="mk2-test"
fi
set -e
_hr_usage() {
echo "Usage: hr <command>"
echo "Commands:"
echo " switch Switch PROJECT_ID between mk2-test and mk2-prod"
echo " init py Initialize a python devenv environment (git-ignored)"
echo " freeze Freeze dependencies to requirements.txt"
}
if [ "$1" = "init" ] && [ "$2" = "py" ]; then
_hr_init_py() {
echo "Initializing python devenv..."
# 1. Init devenv
@ -15,7 +24,7 @@ if [ "$1" = "init" ] && [ "$2" = "py" ]; then
echo "Direnv allowed"
else
echo "Error: devenv not found in path."
exit 1
return 1
fi
if [ -f .gitignore.bak ]; then
@ -91,11 +100,12 @@ EOF
echo "Direnv allowed"
else
echo "Error: direnv not found in path."
exit 1
return 1
fi
}
elif [ "$1" = "freeze" ]; then
extra_index_url="https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/"
_hr_freeze() {
local extra_index_url="https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/"
# Install the auth plugin and keyring CLI
uv pip install keyrings.google-artifactregistry-auth==1.1.2 keyring
@ -106,11 +116,53 @@ elif [ "$1" = "freeze" ]; then
# Generate requirements.txt
echo "--extra-index-url ${extra_index_url}" > requirements.txt
uv pip freeze --exclude-editable >> requirements.txt
}
else
echo "Usage: hr <command>"
echo "Commands:"
echo " init py Initialize a python devenv environment (git-ignored)"
echo " freeze Freeze dependencies to requirements.txt"
exit 1
fi
hr() {
if [[ $# -eq 0 ]]; then
_hr_usage
return 1
fi
local command="$1"
shift
if [[ "$command" == "switch" ]]; then
if [[ -z "$1" ]]; then
# Toggle between test and prod
if [[ "$PROJECT_ID" == "mk2-test" ]]; then
export PROJECT_ID="mk2-prod"
echo "Switched PROJECT_ID to mk2-prod"
else
export PROJECT_ID="mk2-test"
echo "Switched PROJECT_ID to mk2-test"
fi
elif [[ "$1" == "test" ]]; then
export PROJECT_ID="mk2-test"
echo "Set PROJECT_ID to mk2-test"
elif [[ "$1" == "prod" ]]; then
export PROJECT_ID="mk2-prod"
echo "Set PROJECT_ID to mk2-prod"
else
echo "Usage: hr switch [test|prod]"
return 1
fi
return 0
fi
# Run original logic in a subshell to preserve set -e behavior without affecting current shell
(
set -e
# Restore arguments for processing
set -- "$command" "$@"
if [ "$1" = "init" ] && [ "$2" = "py" ]; then
_hr_init_py
elif [ "$1" = "freeze" ]; then
_hr_freeze
else
_hr_usage
exit 1
fi
)
}