zellij-org / zellij

A terminal workspace with batteries included
https://zellij.dev
MIT License
19.38k stars 610 forks source link

Allow `GoToTab` keybind action to focus on latest tab if passed tab idx doesn't exist #3407

Open cristiand391 opened 3 weeks ago

cristiand391 commented 3 weeks ago

I have the following keybinds to replicate the Alt + tab idx shorcuts available in browsers:

    bind "Alt 1" { GoToTab 1; }
    bind "Alt 2" { GoToTab 2; }
    bind "Alt 3" { GoToTab 3; }
    bind "Alt 4" { GoToTab 4; }
    bind "Alt 5" { GoToTab 5; }
    bind "Alt 6" { GoToTab 6; }
    bind "Alt 7" { GoToTab 7; }
    bind "Alt 8" { GoToTab 8; }
    bind "Alt 9" { GoToTab 9; }

Firefox supports going to the last tab if the tab index doesn't exit. Example:

you have 3 tabs, pressing Alt 8 would fail to find a tab with index 8 so it would focus on the 3rd tab. if you have 9 tabs, Alt 8 would to go the 8th tab.

For me it's mostly a faster way to go to the last tab (I usually have ~5 tabs per session, so Alt 6-9 are free to use if this is supported)

bind "Alt 9" {
  GoToTab 9 {
    default "latest"
  }
}