I'm trying to implement a way to put back the previous command in case of an error in Fish. However the following always results in an empty command line.
function __process_last_cmd -e fish_postexec
set -lx error $status
set -lx cmd (commandline)
if test $error -ne 0
commandline $cmd
end
# history delete -C --exact $cmd
end
(There is also a secondary operation where the command is de-duped from history, which I've left in the code in case it's relevant.)
The fish_postexec
event is documented to provide the command line to the function as the first argument, so use
set -l cmd $argv[1]