From 443d9bb0f87714cc4f6fce5ceacdfd587992c77c Mon Sep 17 00:00:00 2001 From: ianmacd <> Date: Sat, 30 Mar 2002 18:20:51 +0000 Subject: [PATCH] - _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 ' 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... --- bash_completion | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bash_completion b/bash_completion index ef52f124..4ec8bb9b 100644 --- a/bash_completion +++ b/bash_completion @@ -1,6 +1,6 @@ # 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 # @@ -1737,6 +1737,15 @@ _command() # split current command line tokens into array COMP_WORDS=( $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 # complete -[abcdefgjkvu] func=$( echo $cspec | \