gnome-terminator / terminator

multiple GNOME terminals in one window
https://gnome-terminator.org
GNU General Public License v2.0
2.07k stars 252 forks source link

Titles for tabs #615

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

First, thanks for this great terminal! I'm absolutely in love with it, can't imagine my life before.

Is your feature request related to a problem? Please describe.

The problem is that I have multiple tabs opened in it, however they all are titled with /bin/bash, so it's inconvenient to cycle between them.

Describe the solution you'd like

I'd like the tabs to be named automatically, based on the number of open windows and their contents.

Example 1

Opened windows:

  1. Running firefox

Title: firefox

Example 2

Opened windows:

  1. Nothing is running (active directory is ~/Desktop)
  2. Running lynx

Title: ~/Desktop | lynx

Example 3

Opened windows:

  1. Nothing is running, ~ is opened
  2. Nothing is running, ~/Desktop is opened
  3. Nothing is running, ~/Phrog/Quack/Hehehe/Aaa is opened

Title: ~ | ~ | ~/Phrog/...

Xemptuous commented 2 years ago

I like your idea, and I think this can be applied to the base-case as well, where this functionality can be applied to the titlebar in general, even on split windows within the same tab. As it stands, I keep the titlebar off because it only displays useless information at the moment (/usr/bin/zsh or /bin/bash). It can get quite confusing remembering which windows are running what processes when there are many of them. This functionality you propose would - I believe - also include the base case, in which case I would add a +1 to this, because seeing what shell the terminal is running seems quite useless to me, especially when most people run one shell.

mattrose commented 2 years ago

If your tabs are named "/bin/bash" you should probably configure your shell to send the information from the shell to the title . This is shell dependent, but there's probably a "/etc/profile.d/vte.sh" file that you should be sourcing. This will set your shell to set the title when it prints out PS1. I have an interesting idea of how to achieve some of what you're asking, but it relies on Terminator receiving the proper Information from the shell in the first place, so I would suggest fixing that up first.

Xemptuous commented 2 years ago

Thanks for your response mattrose. I looked in that directory and found the appropriate file(named vte-2.91.sh), but it seems like sourcing it in my .zshrc didn't do anything. I did notice my PS1 is overridden by my powerlevel10k zsh theme; output of echo $PS1 is quite long, and seems to mostly affect the prompt styling. My terminator windowbar always shows the ~ home directory in the form of user@comp: ~ regardless of where I am, and each titlebar still shows /usr/bin/zsh. I guess the theme is conflicting with Terminator's default method of getting the cwd.

Would it be possible to utilize PS2-4 to show cwd for either the window title or the individual titlebars?

mattrose commented 2 years ago

From reading vte-2.91.sh, it should add the proper OSC7 escape sequence to your zsh precmd_functions function. Maybe make sure you're running in interactive mode, and open up a new terminal?

PS2 and up are only occasionally printed to the terminal, so I don't think those'll help you.

Xemptuous commented 2 years ago

So my zsh runs in interactive by default, so I don't believe that's the issue. Checked it with if [[ -o interactive ]]; then echo "yes"; else echo "no"; fi

I am hitting some roadblocks in my diagnosis, but I am starting to assume it has to do with the p10k theme I have, how it affects the PS1 variable, and how terminator parses it. The /etc/profile.d/vte-2.91.sh seems to append the __vte_osc7 function to my precmd_functions (and not __vte_prompt_command), as evident in the variable itself; the output of my echo $precmd_functionsis:

_p9k_do_nothing __vte_osc7 _zsh_highlight_main__precmd_hook _zsh_autosuggest_start _p9k_precmd

and the output of my echo $PS1 is the walloping:

${$((_p9k_on_expand()))+}%{${_p9k__raw_msg-}${_p9k__raw_msg::=}%}${(e)_p9k_t[7]}${_p9k__1-${${:-${_p9k__d::=0}${_p9k__rprompt::=${_p9k__1r-${${:-${_p9k__bg::=NONE}${_p9k__i::=0}${_p9k__sss::=}}+}${${:-${P9K_CONTENT::=}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=8}}${_p9k__n:=${${(M)${:-x$_p9k__bg}:#x(234|234)}:+10}}${_p9k__n:=11}${_p9k__v}}${_p9k__e::=${${_p9k__1rstatus+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}1}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{070\}${${(M)_p9k__e:#11}:+ }$_p9k__v${${:-${_p9k__w::=%b%K{234\}%F{070\} %b%K{234\}%F{070\}}${_p9k__sss::=%b%K{234\}%F{070\} }${_p9k__i::=1}${_p9k__bg::=234}}+}}${${:-"${${(%):-%j}:#0}"}:+${${:-${P9K_CONTENT::=""}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=12}}${_p9k__n:=${${(M)${:-x$_p9k__bg}:#x(234}}${_p9k__e::=${${_p9k__1rbackground_jobs+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}1}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{037\}${${(M)_p9k__e:#11}:+ }$_p9k__v${${:-${_p9k__w::=%b%K{234\}%F{037\} %b%K{234\}%F{037\}}${_p9k__sss::=%b%K{234\}%F{037\} }${_p9k__i::=3}${_p9k__bg::=234}}+}}}${${:-"${${(%):-%#}:#\#}"}:+${${:-${P9K_CONTENT::=%n@%m}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=20}}${_p9k__n:=${${(M)${:-x$_p}}${_p9k__e::=${${_p9k__1rcontext+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{180\}${${:-${_p9k__w::=%b%K{234\}%F{180\} %b%K{234\}%F{180\}}${_p9k__sss::=%b%K{234\}%F{180\} }${_p9k__i::=31}${_p9k__bg::=234}}+}}}${${:-"${${(%):-%#}:#\%}"}:+${${:-${P9K_CONTENT::=%B%n@%m}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=24}}${_p9k__n:=${${(M)${:-x$_p9k__bg}:#x(234|234)}:+26}}${_p9k__n:}}${_p9k__e::=${${_p9k__1rcontext+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{178\}${${:-${_p9k__w::=%b%K{234\}%F{178\} %b%K{234\}%F{178\}}${_p9k__sss::=%b%K{234\}%F{178\} }${_p9k__i::=31}${_p9k__bg::=234}}+}}}${${:-"${${:-$_p9k__keymap.$_p9k__zle_state}:#(vicmd.*|vivis.*|vivli.*|*.*insert*)}"}:+${${:-${P9K_CONTENT::=OVERTYPE}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=28}}${}}${_p9k__e::=${${_p9k__1rvi_mode+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{172\}${${:-${_p9k__w::=%b%K{234\}%F{172\} %b%K{234\}%F{172\}}${_p9k__sss::=%b%K{234\}%F{172\} }${_p9k__i::=39}${_p9k__bg::=234}}+}}}${${:-"${(M)${:-$_p9k__keymap$_p9k__region_active}:#vicmd0}"}:+${${:-${P9K_CONTENT::=NORMAL}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=32}}${_p9k__n:=${${(M)${:-x$_p9k}}${_p9k__e::=${${_p9k__1rvi_mode+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{106\}${${:-${_p9k__w::=%b%K{234\}%F{106\} %b%K{234\}%F{106\}}${_p9k__sss::=%b%K{234\}%F{106\} }${_p9k__i::=39}${_p9k__bg::=234}}+}}}${${:-"${(M)${:-$_p9k__keymap$_p9k__region_active}:#(vicmd1|vivis?|vivli?)}"}:+${${:-${P9K_CONTENT::=VISUAL}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=36}}${_p9k__n:=$}}${_p9k__e::=${${_p9k__1rvi_mode+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${_p9k_t[$_p9k__n]/<_p9k__w>/$_p9k__w}${_p9k__c}%b%K{234\}%F{068\}${${:-${_p9k__w::=%b%K{234\}%F{068\} %b%K{234\}%F{068\}}${_p9k__sss::=%b%K{234\}%F{068\} }${_p9k__i::=39}${_p9k__bg::=234}}+}}}$_p9k__sss%b%k%f}}${_p9k__lprompt::=${_p9k__1l-${${:-${_p9k__bg::=NONE}${_p9k__i::=0}${_p9k__sss::=%f}}+}${${:-${P9K_CONTENT::=}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=40}}${_p9k__n:=${${(M)${:-x234}:#x($_p9k__bg|${_p9k__bg:-0})}:+42}}${_p9k__n:=43}${_p9k__c::="${P9K_CONTENT}"}$}}${_p9k__e::=${${_p9k__1los_icon+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}0}}}+}${${_p9k__e:#00}:+${${_p9k_t[$_p9k__n]/<_p9k__ss>/$_p9k__ss}/<_p9k__s>/$_p9k__s}${_p9k__c}%b%K{234\}%F{255\} ${${:-${_p9k__s::=%F{234\}}${_p9k__ss::=%242F}${_p9k__sss::=%F{234\}}${_p9k__i::=1}${_p9k__bg::=234}}+}}${${:-${P9K_CONTENT::="%{d%}/${:-"%B%F{039}"}${(Q)${:-"etc"}}${:-"%b%K{234}%F{031}"}/${:-"%B%F{039}"}profile.d${:-"%b%K{234}%F{031}"}%{d%}"}${_p9k__n::=}${${${_p9k__bg:-0}:#NONE}:-${_p9k__n::=76}}${_p9k__n:=${${(M)${:-x234}:#x($_p9k__bg|${_p9k__bg:-0})}:+78}}${_p9k__n:=79}${_p9k__v::=}}}${_p9k__e::=${${_p9k__1ldir+00}:-${${(%):-$_p9k__c%1(l.1.0)}[-1]}1}}}+}${${_p9k__e:#00}:+${${_p9k_t[$_p9k__n]/<_p9k__ss>/$_p9k__ss}/<_p9k__s>/$_p9k__s}${_p9k__v}${${(M)_p9k__e:#11}:+ }${_p9k__c}%b%K{234\}%F{031\} ${${:-${_p9k__s::=%F{234\}}${_p9k__ss::=%242F}${_p9k__sss::=%F{234\}}${_p9k__i::=2}${_p9k__bg::=234}}+}}${(e)_p9k__vcs}%b%k$_p9k__sss%b%k%f${:-" %b%k%f"}}}}+}${(e)_p9k_t[6]}${${_p9k__h::=58.}+}${${_p9k__d::=$((_p9k__m-_p9k__h))}+}${_p9k__lprompt/\%\{d\%\}*\%\{d\%\}/${_p9k__1ldir-/${:-"%B%F{039}"}${(Q)${:-"etc"}}${:-"%b%K{234}%F{031}"}/${:-"%B%F{039}"}profile.d${:-"%b%K{234}%F{031}"}}}${${_p9k__m::=$((_p9k__d+_p9k__h))}+}}${${COLUMNS::=$_p9k__clm}+}

I assume the PS1 variable - as it currently is - is where the problem is occurring.

I have been ripgrepping the terminator directory for clues as to how it works, and the closest I am able to figure is that the functions in terminal.py of def get_cwd(self) and def set_cwd(self, cwd=None) are where issues are occurring for me. As it stands, I just disable the titlebars (as they just show shell) and don't utilize window titlebar, solely relying on my prompt to inform cwd. I'll continue looking for ways to fix it in the meantime.

mattrose commented 2 years ago

Hmm, I think I was getting confused with my OSC escape codes. OSC7 sends the CWD, the code to set the title is OSC0. Yoiur PS1 should include __vte_prompt_command, not just __vte_osc7. __vte_osc7 just sends the cwd to the terminal. if you run something like printf "\033]0;%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${pwd}" it should set the title to user@hostname /path/to/dir

Xemptuous commented 2 years ago

Very interesting response! I managed to find a fix! I ran the command you suggested with the escape codes, and it changed the titlebar, albeit not entirely as desired; i.e., when I ran it from any directory, it would only set the titlebar to user@: without the hostname or directory.

In the /etc/profile.d/vte-2.91.sh I had noticed an interesting block:

  43   | if [[ -n "${BASH_VERSION:-}" ]]; then
  44   │ 
  45   │     # Newer bash versions support PROMPT_COMMAND as an array. In this case
  46   │     # only add the __vte_osc7 function to it, and leave setting the terminal
  47   │     # title to the outside setup.
  48   │     # On older bash, we can only overwrite the whole PROMPT_COMMAND, so must
  49   │     # use the __vte_prompt_command function which also sets the title.
  50   │ 
  51   │     if [[ "$(declare -p PROMPT_COMMAND 2>&1)" =~ "declare -a" ]]; then
  52   │     PROMPT_COMMAND+=(__vte_osc7)
  53   │     else
  54   │     PROMPT_COMMAND="__vte_prompt_command"
  55   │     fi
  56   │ 
  57   │ elif [[ -n "${ZSH_VERSION:-}" ]]; then
  58   │     precmd_functions+=(__vte_osc7)
  59   │ fi

I assumed when reading this that __vte_prompt_command was an optional or potentially deprecated version compared to __vte_osc7, especially for zsh.

I managed to fix it by changing the ZSH_VERSION conditional block to:

elif [[ -n "${ZSH_VERSION:-}" ]]; then
    precmd_functions+=(__vte_osc7);
    precmd_functions+=(__vte_prompt_command);
fi

Now the titlebar is updating appropriately based on cwd (although main window bar is still static pointing to ~), and tabs are renamed according to the cwd of the last selected pane within them. As OP said, it would be nice to have a toggle option to show a condensed breakdown of all open directories and running processes (as well as processes being run showing in the titlebar in general).

Thank you for your help! I would have struggled immensely without it.

mattrose commented 2 years ago

Glad to help. This was a good illustration of what has to go right to get the updating titles to work reliably. Add in multiple levels of titlebar, and multiple windows per titlebar, and the complexity gets ... hairy.