Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

COMPREPLY scope

6 views
Skip to first unread message

Mario Signorino

unread,
May 17, 2013, 5:50:09 PM5/17/13
to
Hi all

I need some help and possibly also an advice.

Is it possible to retrieve the COMPREPLY variable outside and/or after calling the complete function?
I'm working a special terminal emulator inherited from gnome-terminal. I want to modify the common TAB behaviour and manipulate the result of all TAB-completions: any string generated from the complete builtin function (and also any other bash-completion extension) should go handled by me.

Ex: if in the terminal a TAB is pressed after a "ls /" I want to get all the "bin/ initrd.img mnt/ selinux/ vmlinuz ...". Also I want the "add commit init repack ..." given after a "git "+TAB.

My idea was to call something like a getenv("COMPREPLY") from whitin my terminal emulator, read the result and then decide what&if to display to the user.
But in the source I can see this (pcomplete.c):
/* XXX - should we unbind COMPREPLY here? */
unbind_variable ("COMPREPLY");
Ehm! So there is no way...?
Also I would need to know if in the COMPREPLY there are filenames or not.

I could trap any user TAB press and treat all the following strings from the pty as result of a completion (until I get the prompt again)... but then I should at least know if a program is running or not: maybe the user is just pressing tab inside vim.
I do not know how to do that, and anyway it sounds like a bad hack...

Also I cannot modify any part of the the existing system: my terminal will run mostly remotely connected over ssh. Of course I could run some bash script at login, but I have to keep it simple.

Another idea is to add a delimitation around the completion result: I could trap it easily. But I did not find how do that.
Last idea: trap the TAB from the user input and call directly the complete() readline function, putting the result somewhere in the env (or directly in my code). How?
In the end it seems readline already has everything I need: I simply do not know how to access its info.

I'm not actually sure if this is the right place for this question...
Any helps or suggestion will be appreciated.

Tnx
Mario

Chet Ramey

unread,
May 22, 2013, 10:25:16 AM5/22/13
to Mario Signorino, bug-...@gnu.org, chet....@case.edu
On 5/17/13 5:50 PM, Mario Signorino wrote:
> Hi all
>
> I need some help and possibly also an advice.
>
> Is it possible to retrieve the COMPREPLY variable outside and/or after calling the complete function?

No. The programmable completion code unsets COMPREPLY after the shell
function completes. You might have some luck experimenting with the
default completion feature (complete -D), but you'll have to do all the
dispatching yourself.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/

Raphaël Droz

unread,
Jun 1, 2013, 3:31:49 PM6/1/13
to bug-...@gnu.org
On Fri, May 17, 2013 at 02:50:09PM -0700, Mario Signorino wrote:
> Another idea is to add a delimitation around the completion result: I
> could trap it easily. But I did not find how do that.

I thought about time some times ago.

My goal was to enclose the burn-cd files completion result with a
text-based gauge showing the amount of files according to the media
size limit.


For this to work I needed some new hooks inside the bash completion
system.

You can find the two patches here:
https://gitorious.org/drzraf/bash/commit/6dfb9b815e3f1a468dc465263c461912188b0565
https://gitorious.org/drzraf/bash/commit/8aa32cea618fc11c99c798a3324f068b44232aa3

and a sample here:
https://gitorious.org/drzraf/bash-completion/blobs/master/completions/burn-cd


You may also give a look at an attempt to add per-completion settings in
the above-mentioned bash repository at e9b65ae and a123ad7
(that was about a per-completion "wordbreaks" setting)


good luck

0 new messages