zellij-org / zellij

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

Changing the keybindings for plugins like session-manager #3485

Closed AlexanderWatts closed 2 months ago

AlexanderWatts commented 2 months ago

Is there a way that the keybindings for a plugin like session-manager can be customised like the bindings for different modes? For example, in the session-manager I'd like to delete a single session by doing Ctrl-x instead of Del which does not exist on my keyboard.

I believe these are fixed from looking at https://github.com/zellij-org/zellij/blob/main/default-plugins/session-manager/src/main.rs lines 338

BareKey::Delete if key.has_no_modifiers() => {
    if let Some(selected_session_name) = self.sessions.get_selected_session_name() {
        kill_sessions(&[selected_session_name]);
        self.reset_selected_index();
        self.search_term.clear();
        self.sessions
            .update_search_term(&self.search_term, &self.colors);
    } else {
        self.show_error("Must select session before killing it.");
    }
    should_render = true;
},
BareKey::Char('d') if key.has_modifiers(&[KeyModifier::Ctrl]) => {
    let all_other_sessions = self.sessions.all_other_sessions();
    if all_other_sessions.is_empty() {
        self.show_error("No other sessions to kill. Quit to kill the current one.");
    } else {
        self.show_kill_all_sessions_warning = true;
    }
    should_render = true;
},
BareKey::Char('x') if key.has_modifiers(&[KeyModifier::Ctrl]) => {
    disconnect_other_clients()
},

I think it'd be super useful if these could be set via the config something like...

    session {
        bind "Ctrl o" { SwitchToMode "Normal"; }
        bind "Ctrl s" { SwitchToMode "Scroll"; }
        bind "d" { Detach; }
        bind "w" {
            LaunchOrFocusPlugin "session-manager" {
                floating true
                move_to_focused_tab true
                keybinds {
            bind "x" { Delete; }
        }
            };
            SwitchToMode "Normal"
        }
    }
imsnif commented 2 months ago

The best way to change these bindings is by forking the plugins and either changing the hard-coded bindings or creating a plugin that offers this config option.

These are not provided as a built-in option in order to help alleviate the burden of maintenance, while still allowing users the option to customize these if they like (albeit with a little more effort).

AlexanderWatts commented 2 months ago

@imsnif thanks for the response, I will update these values by forking the plugin much appreciated πŸ™Œ

nov1n commented 2 months ago

@imsnif thanks for the response, I will update these values by forking the plugin much appreciated πŸ™Œ

@AlexanderWatts Are you planning to make these values configurable from the keymap file as you suggested? I think there are more people interested in this (including me). If not, I'll have a look myself.

imsnif commented 2 months ago

If one of you (or anyone else ofc) makes a configurable plugin out of this, we'd be happy to link to it in awesome-zellij.

AlexanderWatts commented 2 months ago

Heya @nov1n I can certainly have a look πŸ˜€ I was able to update the bindings manually and will look at getting those options from the config which you can see in zellij-utils/src/kdl/mod.rs

nov1n commented 2 months ago

Very nice! Let me know when you have something usable.