more opaque foot, fix branch, add del by name

This commit is contained in:
RingOfStorms (Joshua Bell) 2025-09-15 12:22:11 -05:00
parent 349e8058b1
commit 0c36d6af65
4 changed files with 98 additions and 33 deletions

View file

@ -8,7 +8,7 @@
}; };
alpha = lib.mkOption { alpha = lib.mkOption {
type = lib.types.float; type = lib.types.float;
default = 0.9; default = 0.935;
description = "Background opacity for Foot terminal (1.0 = opaque)"; description = "Background opacity for Foot terminal (1.0 = opaque)";
}; };
}; };

View file

@ -76,9 +76,17 @@ branch() {
git -C "$repo_dir" fetch --all --prune || true git -C "$repo_dir" fetch --all --prune || true
local wt_root wt_path local wt_root wt_path
if [ -z "$xdg" ]; then
xdg="${XDG_DATA_HOME:-$HOME/.local/share}"
fi
wt_root="$xdg/git_worktrees/${repo_base}_${repo_hash}" wt_root="$xdg/git_worktrees/${repo_base}_${repo_hash}"
wt_path="$wt_root/$branch_name" wt_path="$wt_root/$branch_name"
# ensure worktree root exists
if [ ! -d "$wt_root" ]; then
mkdir -p "$wt_root" || { echo "Failed to create worktree root: $wt_root" >&2; return 1; }
fi
# If worktree already exists at our expected path, open a shell there # If worktree already exists at our expected path, open a shell there
if [ -d "$wt_path" ]; then if [ -d "$wt_path" ]; then
echo "Opening existing worktree at '$wt_path'." echo "Opening existing worktree at '$wt_path'."
@ -86,11 +94,23 @@ branch() {
return 0 return 0
fi fi
local branch_exists branch_from local branch_exists branch_from local_exists
branch_exists=$(git -C "$repo_dir" ls-remote --heads origin "$branch_name" | wc -l) branch_exists=$(git -C "$repo_dir" ls-remote --heads origin "$branch_name" | wc -l)
# check if a local branch exists
if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch_name"; then
local_exists=1
else
local_exists=0
fi
branch_from="$default_branch" branch_from="$default_branch"
if [ "$branch_exists" -eq 0 ]; then if [ "$branch_exists" -eq 0 ]; then
if [ "$local_exists" -eq 1 ]; then
branch_from="$branch_name"
echo "Branch '$branch_name' exists locally; creating worktree from local branch."
else
echo "Branch '$branch_name' does not exist on remote; creating from '$branch_from'." echo "Branch '$branch_name' does not exist on remote; creating from '$branch_from'."
fi
else else
branch_from="origin/$branch_name" branch_from="origin/$branch_name"
echo "Branch '$branch_name' exists on remote; creating worktree tracking it." echo "Branch '$branch_name' exists on remote; creating worktree tracking it."
@ -99,10 +119,17 @@ branch() {
echo "Creating new worktree for branch '$branch_name' at '$wt_path'." echo "Creating new worktree for branch '$branch_name' at '$wt_path'."
# Try to add or update worktree from the resolved ref. Use a fallback path if needed. # Try to add or update worktree from the resolved ref. Use a fallback path if needed.
if [ "$local_exists" -eq 1 ]; then
if git -C "$repo_dir" worktree add "$wt_path" "$branch_name" 2>/dev/null; then
cd "$wt_path" || return 1
return 0
fi
else
if git -C "$repo_dir" worktree add -b "$branch_name" "$wt_path" "$branch_from" 2>/dev/null; then if git -C "$repo_dir" worktree add -b "$branch_name" "$wt_path" "$branch_from" 2>/dev/null; then
cd "$wt_path" || return 1 cd "$wt_path" || return 1
return 0 return 0
fi fi
fi
# Fallback: try to resolve a concrete SHA and create the branch ref locally, then add worktree # Fallback: try to resolve a concrete SHA and create the branch ref locally, then add worktree
local start_sha local start_sha

View file

@ -1,5 +1,7 @@
branchdel() { branchdel() {
# branchd — remove current branch worktree (function form) # branchdel — remove a branch worktree (optional branch arg)
local branch_arg
branch_arg="$1"
local wt_path local wt_path
wt_path=$(pwd) wt_path=$(pwd)
local common_dir repo_dir local common_dir repo_dir
@ -16,40 +18,76 @@ branchdel() {
return 1 return 1
fi fi
if [ "$repo_dir" = "$wt_path" ]; then # determine current branch in this worktree
echo "Inside the root directory of repo, will not delete." >&2 local current default_branch branch target_wt
return 1
fi
local current default_branch
current=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || { echo "Not inside a git repository." >&2; return 1; } current=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || { echo "Not inside a git repository." >&2; return 1; }
default_branch=$(getdefault) default_branch=$(getdefault)
if [ "$current" = "$default_branch" ] || [ "$current" = "default" ]; then # choose branch: provided arg or current
echo "Already on default branch ($default_branch). Won't remove." if [ -z "$branch_arg" ]; then
return 0 branch="$current"
else
branch="$branch_arg"
fi
# normalize branch name if refs/heads/ was provided
branch="${branch#refs/heads/}"
# don't remove default
if [ "$branch" = "$default_branch" ] || [ "$branch" = "default" ]; then
echo "Refusing to remove default branch worktree ($default_branch)." >&2
return 1
fi fi
echo "Switching to default branch '$default_branch'..." # find the worktree path for the requested branch
# Use branch function if available, otherwise checkout directly in repo target_wt=$(git -C "$repo_dir" worktree list --porcelain 2>/dev/null | awk -v b="refs/heads/$branch" '
$1=="worktree" { w=$2 }
$1=="branch" && $2==b { print w; exit }
')
# if not found in worktree list, check main worktree branch
if [ -z "$target_wt" ]; then
local main_branch
main_branch=$(git -C "$repo_dir" rev-parse --abbrev-ref HEAD 2>/dev/null || true)
if [ "$main_branch" = "$branch" ]; then
target_wt="$repo_dir"
fi
fi
if [ -z "$target_wt" ]; then
echo "No worktree found for branch '$branch'." >&2
return 1
fi
if [ "$target_wt" = "$repo_dir" ]; then
echo "Branch '$branch' is the main worktree at '$repo_dir'. Will not delete main worktree." >&2
return 1
fi
# if we're currently in that branch/worktree, switch to default and cd to repo root first
if [ "$current" = "$branch" ]; then
echo "Currently on branch '$branch' in '$wt_path'. Switching to default branch '$default_branch' in main worktree..."
if declare -f branch >/dev/null 2>&1; then if declare -f branch >/dev/null 2>&1; then
branch default || { echo "Failed to switch to default branch" >&2; return 1; } branch default || { echo "Failed to switch to default branch" >&2; return 1; }
else else
git -C "$repo_dir" checkout "$default_branch" || { echo "Failed to checkout default branch" >&2; return 1; } git -C "$repo_dir" checkout "$default_branch" || { echo "Failed to checkout default branch" >&2; return 1; }
fi fi
cd "$repo_dir" || { echo "Failed to change directory to repo root: $repo_dir" >&2; return 1; }
fi
echo "Removing worktree at: $wt_path" echo "Removing worktree at: $target_wt"
if git -C "$repo_dir" worktree remove "$wt_path" 2>/dev/null; then if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null; then
echo "Removed worktree: $wt_path" rm -rf -- "$target_wt" 2>/dev/null || true
echo "Removed worktree: $target_wt"
return 0 return 0
fi fi
# try with --force as a fallback # try with --force as a fallback
if git -C "$repo_dir" worktree remove --force "$wt_path" 2>/dev/null; then if git -C "$repo_dir" worktree remove --force "$target_wt" 2>/dev/null; then
echo "Removed worktree (forced): $wt_path" rm -rf -- "$target_wt" 2>/dev/null || true
echo "Removed worktree (forced): $target_wt"
return 0 return 0
fi fi
echo "Failed to remove worktree: $wt_path" >&2 echo "Failed to remove worktree: $target_wt" >&2
return 1 return 1
} }

8
hosts/lio/flake.lock generated
View file

@ -1206,11 +1206,11 @@
"rust-overlay": "rust-overlay_2" "rust-overlay": "rust-overlay_2"
}, },
"locked": { "locked": {
"lastModified": 1757952613, "lastModified": 1757954114,
"narHash": "sha256-+oe+sRXenNMSP5O9ux0EF808JxoLbUneTV06/ILRPMA=", "narHash": "sha256-1Y6+uiLicKPARiiIjYY32asP9oKBW9z1LEBRYOR6ajI=",
"ref": "refs/heads/master", "ref": "refs/heads/master",
"rev": "4022513b5d59433b9ab0c273c384b664d6d17457", "rev": "f1487458ea787031e00230b604e652464fd44139",
"revCount": 302, "revCount": 303,
"type": "git", "type": "git",
"url": "https://git.joshuabell.xyz/ringofstorms/nvim" "url": "https://git.joshuabell.xyz/ringofstorms/nvim"
}, },