Avoid showing standard command not found message when possible

In bash, command-not-found handler causes the standard messages to
not appear. Because of events model in fish, it isn't really an
option, so I moved the standard command not found message to
fish function. This way, the messages aren't repeated, and the
standard command not found message appears only when handler
couldn't be found.
This commit is contained in:
Konrad Borowski 2013-07-17 13:41:57 +02:00
parent 0b8f7d4fe7
commit db34460bb5
2 changed files with 20 additions and 14 deletions

View file

@ -2027,6 +2027,7 @@ int parser_t::parse_job(process_t *p,
for this, used by other shells like bash for this, used by other shells like bash
and zsh). and zsh).
*/ */
if (wcschr(cmd, L'=')) if (wcschr(cmd, L'='))
{ {
wchar_t *cpy = wcsdup(cmd); wchar_t *cpy = wcsdup(cmd);
@ -2076,9 +2077,15 @@ int parser_t::parse_job(process_t *p,
} }
else else
{ {
debug(0, /*
_(L"Unknown command '%ls'"), Handle unrecognized commands with standard
cmd?cmd:L"UNKNOWN"); command not found handler that can make better
error messages
*/
wcstring_list_t event_args;
event_args.push_back(args.at(0).completion);
event_fire_generic(L"fish_command_not_found", &event_args);
} }
tmp = current_tokenizer_pos; tmp = current_tokenizer_pos;
@ -2090,9 +2097,6 @@ int parser_t::parse_job(process_t *p,
job_set_flag(j, JOB_SKIP, 1); job_set_flag(j, JOB_SKIP, 1);
wcstring_list_t event_args;
event_args.push_back(args.at(0).completion);
event_fire_generic(L"fish_command_not_found", &event_args);
proc_set_last_status(err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE); proc_set_last_status(err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE);
} }
} }

View file

@ -224,15 +224,17 @@ function __fish_config_interactive -d "Initializations that should be performed
function fish_command_not_found_handler --on-event fish_command_not_found function fish_command_not_found_handler --on-event fish_command_not_found
/usr/lib/command-not-found $argv /usr/lib/command-not-found $argv
end end
fish_command_not_found_handler $argv
else
# Ubuntu Feisty places this command in the regular path instead # Ubuntu Feisty places this command in the regular path instead
if type -p command-not-found > /dev/null 2> /dev/null else if type -p command-not-found > /dev/null 2> /dev/null
function fish_command_not_found_handler --on-event fish_command_not_found function fish_command_not_found_handler --on-event fish_command_not_found
command-not-found $argv command-not-found $argv
end end
# Use standard fish command not found handler otherwise
else
function __fish_command_not_found_handler --on-event fish_command_not_found
echo fish: Unknown command "'$argv'" >&2
end
end
fish_command_not_found_handler $argv fish_command_not_found_handler $argv
end end
end
end
end end