Use b:term_title for terminal buffer display names.#138
Use b:term_title for terminal buffer display names.#138charlesg3 wants to merge 1 commit intojlanzarotta:masterfrom
Conversation
When a terminal buffer's b:term_title has been set by an OSC 0/2 title sequence (e.g. via shell preexec/precmd hooks), use it as the display name instead of the opaque `!PID:shell` fallback. This makes it easy to distinguish multiple terminal buffers by showing the running command or current directory rather than an arbitrary process ID. Neovim initialises b:term_title to the raw `term://` URI before any title sequence has arrived, so values matching that prefix are ignored and the existing fallback is used instead.
|
This looks like a useful extension. I don't use the There's not much (other than the buffer number) to distinguish these terminals on my system. If I then It's a bit redundant having the directory name duplicated by the path column. The PID distinguisher is lost here; but a user would likely rather remember the the (probably shorter) buffer number instead of the PID anyway, if the let term_title = getbufvar(buf.bufNbr, 'term_title', '')
if !empty(term_title) && term_title !~# '^term://'
let shellName = term_title
endif
if pid < 0With BufExplorer showing: However, this comes at the expense of quite a few columns in the display, and probably isn't that valuable. Users wanting a better display in BufExplorer would likely want to configure things so that I also didn't test what happens if the currently running command is very long; that might push subsequent columns off the right side of the display. Perhaps if In any event, I think this idea has merit. As a very infrequent user of I expect @jlanzarotta will weigh in when he gets some time; I know he's frequently fairly swamped with other things. |
|
I am currently stuck on Windows development, so I am pretty sure this is not reproduceable there... I do not use NeoVim either. As long as this change does not break Windows Vim, I will merge it. Let me take a look and I hope to merge in the next day or so. |
|
Great -- thanks so much for taking a look and merging. It's definitely a QoL improvement on my end where many of my terminal apps set nice "titles" (and I have my shell do the same) so now I can easily differentiate what's running in each of the shells and not left guessing based on PID. 🙏 |
Problem
When multiple terminal buffers are open, BufExplorer displays each one as
!PID:shell(e.g.!22290:zsh). With several terminals running it is difficult to tell them apart — the PID is meaningless at a glance.Solution
Neovim stores the OSC 0/2 title emitted by the terminal program in the buffer-local variable
b:term_title. When a shell has preexec/precmd hooks that set the title to the running command or current directory, this variable contains something much more useful than the PID.This change checks
b:term_titleafter the existing!PID:shellname is constructed, and substitutes it when a meaningful title is present:The
^term://guard is necessary because Neovim initialisesb:term_titleto the raw terminal URI (e.g.term://~//22290:/bin/zsh) before any OSC sequence has arrived. Without it, that default value would be used verbatim.Result
With a shell configured to emit OSC titles (e.g. zsh
preexec/precmdhooks), terminals appear in the buffer list as:instead of:
Falls back gracefully to the existing
!PID:shellformat whenb:term_titlehas not been set by the terminal.