Skip to content

Commit 05855e1

Browse files
committed
Trim long branch names in kitty tab_bar
1 parent 70a5c67 commit 05855e1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kitty/tab_bar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
SOFT_SEP = "│"
3434
PADDING = " "
3535
BRANCH_ICON = "󰘬"
36+
ELLIPSIS = "…"
3637
USER_ICON = ""
3738
HOST_ICON = "󱡶"
3839
PAGER_ICON = "󰦪"
@@ -43,6 +44,8 @@
4344
ACCENTED_BG_COLOR = Color(30, 104, 199)
4445
ACCENTED_ICON_BG_COLOR = Color(53, 132, 228)
4546

47+
MAX_BRANCH_LEN = 21
48+
4649
MIN_TAB_LEN = (
4750
len(LEFT_SEP)
4851
+ len(RIGHT_SEP)
@@ -235,6 +238,12 @@ def _get_git_info(active_window: Window, is_ssh: bool) -> Dict[str, Any]:
235238
return {"is_git_repo": False, "branch": ""}
236239

237240
branch = str(proc.stdout, "utf-8").strip() or "DETACHED"
241+
if len(branch) > MAX_BRANCH_LEN:
242+
start_len = (MAX_BRANCH_LEN - 1) // 2
243+
end_len = MAX_BRANCH_LEN - start_len - 1
244+
branch = branch[:start_len] + ELLIPSIS + branch[-end_len:]
245+
print(start_len, end_len, len(branch))
246+
238247
return {"is_git_repo": True, "branch": branch}
239248

240249

0 commit comments

Comments
 (0)