summaryrefslogtreecommitdiffstats
path: root/lib/Reply/Plugin/Autocomplete/Commands.pm
blob: 5bc06617c8207abfc42cf15649de83bc45d091dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main;
use strict;
use warnings;
# ABSTRACT: tab completion for reply commands

use mop;

=head1 SYNOPSIS

  ; .replyrc
  [ReadLine]
  [Autocomplete::Commands]

=head1 DESCRIPTION

This plugin registers a tab key handler to autocomplete Reply commands.

=cut

class Reply::Plugin::Autocomplete::Commands extends Reply::Plugin {
    method tab_handler ($line) {
        my ($prefix) = $line =~ /^#(.*)/;
        return unless defined $prefix;

        my @commands = $self->publish('commands');

        return map { "#$_" } sort grep { index($_, $prefix) == 0 } @commands;
    }
}

1;