kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
23.61k stars 952 forks source link

kitty as a tmux replacement #2422

Closed devth closed 4 years ago

devth commented 4 years ago

Context

I've been using kitty casually for about a year. I previously used tmux + tmuxinator + vim + zsh as my IDE. Though I love tmux's functionality, it is insanely slow on macOS for some reason that no one seems to be able to figure out; I had to abandon it.

Last year's experiment was to see if I could replace tmux with neovim and its terminal support. This worked fairly well but had some bugs and downsides so I'm re-evaluating. I tried tmux again: it's still incredibly slow. Then I realized kitty has a lot of the features I'm after and am now on a quest to see how closely it can resemble my old amazing (but slow) tmux/tmuxinator setup.

  1. Using kitty tabs for multiple instances of vim+terminals for a single "project". For example, an open source chat bot I work on, Yetibot, might have 3 tabs for different components of the project like this (actually it has a lot more than 3 tabs):

    image
  2. Using kitty sessions per project. So I'll have a session for Yetibot that might look like:

    new_tab yetibot
    cd ~/oss/yetibot
    title vim
    launch zsh -c 'nvim .'
    title left
    launch zsh
    enabled_layouts fat:bias=80
    layout fat
    title right
    launch zsh -c 'iced repl; zsh -i'
    
    new_tab yetibot.core
    cd ~/oss/yetibot.core
    launch zsh -c 'nvim .'
    title left
    launch zsh
    title right
    launch zsh
    
    new_tab yetibot-public
    cd ~/Dropbox/yetibot/
    launch zsh -c 'nvim .'
    title left
    launch zsh
    title right
    launch zsh

    and another project would have its own multi-tab config. This is a super nice and flexible way to be able to hack on a project with all related components, terminals, and automation setup.

  3. An important part of my IDE is the ability to send keys from vim to a terminal. I usually like to have 2 terminals and an editor on every tab. 1 term might run a repl and the other's available for everything else. Currently I hacked together a vimscript thing (despite using vim for over a decade I can't vimscript):

    function! TerminalH()
     let line=getline('.')
     execute "Spawn! kitty @ send-text --match title:left ".line."\r"
    endfunction
    
    nnoremap <leader>twh :call TerminalH()<cr>

Questions

Main things I'm missing and still trying to figure are:

  1. Quickly launching new sessions

    I did a zsh thing to help:

    function kits() {
     query=$@
     kitty \
       --session ~/.dotfiles/config/kitty/${query}.conf \
       --start-as fullscreen \
       --title {query} \
       --listen-on unix:/tmp/kitty-${query}
    }

    But this results in an active process in the terminal that launched it:

    image

    I want to be able to launch new sessions from anywhere without imparting a parent/child relationship or seeing log output of the session.

  2. Quickly switching between running sessions

    tmux had a built in session switcher utility which I could map to a hotkey. It looked something like this:

    In kitty, every time I launch a session I end up with another unidentifiable kitty instance which turns my app switcher menu into something like this:

    Screen Shot 2020-03-09 at 11 20 19 AM

    Is there a better way? I very much liked the tmux session switcher.

Thanks

Thank you for this amazing project. After recently diving much more in depth to the issues and docs I'm thoroughly impressed with kitty's capabilities. And best of all, it's blazing fast. ⚡️

This is possibly related to https://github.com/kovidgoyal/kitty/issues/391

kovidgoyal commented 4 years ago

Well macOS makes things difficult. But lets see what we can do. For (1) simply add 2>&1 >/dev/null & to the command line.

For (2) I would suggest using a more powerful window manager such as chunkWM or similar and putting your kitty sessions on individual workspaces (this is how I personally work in linux). However, another possibility is to use the kitty remote control protocol to switch sessions. You will need to write a small script that runs kitty @ ls lists out the windows, asks the user for their choice and then runs kitty @ focus-window chosen-id

Feel free to post if you have more questions.

devth commented 4 years ago

Great idea, I'll play with remote control. Thanks!

kovidgoyal commented 4 years ago

Oh and for (2) you would be even better of writing a custom kitten, that way no need to even bother with remote control. https://sw.kovidgoyal.net/kitty/kittens/custom.html

devth commented 4 years ago

It's not possible to set the title of the kitty window to be something other than kitty, right? I'm guessing that's an OS level thing.

kovidgoyal commented 4 years ago

kitty --title sets the window title, but the macOS switcher probably wont use it.

kovidgoyal commented 4 years ago

Oh and the simplest thing for you to do is to have only a single instance of kitty with multiple top level OS windows and switch between them with cmd+`

devth commented 4 years ago

kitty --title sets the window title, but the macOS switcher probably wont use it.

Right, macOS switcher does not use it

Oh and the simplest thing for you to do is to have only a single instance of kitty

For some reason this does not work if I create the window with my zsh helper:

function kits() {
  session=$@
  kitty \
    --session ~/.dotfiles/config/kitty/session/${session}.conf \
    --start-as fullscreen \
    --title {session} \
    --listen-on unix:/tmp/kitty-${session} \
    </dev/null &>/dev/null &
}

Instead this creates a whole new instance of kitty. But If i simply use cmd+n to create a new window, then it does not create a new instance, which is desirable. Can remote control create a new window with a session?

kovidgoyal commented 4 years ago

On Tue, Mar 10, 2020 at 11:08:56AM -0700, Trevor Hartman wrote:

Oh and the simplest thing for you to do is to have only a single instance of kitty

For some reason this does not work if I create the window with my zsh helper:

function kits() {
  session=$@
  kitty \
    --session ~/.dotfiles/config/kitty/session/${session}.conf \
    --start-as fullscreen \
    --title {session} \
    --listen-on unix:/tmp/kitty-${session} \
    </dev/null &>/dev/null &
}

Instead this creates a whole new instance of kitty. But If i simply use cmd+n to create a new window, then it does not create a new instance, which is desirable. Can remote control create a new window with a session?

yes it can, though not with a session file, but every command in the session file has its remote control equivalent, so use thos edirectly in a script.

kovidgoyal commented 4 years ago

Ang you dot need to use remote control for this either. Just use --single-instance

guysherman commented 2 years ago

I stumbled on this thread a little while back, as I was also interested in the session switcher functionality of tmux. Anyway, I started building a thing: https://github.com/guysherman/kittymux

kimlai commented 1 year ago

Since this thread still comes up in the first results when searching for "tmux sessions in kitty", I thought I'd share what I've come up with. Following @kovidgoyal's recommendations I used custom kittens, with os windows treated as sessions.

By default sessions are numbered starting from 0, but you can assign them a name like in tmux, and you can switch between sessions using the following UI:

Screenshot 2023-04-25 at 19 14 16

The implementation is quite rough and tailored to my workflow (I don't need feature parity with the original tmux session switcher), but I've been using it for a week and I don't miss tmux anymore. If anybody's interested the code is here, with the relevant parts being

Session names are kept in ~/.kitty-sessions.json, and I use the following session file to clear old session names when kitty starts:

launch sh -c "echo '{}' > $HOME/.kitty-sessions.json"
new_os_window
focus_os_window
mambusskruj commented 5 months ago

@kimlai thank you for custom kittens ❤️ It helped me to replace tmux workflow completely.

One thing I still missing though is fuzzy search in the session switcher. Maybe one day I will implement it and share it with you : )