|
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 |
4 | 3 | # |
5 | 4 | # usage: title short_tab_title long_window_title |
6 | 5 | # |
7 | 6 | # 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 |
9 | 8 | # (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 | + |
10 | 17 | function title { |
11 | 18 | emulate -L zsh |
12 | 19 | setopt prompt_subst |
13 | | - |
| 20 | + |
14 | 21 | [[ "$EMACS" == *term* ]] && return |
15 | 22 |
|
| 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 | + |
16 | 33 | tabTitle="\$1" |
17 | 34 | termTitle="\$2" |
18 | 35 |
|
@@ -43,23 +60,23 @@ function title { |
43 | 60 |
|
44 | 61 | function setTerminalTitleInIdle { |
45 | 62 |
|
46 | | - if [[ "$ZSH_TAB_TITLE_DISABLE_AUTO_TITLE" == true ]]; then |
| 63 | + if [[ "${ZSH_TAB_TITLE_DISABLE_AUTO_TITLE:-}" == true ]]; then |
47 | 64 | return |
48 | 65 | fi |
49 | 66 |
|
50 | | - if [[ "$ZSH_TAB_TITLE_ONLY_FOLDER" == true ]]; then |
| 67 | + if [[ "${ZSH_TAB_TITLE_ONLY_FOLDER:-}" == true ]]; then |
51 | 68 | ZSH_THEME_TERM_TAB_TITLE_IDLE=${PWD##*/} |
52 | 69 | else |
53 | 70 | ZSH_THEME_TERM_TAB_TITLE_IDLE="%20<..<%~%<<" #15 char left truncated PWD |
54 | 71 | fi |
55 | 72 |
|
56 | | - if [[ "$ZSH_TAB_TITLE_DEFAULT_DISABLE_PREFIX" == true ]]; then |
| 73 | + if [[ "${ZSH_TAB_TITLE_DEFAULT_DISABLE_PREFIX:-}" == true ]]; then |
57 | 74 | ZSH_TAB_TITLE_PREFIX="" |
58 | | - elif [[ -z "$ZSH_TAB_TITLE_PREFIX" ]]; then |
| 75 | + elif [[ -z "${ZSH_TAB_TITLE_PREFIX:-}" ]]; then |
59 | 76 | ZSH_TAB_TITLE_PREFIX="%n@%m:" |
60 | 77 | fi |
61 | 78 |
|
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" |
63 | 80 |
|
64 | 81 | title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE" |
65 | 82 | } |
|
0 commit comments