Skip to content
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

detecting wezterm and calling create tab from console #230

Closed
prabirshrestha opened this issue Jun 21, 2020 · 11 comments
Closed

detecting wezterm and calling create tab from console #230

prabirshrestha opened this issue Jun 21, 2020 · 11 comments
Labels
enhancement New feature or request

Comments

@prabirshrestha
Copy link

I use vim-gtfo which allows me to use got which opens a new terminal pane in the current directory of the file. Is there similar commands to detect and open tabs in wezterm. People use $TMUX environment variable to detect it is running inside tmux and then use tmux split-window. Would be good if wezterm has something similar wezterm split-window.

This feature might be better once #157 is implemented.

@prabirshrestha prabirshrestha added the enhancement New feature or request label Jun 21, 2020
@wez
Copy link
Owner

wez commented Jun 21, 2020

Regarding detection, wezterm sets TERM_PROGRAM=WezTerm in the environment.

literally interpreting your request

For spawning a new tab, some of the plumbing exists in the multiplexer protocol, but it hasn't been exposed to the wezterm cli subcommand as of yet, so some local changes to your config and some engineering would be required:

  • You'd need to enable the unix multiplexer domain and make it auto-connect per https://wezfurlong.org/wezterm/multiplexing.html#unix-domains; with that configured your GUI would then be connecting to the wezterm mux server in a fashion similar to the way that tmux works
  • The wezterm cli list command will enumerate and show your windows/tabs
  • A CLI subcommand that calls the client spawn method could be added. The parameter is the Spawn struct.
  • However, since the mux server is headless it doesn't necessarily know which window/tab has the focus, which makes it a little tricky to figure out which window to spawn the new command into. As it happens in 4e6357b which I haven't pushed yet, I've introduced the concept of tracking focus for local tabs, so we could then enable the mux server to track this

Alternatively, use OSC 7

If you set up vim to emit OSC 7 for the directory containing the file when you eg: BufEnter then spawning a new tab will use that directory.

https://wezfurlong.org/wezterm/shell-integration.html#osc-7-escape-sequence-to-set-the-working-directory

@prabirshrestha
Copy link
Author

actually this could be lot easier if wezterm supports subcommand to split.

https://github.com/justinmk/vim-gtfo/blob/d85e7a2f7e017c54bc5467a3946ca5065d17113d/autoload/gtfo/open.vim#L140

silent call system('tmux split-window -h \; send-keys "cd ''' . l:dir . ''' && clear" C-m')

system is a command to execute shell commands in vim.

Wezterm would need a sub command to open new tab, split tab horizontally or vertically and send keys.

wezterm split-tab -h \; send-keys "cd '/home'" && clear

wez added a commit that referenced this issue Sep 29, 2020
When spawning processes, export the local pane_id.

refs: #230
wez added a commit that referenced this issue Sep 29, 2020
This is the initial pass; the output from the command needs
some thought, but it basically operates.

refs: #230
wez added a commit that referenced this issue Dec 30, 2020
When running the GUI, we generate a unix domain socket path for
the current process and start up a mux server for that path.

This allows `wezterm cli list` and `wezterm cli split-pane` to
work implicitly inside the GUI session.

When started in this way, the mux server is not persistent;
when the GUI process is terminated, all of its windows, tabs
and panes are terminated.

refs: #230
@basbebe
Copy link

basbebe commented Jan 6, 2021

extensive console control would also be great, then software like nnn or kakoune could make use of it in the future like they do now with iTerm, kitty and tmux.

@wez
Copy link
Owner

wez commented Jan 6, 2021

@basbebe since I don't use those tools, I don't know what sorts of features should be prioritized. I'd appreciate it if you could identify the key things that would help unlock those workflows here in the wezterm issue tracker so that I can prioritize.

What I mean by that is: eg: tmux has lots of functions and commands, so literally saying something like "more functions like tmux" doesn't help me figure out which are the top 5 (for example) functions that make it possible to enable a feature in some other tool, so I'd love concrete feedback on that!

Regarding this particular issue: the title talks about creating a tab, but the example was using panes. Current master (as of about a week ago) now supports running wezterm cli split-pane even if you haven't explicitly configured a mux server, so that part of this issue is "done". split-pane has parameters to set the current working directory (but inherits it from the pane that it is run in) and spawn a specific command.

@prabirshrestha what is left to do before you'd consider this closed?

@basbebe
Copy link

basbebe commented Jan 6, 2021

@wez sorry for not being more specific.

kakoune is an extensible modal texteditor that enables e.g. opening a new terminal pane or a REPL (or a fzf window or nnn or…) next to the editor. It doesn't do this within it's own window like vim but relies on the terminal or a multiplexer.

see https://github.com/mawww/kakoune/blob/600be827b378444ed548492328a041a0b5154a70/rc/windowing/kitty.kak

it therefore needs to open a new pane in the current window and execute a given command in it. It also offers the possibility to focus a given client (pane).

nnn is a file manager which has a few plugins, one of which is called preview-tui.
Here, a new pane is being opened to run a script to show a preview of the currently selected item. When the new pane is being opened, the focus stays within the first pane.

So I think most of the needed functionality probably would now be there.

@prabirshrestha
Copy link
Author

Panes were not supported when I filed this issue hence I mentioned new tabs. I personally prefer opening in new pane.

I will try this on weekend.

@wez wondering if you have instead thought of running lua script instead adding these new commands to console. This way instead of adding new commands you get the full lua api support.

$ wezterm --run "wezterm.newtab()"

@prabirshrestha
Copy link
Author

Finally got time to work on this. Sent a pr to vim-gtfo at justinmk/vim-gtfo#55.

I'm closing this for now.

@SuperSandro2000
Copy link
Contributor

Regarding detection, wezterm sets TERM_PROGRAM=WezTerm in the environment.

That does not work over ssh or in WSL without extra work and TERM is a special variable which is treated special by a lot of software. So this should only be used as a fallback and not by default.

@wez
Copy link
Owner

wez commented Jul 16, 2021

How about we have wezterm set or otherwise update WSLENV to include something like TERM:TERM_PROGRAM:TERM_PROGRAM_VERSION if it looks like it is running on windows or inside wsl?

@SuperSandro2000
Copy link
Contributor

I think that would be a good idea.

wez added a commit that referenced this issue Jul 19, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2023

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants