GNOME Bugzilla – Bug 751145
Bash completion doesn't work for uris
Last modified: 2018-09-21 17:50:30 UTC
Bash completion doesn't work as expected for uris, because bash breaks paths on colons. So e.g. "gvfs-cat file:///<TAB>" invokes "gvfs-ls -c ///" which is utterly wrong. So it somehow works for local paths, but not for remote uris... I've been convinced it was working correctly before some time, but it seems this was caused by the following (6 years old!) commit: commit e71622dd0fc658fc3241b6bbf903fa3663ea0ebb
Created attachment 305527 [details] [review] Fix completion for uris Bash completion works almost correctly with the attached patch (path is completed correctly), however the printed suggestions are without uri (colon prefix) and I have no idea how to print whole paths (or basenames)... gvfs-ls file:///<tab> ///sbin/ ///bin/ ... Do you have some ideas?
Created attachment 305528 [details] [review] Use __ltrim_colon_completions Use macro __ltrim_colon_completions to remove colon prefix instead of custom code.
Created attachment 305529 [details] [review] Complete mounts with terminating slash Some type of mounts don't have terminating slash. E.g. LUKS encrypted device mounts appear currently as: file:///var/run/DEVICE We have to be sure that terminating slash is appended for mounts when listing possible completions, because mounts are always directories.
Created attachment 305530 [details] [review] Complete local uris as uris gvfs-ls suggests completions for file:// uris as absolute paths, but it should be also uris. E.g. gvfs-ls -c file:/// /bin/ /lib/ ... It should be file:///bin/ etc. instead.
Review of attachment 305528 [details] [review]: ::: programs/completion/gvfs-cat @@ +33,3 @@ # don't misbehave on colons; See item E13 at http://tiswww.case.edu/php/chet/bash/FAQ # We handle this locally be extracting any BLAH: prefix and removing it from the result. # Not great, but better than globally changing COMP_WORDBREAKS Shouldn't this comment be updated?
Review of attachment 305529 [details] [review]: Would it not be better to ensure that all mounts are consistent correctly rather than working around it here?
Review of attachment 305530 [details] [review]: Looks good!
Review of attachment 305529 [details] [review]: I think the patch is ok, but the commit message should be updated. The uri comes from GFile: uri = g_file_get_uri (mount_root); and therefore the terminating slash isn't preserved in paths... sftp://localhost/ -> sftp://localhost/ sftp://localhost/mydir/ -> sftp://localhost/mydir
Review of attachment 305529 [details] [review]: OK, that's good with an updated commit message.
Review of attachment 305527 [details] [review]: I don't really know how bash-completion works but it looks harmless and if it fixes the problem...
Created attachment 305988 [details] [review] Complete mounts with terminating slash Updated description...
(In reply to Ross Lagerwall from comment #5) > Review of attachment 305528 [details] [review] [review]: > > ::: programs/completion/gvfs-cat > @@ +33,3 @@ > # don't misbehave on colons; See item E13 at > http://tiswww.case.edu/php/chet/bash/FAQ > # We handle this locally be extracting any BLAH: prefix and removing it > from the result. > # Not great, but better than globally changing COMP_WORDBREAKS > > Shouldn't this comment be updated? The macro do exactly what the comment says, so I don't think it is necessary to update it...
I am trying to find better solution in cooperation with fedora bash maintainers, so I am waiting before pushing the attachment 305527 [details] [review].
Review of attachment 305988 [details] [review]: Look good!
(In reply to Ondrej Holy from comment #12) > (In reply to Ross Lagerwall from comment #5) > > Review of attachment 305528 [details] [review] [review] [review]: > > > > ::: programs/completion/gvfs-cat > > @@ +33,3 @@ > > # don't misbehave on colons; See item E13 at > > http://tiswww.case.edu/php/chet/bash/FAQ > > # We handle this locally be extracting any BLAH: prefix and removing it > > from the result. > > # Not great, but better than globally changing COMP_WORDBREAKS > > > > Shouldn't this comment be updated? > > The macro do exactly what the comment says, so I don't think it is necessary > to update it... When it says "We handle this locally...", it suggests that the code in completion/gvfs-cat is extracting the prefix, etc, when it is actually the macro that is doing it. Perhaps it could be changed to: The macro below handles this by extracting any BLAH: prefix and removing it from the result.
Created attachment 307079 [details] [review] Use __ltrim_colon_completions Modified comment as per review.
Created attachment 307080 [details] [review] Always complete mounts Completions are not printed if path is without terminating slash and it is equal with mount, e.g.: gvfs-ls -c sftp://1.2.3.4 However following should be offered for example: sftp://1.2.3.4/ sftp://1.2.3.44/
Created attachment 307081 [details] [review] Workaround to show suggestions with colon prefixes Suggested files are printed without colon prefix currently, e.g.: gvfs-ls file:///<tab> ///bin/ ///boot/ ... We know that suggestions are printed only if result contains more then one file. So do not remove the colon prefix in such cases as a workaround. One empty suggestion has to be added to avoid bash completion to change the current word. So after the patch: gvfs-ls file:///<tab> file:///bin/ file:///boot/ ...
(In reply to Ondrej Holy from comment #13) > I am trying to find better solution in cooperation with fedora bash > maintainers, so I am waiting before pushing the attachment 305527 [details] [review] > [review]. Unfortunately we havn't find anything better then the workaround above...
Review of attachment 307079 [details] [review]: Looks good!
Review of attachment 307080 [details] [review]: Looks good!
Review of attachment 307081 [details] [review]: No idea what this does... but if it fixes the problem :-)
(In reply to Ross Lagerwall from comment #22) > Review of attachment 307081 [details] [review] [review]: > > No idea what this does... but if it fixes the problem :-) Thanks for the reviews! However I would be more happy if somebody could test those patches except me. I am surprised that soo many people I've asked do not use bash completion at all (but it is kinda useful if it works IMO)... I will enlarge the comment, but the idea is following. The commandline is completed if there is only one result from gvfs-ls and no suggestions are printed in such case. Suggestions are printed only if there is more then one result from gvfs-ls. However suggestions are printed without the prefixes if we apply the __ltrim_colon_completions macro, but also commandline is wrongly completed if we don't apply the macro. So we add empty suggestion to avoid commandline changing and do not apply the macro if there is more then one result. This will cause that the one additional empty suggestion is printed, but the other suggestions have the correct prefixes...
Review of attachment 307081 [details] [review]: ::: programs/completion/gvfs-cat @@ +31,3 @@ COMPREPLY=($(compgen -W '$(gvfs-ls --show-completions "$cur")' -- "")) + if [[ ${#COMPREPLY[@]} > 1 && "$cur" == *:* ]]; then I've realized that this condition isn't enough. See the following case: $ gvfs-ls localtest:///li<tab> localtest:///lib/ localtest:///lib64/ But it should looks like as follows to allow user specify the first divergent char: $ gvfs-ls localtest:///li<tab> $ gvfs-ls localtest:///lib<tab> localtest:///lib/ localtest:///lib64/ So we have to check, that the results from gvfs-ls don't have common prefix (longer then what we have on commandline)...
Created attachment 309147 [details] [review] completion: Allow bash completion for gvfs-mount It is pretty useful when you want to unmount some specific share.
Created attachment 309148 [details] [review] completion: Workaround to show suggestions with colon prefixes I've improved the workaround as per Comment 24. I've been using it more then week and it looks to be correct...
Comment on attachment 305530 [details] [review] Complete local uris as uris commit 372679bd9aaf427ad6054405f544e92c4a19a5e1
Comment on attachment 305988 [details] [review] Complete mounts with terminating slash commit 8adeb4a187406881de7850ea405dc352e590b255
Comment on attachment 307080 [details] [review] Always complete mounts commit cd07ff485781dbe7923dc88cbb1de424e709a91d
Review of attachment 309148 [details] [review]: I've just realized that also bash-completion for ls command doesn't work properly without escaping of colons... touch a:bc bad ls a:<TAB> -> nothing happend ls a:b<TAB> -> ls a:bad ls a\:<TAB> -> a\:bc bash-completion for gvfs had been working apparently without escaping, so I wanted to fix the previous behavioral. However maybe we should have same behavioral like ls. Thus we don't need _get_comp_words_by_ref, nor __ltrim_colon_completions, nor this patch, but we need to print escaped colons instead... What do you think?
Comment on attachment 305527 [details] [review] Fix completion for uris commit e009e60a3fb2f8fb48d982fe66469c9f16678620
Comment on attachment 307079 [details] [review] Use __ltrim_colon_completions commit 27809fc426d94189629b4eaae10f7080e5b6ea23
Comment on attachment 309147 [details] [review] completion: Allow bash completion for gvfs-mount commit f2b782ae782b67e0c2e0c99f78c3978464596824
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gvfs/issues/256.