sudo !!
我正在尝试编写一个与 Bash等效的函数。它有效,但仅当最后一个命令没有参数时。
到目前为止,功能是:
function s --description "Run last command (or specified command) using sudo"
if test $argv
switch $argv[1]
case '!!'
command sudo (echo $history[1])
case '*'
command sudo $argv
end
else
command sudo fish
end
end
测试相关线路:
$ command sudo whoami
root
$ whoami
nick
$ command sudo (echo $history[1])
root
到目前为止一切顺利,现在让我们尝试一个带有一些参数的命令:
$ echo hi >> /etc/motd
An error occurred while redirecting file '/etc/motd'
open: Permission denied
$ command sudo (echo $history[1])
sudo: echo hi >> /etc/motd: command not found
嗯,奇怪。