Question. Autocomplete paths starting with %.

2011-02-22 Thread d...@ucore.info
Hi,

I'm not subscribed to this list so please make sure to CC me if you
want me to receive the reply.

I'd like to hack some solution based on:
http://www.huyng.com/bashmarks-directory-bookmarks-for-the-shell/

but to be able to use saved bookmarks in other commands (explanation below).

So if I have a bookmark:
webdir=/home/dpc/www

I could do:

$ cp xfile %webd

and that autocomplete to:

$ cp xffile /home/dpc/www

The % signed would be similar to what bash already does for @, ~ and
$. Only this one would be for bookmarks.

I can script in Bash quite well, but I've never did anything that
fancy with completion and I don't know how to plug my function to
handle this. I understand that I should register something (function
named like _bookmarkcomp) to handle filename completion for things
beginning with %.

If you help me with this one I promise to post my solution for benefit
of other bash users.

Regards,
Dawid
-- 
http://dpc.ucore.info



Re: Question. Autocomplete paths starting with %.

2011-02-24 Thread d...@ucore.info
On Wed, Feb 23, 2011 at 5:06 AM, Clark J. Wang  wrote:
> I can give you an example here:
>
> bash# vi compgen-example.sh
> _compgen_foo()
> {
>     local cmd=$1 cur=$2 pre=$3
>
>     if [[ $cur = % ]]; then
>     COMPREPLY[0]='it-works'
>     fi
> }
>
> complete -F _compgen_foo foo
> bash# source compgen-example.sh
> bash# foo %    <-- Press TAB here
> bash# foo it-works    <-- `%' will be expanded like this

Thanks.

However this only registers for foo. What if I wanted to handle % for
everything or even better ... only at places that expect the path? Any
way to force bash to do that?

Regards,
Dawid

-- 
http://dpc.ucore.info