From 22a684c1a6533bdbea8a6aa3ab5f1ffa5d249bc9 Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 21 Mar 2026 17:10:09 +0000 Subject: [PATCH] Add function for saving envs --- .config/shell/fns | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.config/shell/fns b/.config/shell/fns index baa50b3..0381955 100755 --- a/.config/shell/fns +++ b/.config/shell/fns @@ -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 +}