1
0

feat: restructure dotfiles setup with bootstrap and setup scripts, enhance branch selection and backup processes

This commit is contained in:
2025-08-04 20:39:16 -05:00
parent f9ff648977
commit f824ca52d3
9 changed files with 493 additions and 75 deletions

View File

@@ -34,3 +34,49 @@ command_exists() {
is_interactive() {
[[ $- == *i* ]]
}
# Branch selection utilities
list_branches() {
local dotfiles_dir="$1"
cd "$dotfiles_dir"
# Get available branches (both local and remote)
local branches=()
while IFS= read -r branch; do
# Clean up branch names (remove origin/ prefix, etc.)
clean_branch=$(echo "$branch" | sed 's|^origin/||' | sed 's|^remotes/origin/||')
# Skip HEAD and duplicates
if [[ "$clean_branch" != "HEAD" ]] && [[ ! " ${branches[@]} " =~ " ${clean_branch} " ]]; then
branches+=("$clean_branch")
fi
done < <(git branch -a --format="%(refname:short)" | grep -v "HEAD")
# Sort and return branches
printf '%s\n' "${branches[@]}" | sort
}
switch_to_branch() {
local dotfiles_dir="$1"
local selected_branch="$2"
cd "$dotfiles_dir"
log_info "Switching to branch: $selected_branch"
if git show-ref --verify --quiet "refs/heads/$selected_branch"; then
# Local branch exists
git checkout "$selected_branch"
elif git show-ref --verify --quiet "refs/remotes/origin/$selected_branch"; then
# Remote branch exists, create local tracking branch
git checkout -b "$selected_branch" "origin/$selected_branch"
else
log_error "Branch $selected_branch not found"
return 1
fi
# Pull latest changes
log_info "Pulling latest changes..."
git pull --quiet || true
log_success "Switched to branch: $selected_branch"
}