diff --git a/common/_home_manager/mods/git.nix b/common/_home_manager/mods/git.nix index c36e784..34e6d18 100644 --- a/common/_home_manager/mods/git.nix +++ b/common/_home_manager/mods/git.nix @@ -7,8 +7,8 @@ userName = "RingOfStorms (Joshua Bell)"; extraConfig = { - core.pager = "cat"; - core.editor = "nvim"; + core.pager = "bat"; + core.editor = "nano"; pull.rebase = false; diff --git a/common/general/shell/branchd.func.sh b/common/general/shell/branchd.func.sh index 053d16f..a7769d2 100644 --- a/common/general/shell/branchd.func.sh +++ b/common/general/shell/branchd.func.sh @@ -76,20 +76,48 @@ branchdel() { fi echo "Removing worktree at: $target_wt" - if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null; then - rm -rf -- "$target_wt" 2>/dev/null || true - echo "Removed worktree: $target_wt" - # delete local branch if it exists - if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then - git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true - echo "Deleted local branch: $branch" + # helper: attempt a guarded, forceful removal of a directory + remove_dir_forcefully() { + local dir="$1" + if [ -z "$dir" ]; then + return 1 fi - return 0 - fi - # try with --force as a fallback - if git -C "$repo_dir" worktree remove --force "$target_wt" 2>/dev/null; then - rm -rf -- "$target_wt" 2>/dev/null || true - echo "Removed worktree (forced): $target_wt" + # resolve absolute paths + local abs_dir abs_repo + abs_dir=$(readlink -f -- "$dir" 2>/dev/null) || abs_dir="$dir" + abs_repo=$(readlink -f -- "$repo_dir" 2>/dev/null) || abs_repo="$repo_dir" + + # safety checks: do not remove repository root or / + if [ "$abs_dir" = "/" ] || [ "$abs_dir" = "$abs_repo" ]; then + echo "Refusing to remove unsafe path: $abs_dir" >&2 + return 1 + fi + + # try plain rm -rf + rm -rf -- "$abs_dir" 2>/dev/null && return 0 + + # fix permissions then try again + chmod -R u+rwx "$abs_dir" 2>/dev/null || true + rm -rf -- "$abs_dir" 2>/dev/null && return 0 + + # try removing contents first, then remove directory + if find "$abs_dir" -mindepth 1 -exec rm -rf -- {} + 2>/dev/null; then + rmdir "$abs_dir" 2>/dev/null || true + fi + + # final existence check + [ ! -e "$abs_dir" ] + } + + # try unregistering the worktree, prefer normal then fallback to --force + if git -C "$repo_dir" worktree remove "$target_wt" 2>/dev/null || git -C "$repo_dir" worktree remove --force "$target_wt" 2>/dev/null; then + if remove_dir_forcefully "$target_wt"; then + echo "Removed worktree: $target_wt" + else + echo "Worktree removed from git, but failed to fully delete directory: $target_wt" >&2 + echo "Attempted to force-delete; you may need to remove it manually with sudo." >&2 + fi + # delete local branch if it exists if git -C "$repo_dir" show-ref --verify --quiet "refs/heads/$branch"; then git -C "$repo_dir" branch -D "$branch" 2>/dev/null || true diff --git a/common/general/shell/common.nix b/common/general/shell/common.nix index 9660761..c7bd3df 100644 --- a/common/general/shell/common.nix +++ b/common/general/shell/common.nix @@ -53,6 +53,9 @@ with lib; gcm = "git commit -m"; stashes = "git stash list"; bd = "branch default"; + li = "link_ignored"; + bx = "branchdel"; + b = "branch"; # ripgrep rg = "rg --no-ignore";