[Bash-completion-devel] wget completion

gibboris at gmail.com gibboris at gmail.com
Fri Mar 27 13:42:32 UTC 2009


Hello, following your advices I tryed the bash "pattern completion"
(don't know the exact expression)
There is a huge potential but I can't get it working well.

ex :
http:<TAB> = http:http://
But if I prefix ':' with a \ it completes well (http://)

https://w<TAB> = https:https://www
But if I prefix ':', '/' and '/' with each a \ it completes well
(https://www).

I tried COMPREPLY to send escaped completion and add :
 cur=${cur/\\:/:}
 cur=${cur@\\/@/}
But I now have to add \ to the ':'
I also tried
 cur=${cur/:/\\\\:}
and COMPREPLY=( $( compgen -W "http{,s}\\\\:\\\\/\\\\/{,www}
ftp\\\\:\\\\/\\\\/" -- $cur ) )
I looked to the scp completion but it's too complex for me (too many
backslashes and regexp to clearly understand what do I need in the wget
case).
So, no way... I'm now looking to where is the variable I have to unset
to make ':' and '/' having the behaviour of any normal character.

Otherwise, what was modified since last time :
- replaced $(seq x 1 y) by {x..y}
- fixed : completion for the http --header (still quite brutal though)
- fixed --quota completion

(I'm also stuck with a (small) problem to make a "not bound" number completion
so that any number value would be completed by this range of characters :
[{0..9}${optionnal_suffixe}])

PS: a last thing (to developpers) which as nothing to do with wget,
can't contrib/sitecopy use _longopt. (it's because of this example that I
used sed to parse the --help output in the first version of this
completion)

Bye

Raph

On Fri, Mar 20, 2009 at 11:20:18PM +0100, Freddy Vulto wrote:
> On Fri, Mar 20, 2009 at 1:22 PM,  <gibboris at gmail.com> wrote:
> > - I *tried* the completion of the beginning of the host.  But I
> > can't get the -o nospace working :[
> 
> You have to add the `-o nospace' option after `complete' instead of
> `compgen'.  See diff.
> 
> > Another problem is that after 'http', 's://' and '://' ARE
> > proposed BUT all is messed up with filename completion if I add a
> > ':' (maybe because of the slash or something around $IFS ?).
> 
> You can take a look at `scp' completion in file `contrib/ssh' which
> already solves processing `:'.  Note the: cur=`_get_cword ":"` (?)
> I found it difficult though: I tried copying things to wget
> but couldn't get it work.  Maybe you can give it a try.
> 
> > [parenthesis]
> > It makes me think : would an algorithm to convert a regexp in
> > a completion script like this be useful ?
> > ---> (ht|f)tps?://(www.)?
> > ---> (h => http, ht => http, f => ftp, http => ( http:// https://),...)
> > --->  h) COMPREPLY=( $( compgen -o nospace -W 'http' -- $cur ) );return 0;;...
> > [/parenthesis]
> 
> Or use bash parameter expansion (see also diff):
> 
> COMPREPLY=( $( compgen -W "http{,s}://{,www} ftp://" -- $cur ) )
> 
> 
> Regards,
> 
> Freddy Vulto
> http://fvue.nl
> 
> ---8<---------------------------------------------------------------
> 
> --- wget.sh.orig	2009-03-20 22:20:13.000000000 +0100
> +++ wget.sh	2009-03-20 22:55:39.000000000 +0100
> @@ -93,23 +93,11 @@
>  	    COMPREPLY=( $( compgen -W "$(wget -h | sed -n 's/^[
> [:blank:]]*\(-[a-zA-A46]\).*$/\1/p')" -- $cur ) )
>  	    return 0
>  	    ;;
> -	h)
> -	    COMPREPLY=( $( compgen -o nospace -W 'http' -- $cur ) )
> -	    return 0
> -	    ;;
> -	f)
> -	    COMPREPLY=( $( compgen -o nospace -W 'ftp://' -- $cur ) )
> -	    return 0
> -	    ;;
> -	http)
> -	    COMPREPLY=( $( compgen -W 'http:// https://' -- $cur ) )
> -	    return 0
> -	    ;;
> -	https\?://w)
> -	    COMPREPLY=( $( compgen -W "${cur}ww." -- $cur ) )
> +	*)
> +	    COMPREPLY=( $( compgen -W "http{,s}://{,www} ftp://" -- $cur ) )
>  	    return 0
>  	    ;;
>      esac
>      return 0
>  }
> -complete -F _wget -o default wget
> +complete -F _wget -o nospace wget
> 
> _______________________________________________
> Bash-completion-devel mailing list
> Bash-completion-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wget.sh
Type: application/x-sh
Size: 3924 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20090327/9577c585/attachment.sh 


More information about the Bash-completion-devel mailing list