mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.7k stars 705 forks source link

[REQUEST] revert f26d4ea4 for putting tmux into background again #5177

Open Yukaii opened 1 month ago

Yukaii commented 1 month ago

Feature

I actually found running tmux in the background useful when using tools like kks along with tmux popup.

Unlike the description in commit https://github.com/mawww/kakoune/commit/f26d4ea4bfd3f7e43e4e96a790b19cd6e1e8b17f about split-window, tmux display-popup is a long-running process and needs to be put into the background.

People using kakoune with tmux-popup like me can define an old overwrite command for tmux-terminal-impl:

https://github.com/Yukaii/dotfiles/blob/8ec32679c4c154b45b048bc7fca02e38cc5d1ba3/kakoune/.config/kak/tmux.kak#L36-L59

I have defined a custom tmux command called tmux-popup as follows:

define-command tmux-popup -params 1.. -docstring '
tmux-popup <program> [<arguments>]: create a new terminal as a tmux popup
The program passed as an argument will be executed in the new terminal' \
%{
    tmux-terminal-impl "popup -w 90%% -h 80%% -E -d %val{client_env_PWD}" %arg{@}
}
complete-command tmux-popup shell

https://github.com/mawww/kakoune/assets/4230968/559492f7-1981-4993-a3be-82670300496d

Spent some time to get my kks setup working again after this release. 😂

Usecase

Yukaii commented 1 month ago

The other solution might be to create a standalone tmux-popup command that doesn't depend on tmux-terminal-impl. The split-window stays the current behavior, while tmux-popup runs in the background.

krobelus commented 1 month ago

Reverting sounds fine. If we had never added the backgrounding behavior, I'd have doubts about adding it because users can always copy tmux-terminal-impl. But since it already worked, it seems better to keep it working.

Out of curiosity, with tmux-popup, how do you make it so you can focus other tmux windows/panes while the popup is showing? My C-b is being ignored and forwarded to the program running in the popup.

Yukaii commented 1 month ago

how do you make it so you can focus other tmux windows/panes while the popup is showing?

I cannot either 😅. I use popups as disposable windows.

For persistent actions like a floating terminal or keeping a lazygit process open, I actually wrote a script to create and automatically attach another tmux session on a popup display.

https://github.com/Yukaii/dotfiles/tree/macos-m3/bin#tmux-popup

Demo

https://github.com/mawww/kakoune/assets/4230968/73f888a2-9f9b-41b0-9d6f-af67e88420b1

krobelus commented 1 month ago

Is there a use case where one wants to be notified once the popup is closed? I guess there are but probably not so important

krobelus commented 1 month ago

something like

tmux-terminal-impl display-popup -E -E sh -c 'sleep 1; date >/tmp/result'
echo %file{/tmp/result}

I guess that's a rare use case, especially given we can't pass $kak_command_fifo to tmux-terminal-impl args

Yukaii commented 1 month ago

Is there a use case where one wants to be notified once the popup is closed? I guess there are but probably not so important

Maybe a non-windowing command like tmux list-session? For me, since tmux-terminal-impl is specifically implemented for windowing commands, vertical/horizontal/popup should behave in the same way. For other tmux commands, people should use regular shell commands.

krobelus commented 1 month ago

looking closer at tmux-terminal-impl, it seems that it only works properly for the split-* and new-window commands. For other commands, when using multiple tmux sessions, tmux-terminal-impl will operate in the session that created the kak server, not in the session of the calling kak client. (see 0fb99f217 (tmux.kak: use TMUX_PANE for tmux-terminal-{horizontal,vertical}, 2020-07-26)) We want to do something similar for popup.

Since we'll already want popup-specific code we can add backgrounding logic for that case only? I asked on the tmux-users list why "tmux popup" blocks, would be interesting to know.