From 99d05c541fd67b8e885e550d59e0869fdd7e3061 Mon Sep 17 00:00:00 2001 From: Sufien Tout Date: Wed, 18 Dec 2024 12:08:37 -0500 Subject: [PATCH] feat: add flag parsing for git worktree remove --- bin/git-forgit | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/git-forgit b/bin/git-forgit index bd62090a..0b0612ab 100755 --- a/bin/git-forgit +++ b/bin/git-forgit @@ -1093,12 +1093,30 @@ _forgit_git_worktree_remove() { _forgit_worktree_remove() { _forgit_inside_work_tree || _forgit_inside_git_dir || return 1 - if [[ $# -ne 0 ]]; then - git worktree remove "$@" + local worktree_list tree opts force_flags + + force_flags=() + + while (("$#")); do + case "$1" in + -f | --force) + force_flags+=("$1") + shift + ;; + -*) shift ;; + *) + tree="$1" + shift + ;; + esac + done + + if [[ -n "$tree" ]]; then + _forgit_git_worktree_remove "${force_flags[@]}" "$tree" worktree_remove_status=$? return $worktree_remove_status fi - local worktree_list tree opts + worktree_list=$(git worktree list | grep -v "(bare)") count=$(echo "$worktree_list" | wc -l) @@ -1113,7 +1131,7 @@ _forgit_worktree_remove() { tree=$(echo "$worktree_list" | awk '{print $1}' | FZF_DEFAULT_OPTS="$opts" fzf) [[ -z "$tree" ]] && return 1 - _forgit_git_worktree_remove "$tree" + _forgit_git_worktree_remove "${force_flags[@]}" "$tree" } _forgit_worktree_unlock() {