Kitty: tabs named by process launched

Created on 7 Jun 2018  路  12Comments  路  Source: kovidgoyal/kitty

In tmux, by default, your tabs are named by what is executed. For example, if I launched the "deadbeef" audio player, my tab for that window would be renamed "deadbeef".

A shortcoming of tmux, at least its default settings, is if you execute a script, like a shell script (sh) for example, the tab is renamed to "sh" instead of what comes after "sh". So if I launched a shell script in the means of "sh wine32", the tab would be named "sh" instead of conveniently being renamed "wine32". There may be an option in tmux to have this desired behavior I mentioned, but I ran into other issues with tmux that stopped me from using it.

Can or does kitty have the ability to rename the tabs in this fashion without manually having to rename them? There is no man page for kitty in the kitty-git AUR package on Arch Linux, and I didn't find anything in the README.

Most helpful comment

In meantime I can share my home-backed solution to this for zsh that I've been quite happy so far, works on all terminals including kitty:

~/.zshrc

function set-title-precmd() {
  printf "\e]2;%s\a" "${PWD/#$HOME/~}"
}

function set-title-preexec() {
  printf "\e]2;%s\a" "$1"
}

autoload -Uz add-zsh-hook
add-zsh-hook precmd set-title-precmd
add-zsh-hook preexec set-title-preexec

This sets title to the name of the currently executing command, and to the current directory when no process is running. Apps are able to override this and set title to as they want, for example my nvim sets title to the currently focused file.

UPDATE: oops, sorry I just noticed this is about _tab_ titles and not _window_ titles. You'd have to adjust the printf commands to set tab title, there is also a kitty-specific API to do that.

All 12 comments

kitty has comprehensive documentation on its website, including the ability to set tab titles via both a key combination and the remote control facility.

I saw that you can maunally set each tab with the "ctrl+shift+alt+t" keybind. I don't see anywhere in the documentation where you can have the tabs named automatically by the name of the process launched.

I find naming tabs by the process running in them rather wasteful, since most of the time they would show bash or vim or zsh or ssh. Instead tabs are automatically named by whatever title the terminal program running in the active window in the tab sets. Most modern shells, editors, etc have the ability to set this title builtin (though you may have to turn it on in the config). And if some program lacks it you can make use of the kitty remote control system to compensate by creating a wrapper script that launches the program and sets the window/tab title using kitty @

Tmux by default does this, unless a shell script is executed, then the tab is sadly named only "sh" instead the shell scripts name.

I just thought it would be a nice option to have to compete with what tmux does by default, since that's more desirable then having every tab named "kitty".

I was just suggesting improved default behavior to match the tmux default, but also make it "smarter", by naming tabs with a scripted process be named the name of the script, rather then vaguely labeled "sh".

Ah, well I can certainly see the use of making the fallback title the process name rather than kitty. I just never bothered because all the programs I use set the title anyway.

In meantime I can share my home-backed solution to this for zsh that I've been quite happy so far, works on all terminals including kitty:

~/.zshrc

function set-title-precmd() {
  printf "\e]2;%s\a" "${PWD/#$HOME/~}"
}

function set-title-preexec() {
  printf "\e]2;%s\a" "$1"
}

autoload -Uz add-zsh-hook
add-zsh-hook precmd set-title-precmd
add-zsh-hook preexec set-title-preexec

This sets title to the name of the currently executing command, and to the current directory when no process is running. Apps are able to override this and set title to as they want, for example my nvim sets title to the currently focused file.

UPDATE: oops, sorry I just noticed this is about _tab_ titles and not _window_ titles. You'd have to adjust the printf commands to set tab title, there is also a kitty-specific API to do that.

I noticed that by default, my tabs now say "/bin/zsh". They still don't naturally get renamed to what you launched under the tab. I honestly liked it more when they said kitty lol

There is no way for the terminal to know "what you launched under the tab". Only the shell can know that. If you want that to appear in your tab title, configure your shell to do it.

Ok, I understand now. I didn't comprehend that kitty couldn't do that. I thought it could because tmux did it, but they are two different programs. I got you now lol. I'll do what maximbaz said, thanks guys.

I can't seem to find any information on tab naming on the website. I looked under "kittens" which I assume are the APIs, and don't see anything. I may just use the script maximbaz wrote and use windows instead of tabs

tabs get their title from the title of the currently active window, so you dont need to do anything.

Ok, I totally get it now lol. Thank you guys so much! The script works great maximbaz!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wavexx picture wavexx  路  3Comments

crocket picture crocket  路  4Comments

atomsymbol picture atomsymbol  路  3Comments

bewzaalex picture bewzaalex  路  3Comments

Jomik picture Jomik  路  4Comments