wez / wezterm

A GPU-accelerated cross-platform terminal emulator and multiplexer written by @wez and implemented in Rust
https://wezfurlong.org/wezterm/
Other
16.72k stars 749 forks source link

detecting wezterm and calling create tab from console #230

Closed prabirshrestha closed 3 years ago

prabirshrestha commented 4 years ago

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 https://github.com/wez/wezterm/issues/157 is implemented.

wez commented 4 years ago

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:

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 commented 3 years ago

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
basbebe commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

Finally got time to work on this. Sent a pr to vim-gtfo at https://github.com/justinmk/vim-gtfo/pull/55.

I'm closing this for now.

SuperSandro2000 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

I think that would be a good idea.

github-actions[bot] commented 1 year ago

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.