From 0f802eaad8aeb2a10bfb78e88980a5b8ca5c33bb Mon Sep 17 00:00:00 2001 From: Greg Anders Date: Wed, 25 Sep 2019 10:34:54 -0600 Subject: [PATCH] Add default \es keybinding for "prepend sudo" --- share/functions/__fish_prepend_sudo.fish | 8 ++++++++ share/functions/__fish_shared_key_bindings.fish | 3 +++ 2 files changed, 11 insertions(+) create mode 100644 share/functions/__fish_prepend_sudo.fish diff --git a/share/functions/__fish_prepend_sudo.fish b/share/functions/__fish_prepend_sudo.fish new file mode 100644 index 000000000..a696d8ac3 --- /dev/null +++ b/share/functions/__fish_prepend_sudo.fish @@ -0,0 +1,8 @@ +function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline" + set -l cmd (commandline -boc) + if test "$cmd[1]" != "sudo" + commandline -C 0 + commandline -i "sudo " + commandline -f end-of-line + end +end diff --git a/share/functions/__fish_shared_key_bindings.fish b/share/functions/__fish_shared_key_bindings.fish index 331faa508..668f59228 100644 --- a/share/functions/__fish_shared_key_bindings.fish +++ b/share/functions/__fish_shared_key_bindings.fish @@ -93,6 +93,9 @@ function __fish_shared_key_bindings -d "Bindings shared between emacs and vi mod bind --preset $argv \ed 'set -l cmd (commandline); if test -z "$cmd"; echo; dirh; commandline -f repaint; else; commandline -f kill-word; end' bind --preset $argv \cd delete-or-exit + # Prepend 'sudo ' to the current commandline + bind --preset $argv \es __fish_prepend_sudo + # Allow reading manpages by pressing F1 (many GUI applications) or Alt+h (like in zsh). bind --preset $argv -k f1 __fish_man_page bind --preset $argv \eh __fish_man_page