Don't open relative files in fuzzy_url with :open

With most actions which use fuzzy_url (:open/quickmarks/etc.) it's rather
confusing when relative files are opened - the only place where they should be
opened is when we're processing a commandline argument.
This commit is contained in:
Florian Bruhin 2015-02-01 23:55:37 +01:00
parent 9b1729c77e
commit 59a11c178f
2 changed files with 13 additions and 6 deletions

View File

@ -330,7 +330,7 @@ class Application(QApplication):
window=win_id)
log.init.debug("Startup URL {}".format(cmd))
try:
url = urlutils.fuzzy_url(cmd, cwd)
url = urlutils.fuzzy_url(cmd, cwd, relative=True)
except urlutils.FuzzyUrlError as e:
message.error(0, "Error in startup argument '{}': "
"{}".format(cmd, e))

View File

@ -123,23 +123,30 @@ def _is_url_dns(url):
return not info.error()
def fuzzy_url(urlstr, cwd=None):
def fuzzy_url(urlstr, cwd=None, relative=False):
"""Get a QUrl based on an user input which is URL or search term.
Args:
urlstr: URL to load as a string.
cwd: The current working directory, or None.
relative: Whether to resolve relative files.
Return:
A target QUrl to a searchpage or the original URL.
"""
if cwd:
path = os.path.join(cwd, os.path.expanduser(urlstr))
else:
expanded = os.path.expanduser(urlstr)
if relative and cwd:
path = os.path.join(cwd, expanded)
elif relative:
try:
path = os.path.abspath(os.path.expanduser(urlstr))
path = os.path.abspath(expanded)
except OSError:
path = None
elif os.path.isabs(expanded):
path = expanded
else:
path = None
stripped = urlstr.strip()
if path is not None and os.path.exists(path):
log.url.debug("URL is a local file")