1

I know it's weird and I don't know if it's possible but it would be great to have the name of the command I run in the terminal emulator when I use bash or zsh.

At the moment, to launch a new terminal, I do something like :term zsh so the buffer is named term://.//26149:zsh. Now, I launch a long running command like docker-compose up app. I want the buffer to be renamed to something like term://.//docker-compose up app. I can do it manually by using :file but is there a way to do it automatically?

The main goal is to access it very fast by doing :b docker. If you have other tips to do that, I'm open to suggestions.

2

Alternative:

  • Do :b term<tab>. Assuming you do not have many terminal buffers open. Or :b term if you only have 1 instance
  • Set a file mark, mD, then use 'D to return
  • Use :file to name your buffer something you like and will remember. e.g. :file repl

Now in theory if you can change the buffer name via :file and b:term_title is the current program, then you can automatically change the buffer name. Maybe update the buffer name when you leave the buffer. The idea:

augroup TermName
    autocmd!
    autocmd BufLeave term://* if len(get(b:, 'term_title', '')) | execute 'file ' . matchstr(expand('<afile>'), 'term://(.{-}//(\d+:)?)?\ze.*') . escape(b:term_title, ' ') | endif
augroup END

Note: I do not have NeoVim and I have not tested this in any way.

  • it seems to work. I will try a little more before to accept the answer – Dougui Jan 12 '18 at 20:18
  • It works. I just added a prefix "command://" and add an autocmd for "command://*" to always have the last process. – Dougui Jan 12 '18 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.