- _command(): commands like 'sudo chown' return completions of the form

'user:'. This gets escaped by _chown() and passed back as 'user\:'.
  _command() then escapes this further to 'user\\\:', so we need to unescape it
  to have things work correctly.

  Unfortunately, 'sudo rm' might pass back the name of a file that has a
  backslash followed by a colon in the name, e.g. 'foo\:bar'. This is
  escaped by _command() to 'foo\\\:bar', which we should not unescape.

  How to tell the difference between a completion that contains a backslash
  that is escaping the following character, and one that has literal
  backslashes?

  We extract the '-o <type>' information from the compspec and, if we are
  dealing with a spec that does not specify that it passes back filenames or
  dirnames, we unescape any backslash/colon pairings. Of course, this means
  that 'sudo chown' will still do the wrong thing when dealing with a
  directory or filename that contains '\:'. Oh well...
This commit is contained in:
ianmacd 2002-03-30 18:20:51 +00:00
parent 390a748ed4
commit 443d9bb0f8

View File

@ -1,6 +1,6 @@
# bash_completion - some programmable completion functions for bash 2.05a # bash_completion - some programmable completion functions for bash 2.05a
# #
# $Id: bash_completion,v 1.235 2002/03/29 16:33:08 ianmacd Exp $ # $Id: bash_completion,v 1.236 2002/03/30 19:20:51 ianmacd Exp $
# #
# Copyright (C) Ian Macdonald <ian@caliban.org> # Copyright (C) Ian Macdonald <ian@caliban.org>
# #
@ -1737,6 +1737,15 @@ _command()
# split current command line tokens into array # split current command line tokens into array
COMP_WORDS=( $cline ) COMP_WORDS=( $cline )
$func $cline $func $cline
# remove any \: generated by a command that doesn't
# default to filenames or dirnames (e.g. sudo chown)
if [ "${cspec#*-o }" != "$cspec" ]; then
cspec=${cspec#*-o }
cspec=${cspec%% *}
if [[ "$cspec" != @(dir|file)names ]]; then
COMPREPLY=( "${COMPREPLY[@]//\\\\:/:}" )
fi
fi
elif [ "${cspec#*-[abcdefgjkvu]}" != "$cspec" ]; then elif [ "${cspec#*-[abcdefgjkvu]}" != "$cspec" ]; then
# complete -[abcdefgjkvu] # complete -[abcdefgjkvu]
func=$( echo $cspec | \ func=$( echo $cspec | \