From f10de5f6536d35ad89d879d996df02b1fb42d9bb Mon Sep 17 00:00:00 2001 From: Enrico Borba Date: Sun, 17 May 2020 02:15:15 -0700 Subject: [PATCH] __fish_prepend_sudo: Toggle "sudo" on multiple presses (#7012) At the moment calling __fish_prepend_sudo multiple times does not toggle sudo, and also unnecessarily uses the `-c` flag to `commandline` to see if the first token on the commandline is "sudo". This change removes the `-c` switch and also toggles "sudo" on multiple calls to __fish_prepend_sudo, while maintaining the cursor position and while maintaining any spaces between "sudo" and the next token on the commandline. --- share/functions/__fish_prepend_sudo.fish | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_prepend_sudo.fish b/share/functions/__fish_prepend_sudo.fish index 5eafc488e..4f3c6d999 100644 --- a/share/functions/__fish_prepend_sudo.fish +++ b/share/functions/__fish_prepend_sudo.fish @@ -1,9 +1,12 @@ function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline" - set -l cmd (commandline -poc) + set -l cmd (commandline -po) + set -l cursor (commandline -C) if test "$cmd[1]" != sudo - set -l cursor (commandline -C) commandline -C 0 commandline -i "sudo " commandline -C (math $cursor + 5) + else + commandline -r (string sub --start=6 (commandline -p)) + commandline -C -- (math $cursor - 5) end end