pericmd 031: More on tab completion (3): case sensitivity, Complete

Continuing from the previous blog’s example, you’ll notice that by default tab completion is case-insensitive:

% mycomp2 --baz h<tab>
% mycomp2 --baz H<tab><tab>
HISTCONTROL     HISTIGNORE      HISTTIMEFORMAT  
HISTFILESIZE    HISTSIZE        HOME            

This is because most completion routines, including complete_env() used above, or complete_array_elem() used often in custom completion routines, offer ci (case-insensitive) option which defaults to $Complete::OPT_CI which in turn default to environment variable COMPLETE_OPT_CI or 1.

If you turn off case-insensitivity, e.g. by:

% export COMPLETE_OPT_CI=0

then the above completion will no longer work:

% mycomp2 --baz h<tab><tab>

Alternatively if you need to set case (in-)sensitivity specifically in a routine, you can turn it on or off explicitly. For example:

# explicitly turn on case-insensitivity, regardless of COMPLETE_OPT_CI or $Complete::OPT_CI setting
complete_array_elem(array=>\@array, word=>$args{word}, ci=>1);

There are several other settings in Complete that are observed by the other Complete::* modules. Most of these settings’ default are optimized for convenience. This will be covered in the next blog post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s