From b363f169ce7c1aa0fe0de90f24d93bb2c525b676 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Sun, 14 Sep 2025 19:57:37 -0500 Subject: [PATCH] new git branching strategy and linking --- common/_home_manager/mods/direnv.nix | 1 + common/_home_manager/mods/ssh.nix | 14 ++++---- common/general/shell/branch.func.sh | 41 +++++++++++++++++------ common/general/shell/link_ignored.func.sh | 23 ++++++++----- 4 files changed, 55 insertions(+), 24 deletions(-) diff --git a/common/_home_manager/mods/direnv.nix b/common/_home_manager/mods/direnv.nix index 78fc543..b36ce49 100644 --- a/common/_home_manager/mods/direnv.nix +++ b/common/_home_manager/mods/direnv.nix @@ -15,6 +15,7 @@ prefix = [ "~/projects" "~/.config" + "~/.local/share/git_worktrees/" ]; }; }; diff --git a/common/_home_manager/mods/ssh.nix b/common/_home_manager/mods/ssh.nix index 4100945..50c4e68 100644 --- a/common/_home_manager/mods/ssh.nix +++ b/common/_home_manager/mods/ssh.nix @@ -62,11 +62,6 @@ in identityFile = age.secrets.nix2t.path; user = "joshua.bell"; localForwards = [ - # { - # bind.port = 3000; - # host.port = 3000; - # host.address = "localhost"; - # } { bind.port = 3002; host.port = 3002; @@ -79,8 +74,15 @@ in }; "t_" = lib.mkIf (hasSecret "nix2t") { identityFile = age.secrets.nix2t.path; - hostname = "10.12.14.103"; + hostname = "10.12.14.181"; user = "joshua.bell"; + localForwards = [ + { + bind.port = 3002; + host.port = 3002; + host.address = "localhost"; + } + ]; setEnv = { TERM = "vt100"; }; diff --git a/common/general/shell/branch.func.sh b/common/general/shell/branch.func.sh index 550a950..ae911d8 100644 --- a/common/general/shell/branch.func.sh +++ b/common/general/shell/branch.func.sh @@ -1,16 +1,7 @@ branch() { local branch_name=${1:-} - if [ -z "$branch_name" ]; then - echo "Usage: branch " >&2 - return 2 - fi - - # branch — create or open a worktree for - # This function will change directory into the selected worktree so the - # caller's shell is moved into it. - - local xdg=${XDG_DATA_HOME:-$HOME/.local/share} + # Determine repo root early so we can run branches inside it local common_dir if ! common_dir=$(git rev-parse --git-common-dir 2>/dev/null); then echo "Not inside a git repository." >&2 @@ -25,6 +16,36 @@ branch() { return 1 fi + # If no branch was provided, present an interactive selector combining local and remote branches + if [ -z "$branch_name" ]; then + if ! command -v fzf >/dev/null 2>&1; then + echo "Usage: branch " >&2 + return 2 + fi + + local branches_list_raw branches_list selection + if declare -f local_branches >/dev/null 2>&1; then + branches_list_raw=$(local_branches 2>/dev/null || true; remote_branches 2>/dev/null || true) + else + branches_list_raw=$(git -C "$repo_dir" branch --format='%(refname:short)' 2>/dev/null || true; git -C "$repo_dir" branch -r --format='%(refname:short)' 2>/dev/null | sed 's#^.*/##' || true) + fi + + branches_list=$(printf "%s +" "$branches_list_raw" | awk '!seen[$0]++') + if [ -z "$branches_list" ]; then + echo "No branches found." >&2 + return 1 + fi + + selection=$(printf "%s\n" "$branches_list" | fzf --height=40% --prompt="Select branch: ") + if [ -z "$selection" ]; then + echo "No branch selected." >&2 + return 1 + fi + + branch_name="$selection" + fi + local repo_base repo_hash default_branch repo_base=$(basename "$repo_dir") repo_hash=$(printf "%s" "$repo_dir" | sha1sum | awk '{print $1}') diff --git a/common/general/shell/link_ignored.func.sh b/common/general/shell/link_ignored.func.sh index fdc6848..0043ed9 100644 --- a/common/general/shell/link_ignored.func.sh +++ b/common/general/shell/link_ignored.func.sh @@ -38,24 +38,26 @@ EOF return 2 fi - local -a candidates - IFS=$'\0' read -r -d '' -a candidates < <(git -C "$repo_root" ls-files --others --ignored --exclude-standard -z || true) + local -a candidates=() + while IFS= read -r -d '' file; do + candidates+=("$file") + done < <(git -C "$repo_root" ls-files --others --ignored --exclude-standard -z || true) if [ ${#candidates[@]} -eq 0 ]; then echo "No untracked/ignored files found in $repo_root" return 0 fi - declare -A _seen local -a tops=() for c in "${candidates[@]}"; do c="${c%/}" local top="${c%%/*}" [ -z "$top" ] && continue - if [ -z "${_seen[$top]:-}" ]; then - _seen[$top]=1 - tops+=("$top") - fi + local found=0 + for existing in "${tops[@]}"; do + [ "$existing" = "$top" ] && found=1 && break + done + [ "$found" -eq 0 ] && tops+=("$top") done if [ ${#tops[@]} -eq 0 ]; then @@ -89,7 +91,12 @@ EOF if [ -z "$selected" ]; then echo "No files selected." && return 0 fi - IFS=$'\n' read -r -d '' -a chosen < <(printf "%s\n" "$selected" && printf '\0') + chosen=() + while IFS= read -r line; do + chosen+=("$line") + done <