Getopt-Complete

 view release on metacpan or  search on metacpan

lib/Getopt/Complete/Compgen.pm  view on Meta::CPAN

    my $option = substr($subname,0,1);
    my $code = sub {
        my ($command,$value,$key,$args) = @_;
        $value ||= '';
        $value =~ s/\\/\\\\/;
        $value =~ s/\'/\\'/;
        my @f =  grep { $_ !~/^\s+$/ } `bash -c "compgen -$option -- '$value'"`; 
        chomp @f;
        if ($option eq 'f' or $option eq 'd') {
            # bash is fine with ~/ paths but perl is not, need to translate
            my $home_dir = (getpwuid($<))[7];
            for (my $i = 0; $i < @f; $i++) {
                my $perl_path = $f[$i];
                $perl_path =~ s/^~/$home_dir/;
                if ( -d $perl_path ) {
                    $f[$i] .= "/\t";
                }
            }

            my @not_shown = ($value);
            push @f, \@not_shown;



( run in 0.336 second using v1.01-cache-2.11-cpan-8d75d55dd25 )