nu: Add sudo toggling key

Toggle sudo prefix for command line with <alt-s>. Not sure if I will
keep this binding in the long run but it is a good example of command
execution using nushell through a key binding.

From: https://github.com/nushell/nushell/discussions/16043
This commit is contained in:
Marty Oehme 2025-10-18 12:58:43 +02:00
parent 56916f90d1
commit c1eb686cd3
Signed by: Marty
GPG key ID: 4E535BC19C61886E

View file

@ -70,6 +70,16 @@ $env.config.keybindings = [
send: OpenEditor
}
}
{
name: toggle_sudo
modifier: alt
keycode: char_s
mode: [emacs vi_insert vi_normal]
event: {
send: executehostcommand
cmd: "let cmd = (commandline); commandline edit (if $cmd starts-with sudo { $cmd | str replace -r '^sudo ' '' } else { 'sudo ' ++ $cmd });"
}
}
{
name: run_zoxide
modifier: alt