cli: completion: escape shell special characters "()&!"

https://bugzilla.gnome.org/show_bug.cgi?id=772629
(cherry picked from commit 108f04e71e)
This commit is contained in:
Beniamino Galvani 2016-10-17 15:07:50 +02:00
parent 940cb6eb87
commit c53496fe4a

View file

@ -25,10 +25,11 @@ _nmcli_list_nl()
# [']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
# started with double quote, escaping all double quotes, backslashes and !
# ["]bla'bla"bla\bla bla --> ["]bla'bla\"bla\\bla bla
entry="${entry//\\/\\\\}"
entry="${entry//\"/\\\"}"
entry="${entry//!/\"\\!\"}"
COMPREPLY[$i]="$entry"
else
# no quotes in front, escaping _everything_
@ -37,6 +38,10 @@ _nmcli_list_nl()
entry="${entry//\'/\'}"
entry="${entry//\"/\\\"}"
entry="${entry// /\\ }"
entry="${entry//\(/\\(}"
entry="${entry//)/\\)}"
entry="${entry//!/\\!}"
entry="${entry//&/\\&}"
COMPREPLY[$i]="$entry"
fi
(( i++ ))