URLs are treated as containing subdirectories. E.g. see this:
$ command_not_found_handle() { echo "OK"; }
$ aaa
OK
$ aaa/bbb
bash: aaa/bbb: No such file or directory
$
That is, it works when you run a command, but then when you run a command with a slash, it likely tries to do bbb
in folder aaa
. The same happens with URLs - it considers it running the command www.google.com
within the directory http:
.
From the bash man page:
If the name is neither a shell function nor a builtin, and
contains no slashes, bash searches each element of the PATH for a
directory containing an executable
file by that name. Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS
below). A full search of the
directories in PATH is performed only if the command is not found in the hash table. If the search is unsuccessful, the shell
searches for a defined shell func‐
tion named command_not_found_handle. If that function exists, it is invoked with the original command and the original command's
arguments as its arguments, and
the function's exit status becomes the exit status of the shell. If that function is not defined, the shell prints an error
message and returns an exit status of
127.
Emphasis mine.
command_not_found_handle
only triggers for PATH lookups, and a URL doesn't trigger a PATH lookup. I think you'd have to patch bash (though maybe you can do something with a debug trap).