Skip to content

Improve terminal buffer display and toggling ability #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

drmikehenry
Copy link
Contributor

Overview

  • Improve the display of terminal buffers to be a uniform /current/working/directory/!PID:shellName on Vim and Neovim.

  • Enable the ability to toggle the showing of terminal buffers (via the X command).

Details

Terminal buffer display format

On Neovim, terminal buffers are named as:

term://WorkingDirectoryAtTerminalLaunch//PID:shellPath

On Vim, the name contains only a ! and the shell path:

!/path/to/shell

In order to sort by fullpath in a more useful manner, synthesize a path for terminal buffers based on the shell's current working directory. Display the shell's name without leading path for brevity. Terminal buffers are now displayed with this format:

/current/working/directory/!PID:shellName

At present, the current working directory of the shell can be determined only on Unix-like systems having a /proc filesystem. For other systems, fall back to the directory at terminal launch for Neovim, or else on Vim's current working directory.

It appears to be difficult to determine the current working directory of a program on Windows given the PID, so no attempt is made to determine it for that platform.

Toggling the showing of terminal buffers

When the feature to toggle showing terminal buffers was introduced, a mapping was added for H to perform this toggling in the BufExplorer window; however, the key was inoperable because BufExplorer immediately remapped it (along with some other movement keys).

Because movement keys such as H are valuable for navigating the BufExplorer window, the H mapping has been changed to use X instead, as X is normally an editing feature that's not needed in the BufExplorer window. In addition, this command has been documented.

If a different key (or even no key at all) is preferred for this toggling feature, I'd be happy to adjust the pull request accordingly.

Avoid calculating absolute and relative paths from the irregular path
syntax used for terminal buffers; instead, synthesize a path based on
the terminal's current working directory and the name of the shell:

  /current/working/directory/!PID:shellName

Where `/current/working/directory/` is the shell's current working
directory (when it can be determined), `PID` is the shell's process
identifier, and `shellName` is the name of the shell with leading path
removed for brevity.  For example, a terminal running `/bin/bash` as PID
1234 in directory `/tmp` would have a path of:

  /tmp/!1234:bash

On Neovim, terminal buffers are named as:

  term://WorkingDirectoryAtTerminalLaunch//PID:shellPath

On Vim, the name contains only a `!` and the shell path:

  !/path/to/shell

However, the PID is available on Vim via `term_getjob()` and `job_info()`.

At present, the current working directory of the shell can be determined
only on Unix-like systems having a `/proc` filesystem.  For other
systems, fall back to the directory at terminal launch for Neovim, or
else on Vim's current working directory.

It appears to be difficult to determine the current working directory of
a program on Windows given the PID, so no attempt is made to determine
it for that platform.
When the feature to toggle showing terminal buffers was introduced, a
mapping was added for `H` to perform this toggling in the BufExplorer
window; however, the `H` key was immediately mapped again by
BufExplorer's logic to use `:keepjumps` with some movement keys (`H`,
`M`, `L`, etc.), thus disabling the intended `H` mapping:

  ```vim
  nnoremap <script> <silent> <nowait> <buffer> H             :call <SID>ToggleShowTerminal()<CR>

  for k in ["G", "n", "N", "L", "M", "H"]
      execute "nnoremap <buffer> <silent>" k ":keepjumps normal!" k."<CR>"
  endfor
  ```

As these movement keys are useful for navigating the BufExplorer window,
use `X` instead of `H` to toggle the showing of terminal buffers, as `X`
is normally an editing feature (for deleting characters before the
cursor) that's not needed in the BufExplorer window.

In addition, the `X` command has been documented in `bufexplorer.txt`
and in BufExplorer's `<F1>` help text.
@jlanzarotta jlanzarotta merged commit a74db35 into jlanzarotta:master Mar 17, 2025
@drmikehenry drmikehenry deleted the terminal branch March 17, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants