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