[Bash-completion-devel] Bug#739835: ~ vs. filename expansion

JuanJo Ciarlante jjo at canonical.com
Tue Mar 11 14:44:04 UTC 2014


Following patch (from this MP[1]) seems to fix it for me - at least for:

1) completion when 1st char is '~'
2) fixing potential double escaping when the argument is already
escaped, eg: cat /tmp/file\ with\ spac<TAB>

------------------------------------------------------------
revno: 46
committer: JuanJo Ciarlante <jjo at canonical.com>
branch nick: bash-completion
timestamp: Tue 2014-03-11 11:27:12 -0300
message:
  [jjo, r=] fix _quote_readline_by_ref to avoid escaping 1st '~', and
re-eval to fix double escaping
diff:
=== modified file 'bash_completion'
--- bash_completion	2013-12-27 01:28:28 +0000
+++ bash_completion	2014-03-11 14:27:12 +0000
@@ -539,6 +539,9 @@
     if [[ $1 == \'* ]]; then
         # Leave out first character
         printf -v $2 %s "${1:1}"
+    elif [[ $1 == ~* ]]; then
+        # avoid escaping first ~
+        printf -v $2 ~%q "${1:1}"
     else
         printf -v $2 %q "$1"
     fi
@@ -547,6 +550,10 @@
     # drop the additional quoting.  See also: http://www.mail-archive.com/
     # bash-completion-devel at lists.alioth.debian.org/msg01942.html
     [[ ${!2} == \$* ]] && eval $2=${!2}
+    # Re-evaluate if result is double escaped, ie contains: \\
+    # This happens always when argument is already escaped at cmdline,
+    # and passed to this function as e.g.: file\ with\ spaces
+    [[ ${!2} == *\\* ]] && eval $2=${!2}
 } # _quote_readline_by_ref()

[1]
https://code.launchpad.net/~jjo/bash-completion/fix-bash43-quote_readline_by_ref-tilde-and-double_escaping/+merge/210421

Cheers,
--JuanJo - http://twitter.com/xjjo - http://bit.ly/jjo-cv



More information about the Bash-completion-devel mailing list