There is a way to add this function to
When you try to "run" file bash will emit
command not found error :
bash: 1.pdf: command not found
After that it will also emit
ERR "signal". Using buildin
trap you can catch this type of signal and define function that will handle error.
On that page you can find script that will handle that error (read also explanation).
Script is well commented so it shouldn't be a problem to modify it to your needs.
ERR it checks error code of last command. If it is error 2, 126 or 127 it will continue. In next step it will check last command and split it into command part and arguments.
if..fi "handle possible errors involving forgetting a leading slash", so you can remove it.
On the begging of next
if statement there is a check if your command is a directory, so it also could be removed. More interesting is second part of that
if - script checks filetype and print some suggestions how to open that type of file. Instead of that you can just put something like
open $cmd or
APPLICATION_TO_OPEN_PDF $cmd (of course you need to add check if file is PDF).
If you want to use that function you should rather use
APPLICATION_TO_OPEN_PDF $cmd than
open $cmd. You should also set action for specific filetypes and not use open or exec on all type of files to avoid running some malicious script or something like that.
There is also another way to do this, but I think it could cause some problems, because it is more intrusive.
You could redefine function
command_not_found_handle() and put there that checks and
opens. That will cause that there will be no error messages, but I'm not sure what it will do with error codes and messages in cases that you don't want to handle.