[Bash-completion-devel] [bash-completion-Bugs][311702] _get_cword ignores optional arg, scp host:path completion broken with bash 4

bash-completion-bugs at alioth.debian.org bash-completion-bugs at alioth.debian.org
Tue Oct 20 20:44:59 UTC 2009


Bugs item #311702, was changed at 2009-05-27 18:47 by Freddy Vulto
You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311702&group_id=100114

>Status: Closed
Priority: 3
Submitted By: Ville Skyttä  (scop-guest)
Assigned to: Freddy Vulto (fvu-guest)
Summary: _get_cword ignores optional arg, scp host:path completion broken with bash 4 
Distribution: None
Originally reported in: Fedora / Red Hat Bugzilla
Milestone: None
Status: None
Original bug number: 502745


Initial Comment:
http://git.debian.org/?p=bash-completion/bash-completion.git;a=commitdiff;h=f6497298a4422ac236cfd10ddc05b3ace3961a27

This commit changes _get_cword so that it no longer does what it is documented to do; the optional argument (see comments in code) is ignored by the new implementation.  The commit message "fixed _get_cword()" does not tell much what was wrong with the original version and since it was pretty much completely rewritten it's hard to guess; David, do you remember any details?  Was ignoring the optional argument an oversight?

Current _get_cword does not play nice with scp completion and bash 4 - some splitting occurs after the colon in hostname:path causing path gets completed locally.  I do not observe this problem with bash 3.2.
https://bugzilla.redhat.com/show_bug.cgi?id=502745#c2

If I revert _get_cword to what it was before this commit, it appears to do the right thing with scp completion and bash 4 (can only partially test at the moment, no real scp available in my limited bash 4 test env, and I haven't tested the reverted version with bash 3.x).

----------------------------------------------------------------------

>Comment By: Freddy Vulto (fvu-guest)
Date: 2009-10-20 22:44

Message:
Hello Jeremy,

Good you found out.  I don't anticipate any issues with $bash4 in the environment.

I'm not really happy with this global variable though.  I think we just added it because there already were a $bash205, $bash205b and $bash3.  I don't know why $BASH_VERSINFO isn't used; I checked and it's available since bash-2.0 (http://www.faqs.org/faqs/unix-faq/shell/bash/).  Since I'm not sure who is relying on the global variables now, I'm putting removal of these variables on the roadmap for the next major version, bash-completion-2:
"Remove global variables $bash205, $bash205b, $bash3 & $bash4.  They're cluttering everyone's environment and we can just use $BASH_VERSINFO?"
See: http://wiki.debian.org/Teams/BashCompletion/Proposals/Roadmap

Greetings, Freddy

----------------------------------------------------------------------

Comment By: Jeremy Olexa (darkside-guest)
Date: 2009-10-19 22:47

Message:
Freddy, thanks for the hint. The Gentoo Linux package splits up the bash-completion file so $bash4 wasn't being exposed to _get_cword. This made _get_cword to use the bash3 implementation. Doh. I'll patch that for Gentoo. Do you anticipate any issues with bash4 in the environment?

----------------------------------------------------------------------

Comment By: Freddy Vulto (fvu-guest)
Date: 2009-10-19 19:28

Message:
Can you post the output after doing a `set -x'?  This is how at it looks at my box:

$ set -x
$ scp mybox:<TAB>
+ local configfile cur userhost path prefix                       
+ COMPREPLY=()
++ _get_cword :
++ '[' -n '4.0.33(7)-release' ']'
++ __get_cword4 :
++ local i
++ local LC_CTYPE=C
++ local 'WORDBREAKS= 	
"'\''><=;|&(:'
++ WORDBREAKS=' 	
'\''><=;|&(:'
++ WORDBREAKS=' 	
><=;|&(:'
++ '[' -n : ']'
++ (( i=0 ))
++ (( i<1 ))
++ local char=:
++ WORDBREAKS=' 	
><=;|&('
++ (( ++i  ))
++ (( i<1 ))
++ local 'cur=scp mybox:'
++ local 'tmp=scp mybox:'
+++ expr 'scp mybox:' : '.*[ 	
><=;|&(]'
++ local word_start=4
++ '[' 4 -ge 2 ']'
++ local char=p
++ '[' p '!=' '\' ']'
++ break
++ cur=mybox:
++ printf %s mybox:
+ cur=mybox:
+ _expand
+ [[ mybox: == \~*/* ]]
+ [[ mybox: == \~* ]]
+ [[ mybox: == *:* ]]
+ local 'IFS=	
'
+ cur=mybox:
+ userhost=mybox
+ path=
+ path=
+ '[' -z '' ']'
++ ssh -o 'Batchmode yes' mybox pwd
+ path=/home/joe
+ COMPREPLY=($( ssh -o 'Batchmode yes' $userhost             command ls -aF1d "$path*" 2>/dev/null |             sed -e "s/[][(){}<>\",:;^&\!$=?\`|\\ ']/\\\\\\\\\\\\&/g"             -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g' ))
++ ssh -o 'Batchmode yes' mybox command ls -aF1d '/home/joe*'
++ sed -e 's/[][(){}<>",:;^&\!$=?`|\ '\'']/\\\\\\&/g' -e 's/[*@|=]$//g' -e 's/[^\/]$/& /g'
+ return 0
/home/joe/


----------------------------------------------------------------------

Comment By: Jeremy Olexa (darkside-guest)
Date: 2009-10-19 04:39

Message:
Indeed, I am using bash-completion-1.1.

I am not sure how to be more specific. scp host:<tab> returns nothing on hosts that I have access to via a ssh key. I have the following modules active:

%% ls -1 /etc/bash_completion.d/
base
bash-builtins
bzip2
gcc
genlop
gentoo
git
gzip
imagemagick
man
mercurial
modules
mplayer
ooffice.sh
repoman
screen
ssh
vim
xz

----------------------------------------------------------------------

Comment By: Freddy Vulto (fvu-guest)
Date: 2009-10-17 21:42

Message:
Hello Jeremy,

scp remote path completion in bash-completion-1.1 with bash-4 seems to be working all right on my machine.  Can you be more specific about the problem?
Are you sure you're running bash-completion-1.1 and not 1.0?  You can tell it's 1.1 if _get_cword looks like this:

$ declare -f _get_cword
_get_cword () 
{ 
    if [ -n "$bash4" ]; then
        __get_cword4 "$@";
    else
        __get_cword3;
    fi
}

Regards, Freddy

----------------------------------------------------------------------

Comment By: Jeremy Olexa (darkside-guest)
Date: 2009-10-16 04:13

Message:
scp remote path completion is still broken in bash-completion-1.1 with bash-4

----------------------------------------------------------------------

Comment By: David Paleino (hanska-guest)
Date: 2009-05-27 19:11

Message:
Hello Ville,
no, I can't really remember what was wrong with the old implementation of _get_cword.

Maybe the reverted version didn't play nice with 3.x? I'm currently unable to do any commit (not posting from my computer) :(

Sorry,
David

----------------------------------------------------------------------

You can respond by visiting: 
https://alioth.debian.org/tracker/?func=detail&atid=413095&aid=311702&group_id=100114



More information about the Bash-completion-devel mailing list