Skip to content

Commit 8a75c2d

Browse files
chmoueltrystan2k
authored andcommitted
feat: Add support for Zellij terminal emulator
Implemented logic to detect when running inside Zellij and used its native actions to rename the current tab and pane using the provided title arguments. Updated shell shebang to use `#!/usr/bin/env zsh` and improved variable access for configuration options. Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
1 parent 9c36ac9 commit 8a75c2d

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

zsh-tab-title.plugin.zsh

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
1-
#!/bin/bash
2-
3-
# Set terminal window and tab/icon title
1+
#!/usr/bin/env zsh
2+
#bashbash Set terminal window and tab/icon title
43
#
54
# usage: title short_tab_title long_window_title
65
#
76
# See: http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
8-
# Fully supports screen, hyper, iterm, and probably most modern xterm and rxvt
7+
# Fully supports screen, hyper, iterm, zellij, and probably most modern xterm and rxvt
98
# (In screen, only short_tab_title is used)
9+
10+
# Detect Zellij
11+
_in_zellij() { [[ -n "$ZELLIJ" || -n "$ZELLIJ_SESSION_NAME" ]]; }
12+
13+
# Zellij rename actions
14+
_zt_rename_tab() { command zellij action rename-tab "$1" >/dev/null 2>&1; }
15+
_zt_rename_pane() { command zellij action rename-pane "$1" >/dev/null 2>&1; }
16+
1017
function title {
1118
emulate -L zsh
1219
setopt prompt_subst
13-
20+
1421
[[ "$EMACS" == *term* ]] && return
1522

23+
# Handle Zellij first - use actual arguments directly
24+
if _in_zellij; then
25+
# Expand prompt sequences in arguments before passing to zellij
26+
local tab_name="$(print -P "$1")"
27+
local pane_name="$(print -P "$2")"
28+
_zt_rename_tab "$tab_name"
29+
_zt_rename_pane "$pane_name"
30+
return
31+
fi
32+
1633
tabTitle="\$1"
1734
termTitle="\$2"
1835

@@ -43,23 +60,23 @@ function title {
4360

4461
function setTerminalTitleInIdle {
4562

46-
if [[ "$ZSH_TAB_TITLE_DISABLE_AUTO_TITLE" == true ]]; then
63+
if [[ "${ZSH_TAB_TITLE_DISABLE_AUTO_TITLE:-}" == true ]]; then
4764
return
4865
fi
4966

50-
if [[ "$ZSH_TAB_TITLE_ONLY_FOLDER" == true ]]; then
67+
if [[ "${ZSH_TAB_TITLE_ONLY_FOLDER:-}" == true ]]; then
5168
ZSH_THEME_TERM_TAB_TITLE_IDLE=${PWD##*/}
5269
else
5370
ZSH_THEME_TERM_TAB_TITLE_IDLE="%20<..<%~%<<" #15 char left truncated PWD
5471
fi
5572

56-
if [[ "$ZSH_TAB_TITLE_DEFAULT_DISABLE_PREFIX" == true ]]; then
73+
if [[ "${ZSH_TAB_TITLE_DEFAULT_DISABLE_PREFIX:-}" == true ]]; then
5774
ZSH_TAB_TITLE_PREFIX=""
58-
elif [[ -z "$ZSH_TAB_TITLE_PREFIX" ]]; then
75+
elif [[ -z "${ZSH_TAB_TITLE_PREFIX:-}" ]]; then
5976
ZSH_TAB_TITLE_PREFIX="%n@%m:"
6077
fi
6178

62-
ZSH_THEME_TERM_TITLE_IDLE="$ZSH_TAB_TITLE_PREFIX %~ $ZSH_TAB_TITLE_SUFFIX"
79+
ZSH_THEME_TERM_TITLE_IDLE="${ZSH_TAB_TITLE_PREFIX:-} %~ $ZSH_TAB_TITLE_SUFFIX"
6380

6481
title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE"
6582
}

0 commit comments

Comments
 (0)