After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 709426 - nmcli bash completion does not work correctly with special characters/whitespace
nmcli bash completion does not work correctly with special characters/whitespace
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: nmcli
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
: 729454 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2013-10-04 12:03 UTC by Thomas Haller
Modified: 2014-05-03 12:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] enhance bash completion for connection names (2.34 KB, patch)
2014-04-14 11:14 UTC, Jiri Klimes
reviewed Details | Review
fixup! patch to 0001-cli-bash-completion-escape-spaces-in-profile-names-r.patch (1.80 KB, patch)
2014-04-14 13:33 UTC, Thomas Haller
none Details | Review
[PATCH] enhance bash completion for connection names (2.42 KB, patch)
2014-04-15 14:28 UTC, Jiri Klimes
none Details | Review

Description Thomas Haller 2013-10-04 12:03:09 UTC
bash completion for nmcli with names that contains spaces does not work as expected.

Assuming you have a connection name "Wireless Connection 1"
See how the following cases fail:

$ nmcli c show configured id Wir<TAB>
$ nmcli c show configured id Wireless\ <TAB>
$ nmcli c show configured id W'<TAB>

Notice, that in standard bash this works correctly and as you would expect.


Basically, _nmcli_list_nl does not work correctly. I don't know how to fix it. Anyone?
Comment 1 Jiri Klimes 2014-04-14 11:14:07 UTC
Created attachment 274256 [details] [review]
[PATCH] enhance bash completion for connection names

This patch fixes handling of connection names with spaces and quotes in the name.
Comment 2 Dan Winship 2014-04-14 13:11:27 UTC
Comment on attachment 274256 [details] [review]
[PATCH] enhance bash completion for connection names

> See e.g. http://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion

Did you try the simpler version further down the page?

>+    local escaped_single_qoute="'\''"

typo "qoute" (and where it's used below).

Although, I don't think it needs that variable anyway... it seems like if you just replace the "\" with "\\" then you should be able to have the substitution be inline just like in the double-quote case.
Comment 3 Thomas Haller 2014-04-14 13:33:09 UTC
Created attachment 274267 [details] [review]
fixup! patch to 0001-cli-bash-completion-escape-spaces-in-profile-names-r.patch

It improves the situation a lot, great.

I would however apply the attached fixup!, because otherwise the syntax highlighting in VI got confused (at least for me).



Things that still don't work are like
  nmcli connection show "W"ired\ Conn<TAB>
results in 
  nmcli connection show Wired Connection 1


anyway, it does improve a lot...
Comment 4 Jiri Klimes 2014-04-15 14:27:35 UTC
(In reply to comment #2)
> (From update of attachment 274256 [details] [review])
> > See e.g. http://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion
> 
> Did you try the simpler version further down the page?
> 
I tried with printf "%q\n". It solves some case, but not all. So it is not sufficient itself.

> >+    local escaped_single_qoute="'\''"
> 
> typo "qoute" (and where it's used below).
> 
> Although, I don't think it needs that variable anyway... it seems like if you
> just replace the "\" with "\\" then you should be able to have the substitution
> be inline just like in the double-quote case.

I fixed the typo. But, I prefer to have the variable there for readability, because putting the literal value makes the forest of slashes and quotes worse.

(In reply to comment #3)
> Created an attachment (id=274267) [details] [review]
> fixup! patch to 0001-cli-bash-completion-escape-spaces-in-profile-names-r.patch
> 

Squashed.
Comment 5 Jiri Klimes 2014-04-15 14:28:27 UTC
Created attachment 274371 [details] [review]
[PATCH] enhance bash completion for connection names
Comment 6 Jiri Klimes 2014-04-15 14:34:46 UTC
Patch in comment #5 pushed to master as
b911d66 cli/bash-completion: escape spaces in profile names (rh #1041901) (bgo #709426)
Comment 7 Igor Gnatenko 2014-05-03 12:20:04 UTC
*** Bug 729454 has been marked as a duplicate of this bug. ***
Comment 8 Igor Gnatenko 2014-05-03 12:23:10 UTC
Could you also apply this patch for Fedora 20?