Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delet this

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Lua.diagnostics.globals": [
"vim"
]
}
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ It supports the following multiplexers/terminal, referred to as backends hereaft

- tmux
- wezterm
- zellij
- toggleterm

## Installation
Expand Down Expand Up @@ -78,23 +79,32 @@ vim.g.command = {--[[ options go here ]]}
The backend is the multiplexer or terminal to use. It's controlled by the `backend` key in the options table.
If the `backend` key is unset, as it is by default, heuristics are used to pick one of the supported backends.

* If `$TMUX` is set, tmux is used.
The backend is selected using the following table of fallbacks, checked in order from top to bottom. The first condition that matches determines which backend will be used:

* Else if `wezterm(?.exe)` exists in `$PATH`, wezterm is used.
| Condition | Backend |
| ------------------------------------------------- | ---------- |
| `$TMUX` is set | tmux |
| `$ZELLIJ` or `$ZELLIJ_SESSION_NAME` is set | zellij |
| `$TERM` is `wezterm` | wezterm |
| toggleterm's module can be `require()`'ed | toggleterm |

* Else if toggleterm's module can be `require()`'ed, toggleterm is used.
This order ensures that the most specific environment (e.g., tmux or zellij) is prioritized.
**If none of these heuristics succeed, you must explicitly set a backend using the `backend` key in your configuration. Otherwise, an error will be raised and no backend will be used.**

```lua
--- @alias backend_used
--- | 'tmux'
--- | 'wezterm'
--- | 'zellij'
--- | 'toggleterm'
backend = nil
```

#### tmux & wezterm
#### tmux, wezterm, and zellij

The tmux and wezterm backends both have 2 built in pane directions, right of the editor pane, and below the editor pane.
The tmux and wezterm backends each have 2 built in pane directions, right of the editor pane, and below the editor pane.

The zellij backend has those two directions plus a third that sends commands to a floating pane (creating one if none exists).

#### ToggleTerm

Expand Down Expand Up @@ -137,6 +147,7 @@ vim.g.command = {
--- @alias backend_used
--- | 'tmux'
--- | 'wezterm'
--- | 'zellij'
--- | 'toggleterm'
backend = nil

Expand Down Expand Up @@ -174,10 +185,10 @@ vim.g.command = {
- [x] tmux
- [x] ToggleTerm
- [x] wezterm
- [x] zellij
- [ ] default nvim terminal
- [ ] kitty
- [ ] some other backend
- [ ] zellij
- [x] clean up types
- [x] types for all opts, use lua-ls enums
- [x] move to utils ?
Expand Down
32 changes: 20 additions & 12 deletions doc/command.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*command.nvim.txt* For Neovim >= 0.9.0 Last change: 2025 October 20
*command.nvim.txt* For Neovim >= 0.9.0 Last change: 2026 March 25

==============================================================================
Table of Contents *command.nvim-table-of-contents*
Expand Down Expand Up @@ -36,11 +36,12 @@ if you want to make it executable.
- |command.nvim-defaults|
- |command.nvim-todo|

It supports the following multiplexers/terminal, refered to as backends
It supports the following multiplexers/terminal, referred to as backends
hereafter:

- tmux
- wezterm
- zellij
- toggleterm


Expand Down Expand Up @@ -93,34 +94,40 @@ CONFIGURATION *command.nvim-toc-configuration*
Configurations is done by setting the `vim.g.command` table.

>lua
vim.g.command = {--[[ options go here ]]} )
vim.g.command = {--[[ options go here ]]}
<


BACKENDS ~

The backend is the multiplexer or terminal to use. It’s controlled by the
`backend` key in the options table. If the `backend` key is unset, as it is by
default, heuristics are used to pick on of the supported backends.
default, heuristics are used to pick one of the supported backends.

- If `$TMUX` is set, tmux is used.
- Else if `wezterm(?.exe)` exists in `$PATH`, wezterm is used.
- Else if `$ZELLIJ` or `$ZELLIJ_SESSION_NAME` is set (Neovim is running inside
Zellij), zellij is used.
- Else if `$TERM` is `wezterm`, wezterm is used.
- Else if toggleterm’s module can be `require()`’ed, toggleterm is used.

>lua
--- @alias backend_used
--- | 'tmux'
--- | 'wezterm'
--- | 'zellij'
--- | 'toggleterm'
backend = nil
<


TMUX & WEZTERM
TMUX, WEZTERM, AND ZELLIJ

The tmux and wezterm backends both have 2 built in pane directions, right of
The tmux and wezterm backends each have 2 built in pane directions, right of
the editor pane, and below the editor pane.

The zellij backend has those two directions plus a third that sends commands to
a floating pane (creating one if none exists).


TOGGLETERM

Expand All @@ -133,8 +140,8 @@ RULES ~
When using `Command File` to run a file, instead of simply running the file you
might want to run a specific shell command. Using Rules you can, they are
key-value pairs of lua patterns and functions. The lua pattern is compared
against the current filename, if it maches the function is run to get the shell
command and run it.
against the current filename, if it matches the function is run to get the
shell command and run it.

>lua
opts = {
Expand Down Expand Up @@ -168,8 +175,9 @@ The defaults options are as follows:
--- @alias backend_used
--- | 'tmux'
--- | 'wezterm'
--- | 'zellij'
--- | 'toggleterm'
use = nil
backend = nil

--- defines rules to overwrite the command to run when using the "run current file" behavior
--- keys are lua patterns (see :help lua-pattern)
Expand Down Expand Up @@ -206,10 +214,10 @@ TODO *command.nvim-toc-todo*
- tmux
- ToggleTerm
- wezterm
- zellij
- default nvim terminal
- kitty
- some other backend
- zellij
- clean up types
- types for all opts, use lua-ls enums
- move to utils ?
Expand All @@ -228,7 +236,7 @@ TODO *command.nvim-toc-todo*

SIMILAR PLUGINS *command.nvim-toc-similar-plugins*

- yeet.nvim <https://github.com/samharju/yeet.nvim>, very similar, would not have _originaly_ made this had I known yeet.nvim existed :^P
- yeet.nvim <https://github.com/samharju/yeet.nvim>, very similar, would not have _originally_ made this had I known yeet.nvim existed :^P

==============================================================================
3. Links *command.nvim-links*
Expand Down
4 changes: 4 additions & 0 deletions lua/command/command-types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
--- | 'wezterm'
--- | 'tmux'
--- | 'toggleterm'
--- | 'zellij'
--- | 'auto' -- pick automatically by examining environment vars

--- @alias rule table<string, fun(string?):string>

--- @class direction
--- @field name string
--- @field new string|nil
--- @field old string|nil
--- @field split string|nil

--- @class backend
--- @field run fun(string)
Expand Down
2 changes: 1 addition & 1 deletion lua/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ M.CommandDirection = 1

M.ChangeDirection = function()
if not M.backend.directions then
notify('Changing directions is not supported using backend: ' .. vim.g.command.use, 'error')
notify('Changing directions is not supported using backend: ' .. vim.g.command.backend, 'error')
return
end
M.CommandDirection = (M.CommandDirection % #M.backend.directions + 1)
Expand Down
Loading
Loading