@@ -1003,24 +1003,31 @@ _forgit_ignore_clean() {
1003
1003
[[ -d " $FORGIT_GI_REPO_LOCAL " ]] && rm -rf " $FORGIT_GI_REPO_LOCAL "
1004
1004
}
1005
1005
1006
+ _forgit_filter_existing_paths () {
1007
+ while read -r path; do
1008
+ [[ -d " $path " ]] && echo " $path "
1009
+ done
1010
+ }
1011
+
1006
1012
_forgit_worktree_preview () {
1007
1013
local sha
1008
1014
# trailing space in grep to avoid matching worktrees with a common path
1009
1015
sha=$( git worktree list | grep " $1 " | awk ' {print $2}' )
1010
- # bare git-dir has no history
1011
- [[ " $sha " == " (bare)" ]] && return
1012
- _forgit_worktree_preview_git_opts=()
1013
- _forgit_parse_array _forgit_worktree_preview_git_opts " $FORGIT_WORKTREE_PREVIEW_GIT_OPTS "
1016
+ if [[ " $sha " == " (bare) " ]] ; then
1017
+ printf " %b (bare)%b %s\n " ' \e[0;33m ' ' \e[0m ' ' No history for git dir '
1018
+ return
1019
+ fi
1014
1020
# the trailing '--' ensures that this works for branches that have a name
1015
1021
# that is identical to a file
1016
- git log " $sha " " ${_forgit_worktree_preview_git_opts [@]} " --
1022
+ git log " $sha " " ${_forgit_log_preview_options [@]} " --
1017
1023
}
1018
1024
1019
1025
_forgit_worktree_jump () {
1020
1026
_forgit_inside_work_tree || _forgit_inside_git_dir || return 1
1021
- local count tree opts
1022
- count =$( git worktree list | wc -l )
1027
+ local worktree_list count tree opts
1028
+ worktree_list =$( git worktree list | grep -vE " prunable$ " | awk ' {print $1} ' | _forgit_filter_existing_paths )
1023
1029
1030
+ count=$( echo " $worktree_list " | wc -l)
1024
1031
[[ $count -eq 1 ]] && return 1
1025
1032
1026
1033
opts="
@@ -1030,7 +1037,7 @@ _forgit_worktree_jump() {
1030
1037
$FORGIT_WORKTREE_JUMP_FZF_OPTS
1031
1038
"
1032
1039
1033
- tree=$( git worktree list | awk ' {print $1} ' | FZF_DEFAULT_OPTS=" $opts " fzf)
1040
+ tree=$( echo " $worktree_list " | FZF_DEFAULT_OPTS=" $opts " fzf)
1034
1041
[[ -z " $tree " ]] && return 1
1035
1042
echo " $tree "
1036
1043
}
@@ -1043,16 +1050,21 @@ _forgit_git_worktree_lock() {
1043
1050
1044
1051
_forgit_worktree_lock () {
1045
1052
_forgit_inside_work_tree || _forgit_inside_git_dir || return 1
1053
+ if [[ $# -ne 0 ]]; then
1054
+ git worktree lock " $@ "
1055
+ worktree_lock_status=$?
1056
+ return $worktree_lock_status
1057
+ fi
1046
1058
local tree opts
1047
1059
1048
1060
opts="
1049
1061
$FORGIT_FZF_DEFAULT_OPTS
1050
- +s - m --tiebreak=index
1062
+ +s + m --tiebreak=index
1051
1063
--preview=\" $FORGIT worktree_preview {1}\"
1052
1064
$FORGIT_WORKTREE_LOCK_FZF_OPTS
1053
1065
"
1054
1066
1055
- tree=$( git worktree list | awk ' {print $1}' | grep -v " (bare) " | FZF_DEFAULT_OPTS=" $opts " fzf)
1067
+ tree=$( git worktree list | grep -vE " \(bare\)|locked " | awk ' {print $1}' | FZF_DEFAULT_OPTS=" $opts " fzf)
1056
1068
[[ -z " $tree " ]] && return 1
1057
1069
_forgit_git_worktree_lock " $tree "
1058
1070
}
@@ -1065,32 +1077,50 @@ _forgit_git_worktree_remove() {
1065
1077
1066
1078
_forgit_worktree_remove () {
1067
1079
_forgit_inside_work_tree || _forgit_inside_git_dir || return 1
1068
- local tree opts
1080
+ if [[ $# -ne 0 ]]; then
1081
+ git worktree remove " $@ "
1082
+ worktree_remove_status=$?
1083
+ return $worktree_remove_status
1084
+ fi
1085
+ local worktree_list tree opts
1086
+ worktree_list=$( git worktree list | grep -v " (bare)" )
1087
+
1088
+ count=$( echo " $worktree_list " | wc -l)
1089
+ [[ $count -eq 1 ]] && return 1
1069
1090
1070
1091
opts="
1071
1092
$FORGIT_FZF_DEFAULT_OPTS
1072
- +s - m --tiebreak=index --header-lines=1
1093
+ +s + m --tiebreak=index
1073
1094
--preview=\" $FORGIT worktree_preview {1}\"
1074
1095
$FORGIT_WORKTREE_REMOVE_FZF_OPTS
1075
1096
"
1076
1097
1077
- tree=$( git worktree list | awk ' {print $1}' | grep -v " (bare) " | FZF_DEFAULT_OPTS=" $opts " fzf)
1098
+ tree=$( echo " $worktree_list " | awk ' {print $1}' | FZF_DEFAULT_OPTS=" $opts " fzf)
1078
1099
[[ -z " $tree " ]] && return 1
1079
1100
_forgit_git_worktree_remove " $tree "
1080
1101
}
1081
1102
1082
1103
_forgit_worktree_unlock () {
1083
1104
_forgit_inside_work_tree || _forgit_inside_git_dir || return 1
1084
- local tree opts
1105
+ if [[ $# -ne 0 ]]; then
1106
+ git worktree unlock " $@ "
1107
+ worktree_unlock_status=$?
1108
+ return $worktree_unlock_status
1109
+ fi
1110
+ local worktree_list tree opts
1111
+
1112
+ worktree_list=$( git worktree list | grep -v " (bare)" | grep -E " locked$" )
1113
+ count=$( echo " $worktree_list " | wc -l)
1114
+ [[ $count -eq 0 ]] && return 1
1085
1115
1086
1116
opts="
1087
1117
$FORGIT_FZF_DEFAULT_OPTS
1088
- +s - m --tiebreak=index --header-lines=1
1118
+ +s + m --tiebreak=index
1089
1119
--preview=\" $FORGIT worktree_preview {1}\"
1090
1120
$FORGIT_WORKTREE_UNLOCK_FZF_OPTS
1091
1121
"
1092
1122
1093
- tree=$( git worktree list | awk ' {print $1}' | grep -v " (bare) " | FZF_DEFAULT_OPTS=" $opts " fzf)
1123
+ tree=$( echo " $worktree_list " | awk ' {print $1}' | FZF_DEFAULT_OPTS=" $opts " fzf)
1094
1124
[[ -z " $tree " ]] && return 1
1095
1125
git worktree unlock " $tree "
1096
1126
}
0 commit comments