2019-09-26 00:34:54 +08:00
|
|
|
function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline"
|
2020-05-17 17:15:15 +08:00
|
|
|
set -l cmd (commandline -po)
|
|
|
|
set -l cursor (commandline -C)
|
2020-06-05 00:25:02 +08:00
|
|
|
if test -z "$cmd"
|
|
|
|
commandline -r "sudo $history[1]"
|
|
|
|
else if test "$cmd[1]" != sudo
|
2019-09-26 00:34:54 +08:00
|
|
|
commandline -C 0
|
|
|
|
commandline -i "sudo "
|
2020-01-27 18:32:50 +08:00
|
|
|
commandline -C (math $cursor + 5)
|
2020-05-17 17:15:15 +08:00
|
|
|
else
|
|
|
|
commandline -r (string sub --start=6 (commandline -p))
|
|
|
|
commandline -C -- (math $cursor - 5)
|
2019-09-26 00:34:54 +08:00
|
|
|
end
|
|
|
|
end
|