@@ -295,6 +295,7 @@ cmd_list() {
295295 echo " Git worktrees ($main_worktree , worktrees in .worktrees/):"
296296 echo " "
297297
298+ local -a abs_paths=()
298299 local -a paths=()
299300 local -a commits=()
300301 local -a branches=()
@@ -305,6 +306,8 @@ cmd_list() {
305306 commit=$( echo " $line " | awk ' {print $2}' )
306307 branch=$( echo " $line " | awk ' {print $3}' )
307308
309+ abs_paths+=(" $path " )
310+
308311 if [[ " $path " == " $main_worktree " ]]; then
309312 path=" ."
310313 elif [[ " $path " == " $main_worktree /" * ]]; then
@@ -324,6 +327,24 @@ cmd_list() {
324327 fi
325328 done
326329
330+ local -a statuses=()
331+ local -a syncs=()
332+ local max_status_len=0
333+ for i in " ${! abs_paths[@]} " ; do
334+ local raw_branch=" ${branches[$i]} "
335+ raw_branch=" ${raw_branch# \[ } "
336+ raw_branch=" ${raw_branch% \] } "
337+
338+ local status
339+ status=$( get_worktree_status " ${abs_paths[$i]} " )
340+ statuses+=(" $status " )
341+ (( ${# status} > max_status_len )) && max_status_len=${# status}
342+
343+ local sync
344+ sync=$( get_worktree_ahead_behind " ${abs_paths[$i]} " " $raw_branch " )
345+ syncs+=(" $sync " )
346+ done
347+
327348 local use_color=false
328349 if [[ -t 1 ]]; then
329350 use_color=true
@@ -337,10 +358,33 @@ cmd_list() {
337358 for (( j= 0 ; j< padding; j++ )) ; do
338359 spaces+=" "
339360 done
361+
362+ local status_str=" ${statuses[$i]} "
363+ local slen=${# status_str}
364+ local spadding=$(( max_status_len - slen))
365+ local sspaces=" "
366+ for (( j= 0 ; j< spadding; j++ )) ; do
367+ sspaces+=" "
368+ done
369+
370+ local sync_str=" ${syncs[$i]} "
371+
340372 if $use_color ; then
341- echo -e " ⎇ \033[1;36m${p} \033[0m${spaces} \033[33m${commits[$i]} \033[0m \033[32m${branches[$i]} \033[0m"
373+ local status_color=" \033[32m"
374+ if [[ " $status_str " != " clean" ]]; then
375+ status_color=" \033[33m"
376+ fi
377+ local sync_color=" "
378+ if [[ -n " $sync_str " ]]; then
379+ if [[ " $sync_str " == " synced" ]]; then
380+ sync_color=" \033[32m"
381+ else
382+ sync_color=" \033[35m"
383+ fi
384+ fi
385+ echo -e " ⎇ \033[1;36m${p} \033[0m${spaces} \033[33m${commits[$i]} \033[0m \033[32m${branches[$i]} \033[0m ${status_color}${status_str} \033[0m${sspaces} ${sync_color}${sync_str} \033[0m"
342386 else
343- echo " ⎇ ${p}${spaces} ${commits[$i]} ${branches[$i]} "
387+ echo " ⎇ ${p}${spaces} ${commits[$i]} ${branches[$i]} ${status_str}${sspaces} ${sync_str} "
344388 fi
345389 done
346390}
0 commit comments