-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add local file paths to URL completion #6038
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that turned out to be simpler than I would've imagined, at least code-wise - great work so far, I don't think I'd have managed such a simple implementation!
Not a full review yet, but a couple of things coming to mind apart from the ones already added by the linters:
- Right now, without any input this displays paths relative to the current directory. However, those don't actually work, because
:open
doesn't handle them. It seems to me like it should only be triggered if the input actually is an absolute path? - We're trying to move away from
os.path
/glob.glob
, see Use pathlib #176 - could you please use pathlib instead? - Any particular reason why you didn't add it to the default completion categories? I think once it doesn't display relative paths, it shouldn't be in the way, so why not make it the default?
- It'd be good if this could handle
file:///
URLs as well. - This will need some tests in
tests/unit/completion/test_models.py
(you can use pytest's tmp_path to build a file structure)
This comment has been minimized.
This comment has been minimized.
I'm not sure if the current code works in Windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick changes! I did a full review and added some more comments.
Other than those, I think the only thing missing is the migration to pathlib
(unless you see a good reason to not do that) and tests.
val: The user's partially typed URL/path. | ||
""" | ||
if not val: | ||
self._paths = [os.path.expanduser('~')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of offering the home directory here! A couple of thoughts:
- Should we really expand it, or just display
~
initially? - Are there more useful directories we could add? Perhaps the downloads directory?
- Or should we even offer a config option so the user could add their preferred directories here? That seems like something that could be pretty useful, e.g. for people doing web development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we really expand it, or just display ~ initially?
I'd say just ~
, and do the expansion behind-the-scenes, to keep paths shorter.
offer a config option so the user could add their preferred directories here
I like this idea. It might be worth considering completion.file_path.exclude
too, in case the user has something like an sshfs
that is slow to access (would that hold up the entire completion?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I'd say we should do here whatever we do later. If we can always keep ~
un-expanded (which would be ideal IMHO), we should show ~
here. If that's infeasible, then we should expand here too.
@@ -1141,7 +1141,7 @@ downloads.location.suggestion: | |||
completion.open_categories: | |||
type: | |||
name: FlagList | |||
valid_values: [searchengines, quickmarks, bookmarks, history] | |||
valid_values: [searchengines, quickmarks, bookmarks, history, filesystem] | |||
none_ok: true | |||
default: | |||
- searchengines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add it as a default here (I'd say above searchengines
even) for discoverability?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. Opening files in a browser is pretty rare for me, so it feels off to put it at the top. Still, you probably won't notice this feature unless you see the category or read the release notes, so 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps as a compromise, if we have a completion.filesystem.favorites
(or whatever) setting, we could have that empty by default (i.e., not even including ~
)? Then the (empty) category is hidden when just doing :open
, but still appears when starting to enter an absolute path.
Co-authored-by: Florian Bruhin <me@the-compiler.org>
Co-authored-by: Florian Bruhin <me@the-compiler.org>
Co-authored-by: Florian Bruhin <me@the-compiler.org>
Co-authored-by: Florian Bruhin <me@the-compiler.org>
The semantics should now be implemented. |
There are also some commands taking a filename:
Would you like to add completion for those as well? I think this would be an excellent base for doing so. |
I'll take a look. |
Looks like my fuzzing test (using hypothesis) caught a bug: https://github.com/qutebrowser/qutebrowser/runs/1735417829?check_suite_focus=true#step:8:135 I can't quite explain why it happens, but I now pushed another commit to avoid pathlib entirely and only use os.path, as I suspect that
From what I can see, this seems to have fixed the issue. Weird... |
Awesome, thank you! |
In regards to #32 and #5792
This adds a new completion category for
:open
for local files. URLs starting with ~ work.