Skip to content

Commit 86311b3

Browse files
thiagowfxAmp
andcommitted
wt: use starship-style git status indicators
Status: =conflicted +staged !modified »renamed ✘deleted ?untracked $stashed Sync: ⇡ahead ⇣behind ⇕diverged (empty when synced) Amp-Thread-ID: https://ampcode.com/threads/T-019cb3c8-3b5d-74db-81ab-5678430f5639 Co-authored-by: Amp <amp@ampcode.com>
1 parent aee4a75 commit 86311b3

1 file changed

Lines changed: 46 additions & 18 deletions

File tree

wt/wt.sh

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,17 @@ cmd_list() {
372372
if $use_color; then
373373
local status_color="\033[32m"
374374
if [[ "$status_str" != "clean" ]]; then
375-
status_color="\033[33m"
375+
status_color="\033[1;31m"
376376
fi
377-
local sync_color=""
377+
local sync_part=""
378378
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
379+
sync_part=" \033[1;31m${sync_str}\033[0m"
384380
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"
381+
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_part}"
386382
else
387-
echo "${p}${spaces} ${commits[$i]} ${branches[$i]} ${status_str}${sspaces} ${sync_str}"
383+
local sync_part=""
384+
[[ -n "$sync_str" ]] && sync_part=" ${sync_str}"
385+
echo "${p}${spaces} ${commits[$i]} ${branches[$i]} ${status_str}${sspaces}${sync_part}"
388386
fi
389387
done
390388
}
@@ -1282,7 +1280,7 @@ get_worktree_status() {
12821280
git_dir=$(git -C "$path" rev-parse --git-dir 2>/dev/null)
12831281

12841282
if [[ -f "$git_dir/MERGE_HEAD" ]]; then
1285-
echo "merging"
1283+
echo "=merging"
12861284
return
12871285
fi
12881286

@@ -1306,11 +1304,41 @@ get_worktree_status() {
13061304
return
13071305
fi
13081306

1309-
local changes
1310-
changes=$(git -C "$path" status --porcelain 2>/dev/null | wc -l | tr -d ' ')
1307+
local indicators=""
1308+
local staged=0 modified=0 untracked=0 deleted=0 renamed=0 conflicted=0
1309+
1310+
while IFS= read -r line; do
1311+
local xy="${line:0:2}"
1312+
case "$xy" in
1313+
"UU"|"AA"|"DD") ((conflicted++)) ;;
1314+
*)
1315+
case "${xy:0:1}" in
1316+
"R") ((renamed++)) ;;
1317+
"A"|"M"|"C") ((staged++)) ;;
1318+
"D") ((deleted++)) ;;
1319+
esac
1320+
case "${xy:1:1}" in
1321+
"M") ((modified++)) ;;
1322+
"D") ((deleted++)) ;;
1323+
"?") ((untracked++)) ;;
1324+
esac
1325+
;;
1326+
esac
1327+
done < <(git -C "$path" status --porcelain 2>/dev/null)
1328+
1329+
local stashed
1330+
stashed=$(git -C "$path" stash list 2>/dev/null | wc -l | tr -d ' ')
13111331

1312-
if [[ "$changes" -gt 0 ]]; then
1313-
echo "$changes changes"
1332+
[[ "$conflicted" -gt 0 ]] && indicators+="=$conflicted"
1333+
[[ "$staged" -gt 0 ]] && indicators+="+$staged"
1334+
[[ "$modified" -gt 0 ]] && indicators+="!$modified"
1335+
[[ "$renamed" -gt 0 ]] && indicators+="»$renamed"
1336+
[[ "$deleted" -gt 0 ]] && indicators+="$deleted"
1337+
[[ "$untracked" -gt 0 ]] && indicators+="?$untracked"
1338+
[[ "$stashed" -gt 0 ]] && indicators+="\$$stashed"
1339+
1340+
if [[ -n "$indicators" ]]; then
1341+
echo "$indicators"
13141342
else
13151343
echo "clean"
13161344
fi
@@ -1338,13 +1366,13 @@ get_worktree_ahead_behind() {
13381366
behind=$(git -C "$path" rev-list --count "HEAD..@{u}" 2>/dev/null || echo "0")
13391367

13401368
if [[ "$ahead" -gt 0 ]] && [[ "$behind" -gt 0 ]]; then
1341-
echo "$ahead$behind"
1369+
echo "⇕⇡${ahead}${behind}"
13421370
elif [[ "$ahead" -gt 0 ]]; then
1343-
echo "$ahead"
1371+
echo "$ahead"
13441372
elif [[ "$behind" -gt 0 ]]; then
1345-
echo "$behind"
1373+
echo "$behind"
13461374
else
1347-
echo "synced"
1375+
echo ""
13481376
fi
13491377
}
13501378

0 commit comments

Comments
 (0)