Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Alias (5735)

  (email not shown publicly)

Journal of Alias (5735)

Tuesday June 12, 2007
11:01 PM

Mental Note: Unbreaking Perl tab completion on Debian/etc

[ #33508 ]

Bash (and with it Debian and Ubuntu and any number of other variants) has implemented numerous tab-completion extensions since the programmable tab-completion feature first appeared.

Annoyingly, quite possibly the worst implementation of this is for Perl.

The utterly basic version works as usual

adamk@red:~/stuff$ perl (tab)
blib/ Makefile script/ tmp/
Changes Makefile.PL .svn/
inc/ META.yml svn-commit.tmp
lib/ pm_to_blib t/

Of course, it doesn't show the Perl options. But you get that from this...

adamk@red:~/stuff$ perl -(tab)
-0 -c -d -e -h -I -m -n -P -S -u -v -w -x
-a -C -D -F -i -l -M -p -s -T -U -V -W -X

So now if you have no idea what the Perl options are called, but you know what they all do, you don't save a keystroke but you can get a reminder. hrm... vaaaaguely useful, ok.

Of course, having already chosen an option, like say to use the debugger, things go downhill..

adamk@red:~/stuff$ perl -d (tab)
adamk@red:~/stuff$ perl -d -

Wait... what?

The only thing I can possibly do after using a Perl option is, apparently, to add ANOTHER option to Perl... and there is no way to get tab completion for files after setting options.

This is utterly brain dead annoying.

Fortunately, a fix (although fiddly) exists.

In /etc/bash_completion, waaaaaaay down in the Perl section at line four bazillion and twelve, is this (hint: search in the file for the comment, it's about the second time it exists in the file, in a section called _perl)

                # handle case where first parameter is not a dash option
                if [ $COMP_CWORD -eq 1 ] && [[ "$cur" != -* ]]; then

This needs to be changed to this...

                # handle case where first parameter is not a dash option
                if [[ "$cur" != -* ]]; then

Thanks to Tony Cook for location the line to change, and writing the alternative.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • The screenshot [] of things you can tab-complete is suggestive. The man pages I guess you could do with man -k, or apropos.
  • Standard tab completion is one of the reasons I love zsh. If I do zsh -<Tab> I get:

    -I       -- specify @INC/#include directory (may be used more than once)
    -M   -m  -- module.. executes `use/no module...' before executing your script
    -P       -- run script through C preprocessor before compilation
    -S       -- look for the script using PATH environment variable
    -T       -- turn on tainted checks

    Ordinary morality is for ordinary people. -- Aleister Crowley