Add function for saving envs

This commit is contained in:
2026-03-21 17:10:09 +00:00
parent fd0ccc015b
commit 22a684c1a6

View File

@@ -263,3 +263,30 @@ gd() {
fi
fi
}
linkenv() {
local env="$1:-dev"
local env_files_directory="$HOME/Tower/.backup/Development/Environments"
# Fetch the closest git parent or current directory if not
local root_dir=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
local project_name=$(basename "$root_dir")
local source_file="$env_files_directory/${project_name}-${env}-env"
local target_file="$root_dir/.env"
if [[ -f "$source_file" ]]; then
ln -sf "$source_file" "$target_file"
echo "Linked $source_file -> $target_file"
else
echo "No environment file found for $project_name at $source_file copying example, copying example if exists"
if [[ -f "$root_dir/.env.example" ]]; then
cp "$root_dir/.env.example" "$source_file"
ln -sf "$source_file" "$target_file"
echo "Copied .env.example to $source_file and linked"
else
echo "No .env.example found."
fi
fi
}