mirror of
https://codeberg.org/muon/home.git
synced 2026-03-08 03:25:16 +00:00
Add hr switch
This commit is contained in:
parent
169a75db16
commit
181ad4416a
2 changed files with 67 additions and 17 deletions
|
|
@ -11,11 +11,10 @@ in {
|
||||||
options.mods.terminal.hr.enable = lib.mkEnableOption "Hefring (Work Tooling)";
|
options.mods.terminal.hr.enable = lib.mkEnableOption "Hefring (Work Tooling)";
|
||||||
|
|
||||||
config = lib.mkIf cfg.hr.enable {
|
config = lib.mkIf cfg.hr.enable {
|
||||||
home.packages = [hr];
|
programs.zsh.initExtra = builtins.readFile ./hr.sh;
|
||||||
|
|
||||||
systemd.user.services = {
|
systemd.user.services = {
|
||||||
google-db-proxy-test = {
|
google-db-proxy-test = {
|
||||||
enable = true;
|
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Google Cloud SQL Proxy (Test)";
|
Description = "Google Cloud SQL Proxy (Test)";
|
||||||
After = ["network.target"];
|
After = ["network.target"];
|
||||||
|
|
@ -30,7 +29,6 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
google-db-proxy-prod = {
|
google-db-proxy-prod = {
|
||||||
enable = true;
|
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Google Cloud SQL Proxy (Prod)";
|
Description = "Google Cloud SQL Proxy (Prod)";
|
||||||
After = ["network.target"];
|
After = ["network.target"];
|
||||||
|
|
|
||||||
|
|
@ -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..."
|
echo "Initializing python devenv..."
|
||||||
|
|
||||||
# 1. Init devenv
|
# 1. Init devenv
|
||||||
|
|
@ -15,7 +24,7 @@ if [ "$1" = "init" ] && [ "$2" = "py" ]; then
|
||||||
echo "Direnv allowed"
|
echo "Direnv allowed"
|
||||||
else
|
else
|
||||||
echo "Error: devenv not found in path."
|
echo "Error: devenv not found in path."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f .gitignore.bak ]; then
|
if [ -f .gitignore.bak ]; then
|
||||||
|
|
@ -91,11 +100,12 @@ EOF
|
||||||
echo "Direnv allowed"
|
echo "Direnv allowed"
|
||||||
else
|
else
|
||||||
echo "Error: direnv not found in path."
|
echo "Error: direnv not found in path."
|
||||||
exit 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
elif [ "$1" = "freeze" ]; then
|
_hr_freeze() {
|
||||||
extra_index_url="https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/"
|
local extra_index_url="https://europe-west1-python.pkg.dev/mk2-prod/python-packages/simple/"
|
||||||
|
|
||||||
# Install the auth plugin and keyring CLI
|
# Install the auth plugin and keyring CLI
|
||||||
uv pip install keyrings.google-artifactregistry-auth==1.1.2 keyring
|
uv pip install keyrings.google-artifactregistry-auth==1.1.2 keyring
|
||||||
|
|
@ -106,11 +116,53 @@ elif [ "$1" = "freeze" ]; then
|
||||||
# Generate requirements.txt
|
# Generate requirements.txt
|
||||||
echo "--extra-index-url ${extra_index_url}" > requirements.txt
|
echo "--extra-index-url ${extra_index_url}" > requirements.txt
|
||||||
uv pip freeze --exclude-editable >> requirements.txt
|
uv pip freeze --exclude-editable >> requirements.txt
|
||||||
|
}
|
||||||
|
|
||||||
else
|
hr() {
|
||||||
echo "Usage: hr <command>"
|
if [[ $# -eq 0 ]]; then
|
||||||
echo "Commands:"
|
_hr_usage
|
||||||
echo " init py Initialize a python devenv environment (git-ignored)"
|
return 1
|
||||||
echo " freeze Freeze dependencies to requirements.txt"
|
fi
|
||||||
exit 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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue