mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 09:20:10 +08:00
fb7c8c4064
Previously this would only ever insert sudo if it took a commandline from history, not remove it. So you would end up with sudo sudo apt install
20 lines
600 B
Fish
20 lines
600 B
Fish
function __fish_prepend_sudo -d "Prepend 'sudo ' to the beginning of the current commandline"
|
|
# 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
|
|
|
|
set -l cmd (commandline -po)
|
|
set -l cursor (commandline -C)
|
|
|
|
if test "$cmd[1]" != sudo
|
|
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
|