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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/usr/bin/perl
use v5.14;
use warnings;
use Term::TermKey;
my $tk = Term::TermKey->new( undef );
my $path = shift @ARGV || "/etc/inputrc";
open my $rc, "<", $path or die "Cannot read $path - $!";
my @ifs;
while( <$rc> ) {
chomp;
for($_) {
if( m/^#/ or m/^\s*$/ ) {
# comment or blank
say $_
}
elsif( m/^\$if ([^=]+)=(.*)$/ ) {
print " " x @ifs;
say "\$if $1=$2";
push @ifs, "$1=$2";
}
elsif( m/^\$endif$/ ) {
pop @ifs;
print " " x @ifs;
say "\$endif";
}
elsif( m/^set (\S+)\s+(.*)$/ ) {
print " " x @ifs;
say "set $1 $2";
}
elsif( m/"(.*)": (.*)$/ ) {
my ( $bytes, $binding ) = ( $1, $2 );
# TODO: This probably needs a lot more work
$bytes =~ s/\\e/\e/g;
$bytes =~ s{\\C-(.)}{chr( 0x1f & ord $1)}eg;
print " " x @ifs;
$tk->push_bytes( $bytes );
while( $tk->getkey( my $key ) ) {
print $tk->format_key( $key, Term::TermKey::FORMAT_VIM );
}
say ": $binding";
}
else {
die "Not sure how to parse line $_\n";
}
}
}
|