mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 18:50:29 +01:00
We need to escape spaces and quotes in connection names, so that a connection name containing spaces (quotes) is regarded as a single argument by bash. See e.g. http://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion https://bugzilla.redhat.com/show_bug.cgi?id=1041901 https://bugzilla.gnome.org/show_bug.cgi?id=709426
This commit is contained in:
parent
05b5577815
commit
b911d663d8
1 changed files with 30 additions and 0 deletions
|
|
@ -11,6 +11,36 @@ _nmcli_list_nl()
|
|||
{
|
||||
local IFS=$'\n'
|
||||
COMPREPLY=( $( compgen -W '$1' -- $cur ) )
|
||||
|
||||
# Now escape special characters (spaces, single and double quotes),
|
||||
# so that the argument is really regarded a single argument by bash.
|
||||
# See http://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion
|
||||
local escaped_single_quote="'\''"
|
||||
local i=0
|
||||
local entry
|
||||
for entry in ${COMPREPLY[*]}
|
||||
do
|
||||
if [[ "${cur:0:1}" == "'" ]]; then
|
||||
# started with single quote, escaping only other single quotes
|
||||
# [']bla'bla"bla\bla bla --> [']bla'\''bla"bla\bla bla
|
||||
COMPREPLY[$i]="${entry//\'/${escaped_single_quote}}"
|
||||
elif [[ "${cur:0:1}" == '"' ]]; then
|
||||
# started with double quote, escaping all double quotes and all backslashes
|
||||
# ["]bla'bla"bla\bla bla --> ["]bla'bla\"bla\\bla bla
|
||||
entry="${entry//\\/\\\\}"
|
||||
entry="${entry//\"/\\\"}"
|
||||
COMPREPLY[$i]="$entry"
|
||||
else
|
||||
# no quotes in front, escaping _everything_
|
||||
# [ ]bla'bla"bla\bla bla --> [ ]bla\'bla\"bla\\bla\ bla
|
||||
entry="${entry//\\/\\\\}"
|
||||
entry="${entry//\'/\'}"
|
||||
entry="${entry//\"/\\\"}"
|
||||
entry="${entry// /\\ }"
|
||||
COMPREPLY[$i]="$entry"
|
||||
fi
|
||||
(( i++ ))
|
||||
done
|
||||
}
|
||||
|
||||
_nmcli_con_show()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue