Add function for saving envs
This commit is contained in:
@@ -228,7 +228,7 @@ img2png() {
|
||||
}
|
||||
|
||||
# Create a new worktree and branch from within current git directory.
|
||||
ga() {
|
||||
gwa() {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Usage: ga [branch name]"
|
||||
return 1
|
||||
@@ -244,7 +244,7 @@ ga() {
|
||||
}
|
||||
|
||||
# Remove worktree and branch from within active worktree directory.
|
||||
gd() {
|
||||
gwd() {
|
||||
if gum confirm "Remove worktree and branch?"; then
|
||||
local cwd base branch root
|
||||
|
||||
@@ -265,8 +265,8 @@ gd() {
|
||||
}
|
||||
|
||||
linkenv() {
|
||||
local env="$1:-dev"
|
||||
local env_files_directory="$HOME/Tower/.backup/Development/Environments"
|
||||
local env="${1:-dev}"
|
||||
local env_files_directory="$HOME/Tower/.backups/Development/Environments"
|
||||
|
||||
# Fetch the closest git parent or current directory if not
|
||||
local root_dir=$(git rev-parse --show-toplevel 2>/dev/null || pwd)
|
||||
@@ -275,6 +275,19 @@ linkenv() {
|
||||
local source_file="$env_files_directory/${project_name}-${env}-env"
|
||||
local target_file="$root_dir/.env"
|
||||
|
||||
if [[ -f "$target_file" ]]; then
|
||||
if gum confirm "Overwrite existing .env file?"; then
|
||||
if [[ -L "$target_file" ]]; then
|
||||
rm "$target_file"
|
||||
else
|
||||
mv "$target_file" "${target_file}.bak"
|
||||
echo "Existing .env backed up to .env.bak"
|
||||
fi
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -f "$source_file" ]]; then
|
||||
ln -sf "$source_file" "$target_file"
|
||||
echo "Linked $source_file -> $target_file"
|
||||
|
||||
Reference in New Issue
Block a user