I know that xdg-open
will open from terminal a file in the user's preferred application like this:
xdg-open filename
But I wonder how can I open a file from the current directory in its default application only by typing:
filename
followed by Enter, of course. Nothing more.
Use Ubuntu's
command-not-found
hook, as specified in Command Not Found Magic. It is currently used to suggest packages to install. Refer to/usr/share/doc/command-not-found/README
which should be installed on your system.Better yet, because it does not depend on the
command-not-found
package, (re)implement the Bash builtincommand_not_found_handle
to do anxdg-open
if$1
is an existing file, and to delegate all other cases to the previous implementation.Good question, nifty feature.
Thinking it over some more: you might not like the feature as much as you think, unless you also extend the
bash_completion
handler. Imagine wanting to openfile-with-a-long-name.txt
, then settingwill make (about) four key presses suffice:
Whereas typing the full file name takes a tedious 26 - and that excludes backspacing over the inevitable typos.