2019-09-26 00:34:54 +08:00
|
|
|
function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline"
|
2021-03-27 02:02:20 +08:00
|
|
|
# If there is no commandline, insert the last item from history
|
|
|
|
# and *then* toggle
|
|
|
|
if not commandline | string length -q
|
|
|
|
commandline -r "$history[1]"
|
|
|
|
end
|
|
|
|
|
2020-05-17 17:15:15 +08:00
|
|
|
set -l cmd (commandline -po)
|
|
|
|
set -l cursor (commandline -C)
|
2021-03-27 02:02:20 +08:00
|
|
|
|
|
|
|
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
|