[Bash-completion-devel] Bug#498105: bash-completion: Incorrect completion on 'find -n[TAB]' and 'find -ne[TAB]'

Morita Sho morita-pub-en-debian at inz.sakura.ne.jp
Sun Sep 7 06:11:43 UTC 2008


Package: bash-completion
Version: 20080705
Severity: normal
Tags: patch

Hi,

find -n[TAB] and find -ne[TAB] won't work, even though other options that is not begin with '-n' or '-ne' works correctly.

$ find -n[TAB]
=> -amin       -false      -ilname     -mmin       -print      -user
   -anewer     -fls        -iname      -mount      -print0     -version
   -atime      -follow     -inum       -mtime      -printf     -wholename
   -cmin       -fprint     -ipath      -name       -prune      -xdev
   -cnewer     -fprint0    -iregex     -newer      -regex      -xtype
   -ctime      -fprintf    -links      -nogroup    -size       
   -daystart   -fstype     -lname      -noleaf     -true       
   -depth      -gid        -ls         -nouser     -type       
   -empty      -group      -maxdepth   -ok         -uid        
   -exec       -help       -mindepth   -perm       -used
$ find -ne[TAB]
=> -amin       -false      -ilname     -mmin       -print      -user
   -anewer     -fls        -iname      -mount      -print0     -version
   -atime      -follow     -inum       -mtime      -printf     -wholename
   -cmin       -fprint     -ipath      -name       -prune      -xdev
   -cnewer     -fprint0    -iregex     -newer      -regex      -xtype
   -ctime      -fprintf    -links      -nogroup    -size       
   -daystart   -fstype     -lname      -noleaf     -true       
   -depth      -gid        -ls         -nouser     -type       
   -empty      -group      -maxdepth   -ok         -uid        
   -exec       -help       -mindepth   -perm       -used
$ find -new[TAB]
    => -newer

I expected -n[TAB] completes options that begin with -n, but it completes all options...


Besides that, it seems that completions for "-e", "-n", "-ne" or "-en" won't work for every program.

$ mplayer -n[TAB]
     => nothing completes
$ mplayer -e[TAB]
     => nothing completes
$ mplayer -ed[TAB]
     => -edl  -edlout

$ convert -e[TAB]
     => nothing completes
$ convert -en[TAB]
     => nothing completes
$ convert -em[TAB]
     => -emboss


IMHO, the problem is that _get_cword is using 'echo' to output a string.
It seems that 'echo' cannot output a string "-n" and "-e" because such strings are interpreted as a option for 'echo' itself.
Thus I suggest to use 'printf' instead of 'echo'.

  echo "$var"   =>   printf "%s" "$var"


Regards,

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-1-686 (SMP w/1 CPU core)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages bash-completion depends on:
ii  bash                          3.2-4      The GNU Bourne Again SHell

bash-completion recommends no packages.

bash-completion suggests no packages.

-- no debconf information
-------------- next part --------------
--- bash_completion.orig	2008-07-05 22:55:03.000000000 +0900
+++ bash_completion	2008-09-07 15:05:46.000000000 +0900
@@ -228,7 +228,7 @@
 _get_cword()
 {
 	if [[ "${#COMP_WORDS[COMP_CWORD]}" -eq 0 ]] || [[ "$COMP_POINT" == "${#COMP_LINE}" ]]; then
-		echo "${COMP_WORDS[COMP_CWORD]}"
+		printf "%s" "${COMP_WORDS[COMP_CWORD]}"
 	else
 		local i
 		local cur="$COMP_LINE"
@@ -249,9 +249,9 @@
 		if [[ "${COMP_WORDS[COMP_CWORD]:0:${#cur}}" != "$cur" ]]; then
 			# We messed up! At least return the whole word so things 
 			# keep working
-			echo "${COMP_WORDS[COMP_CWORD]}"
+			printf "%s" "${COMP_WORDS[COMP_CWORD]}"
 		else
-			echo "${cur:0:$index}"
+			printf "%s" "${cur:0:$index}"
 		fi
 	fi
 }


More information about the Bash-completion-devel mailing list