# hash to store abbreviations
my %abbrev;

# save a new abbreviation
sub abbrev_make ($$) {
    my ($class, $abbrev) = @_;
    if (my $c = abbrev_lookup($abbrev)) {
        delete $abbrev{c};
    }
    $abbrev{lc($class)} = lc($abbrev);
}

# look up the given class and return the abbreviation
sub abbrev_get (;$) {
    my ($class) = @_;
    return $abbrev{lc($class)};
}

# look up the given abbreviation and return the class
sub abbrev_lookup (;$) {
    my ($abbrev) = (@_ ? @_ : ($_));
    my ($key, $value, $class);
    foreach my $class (keys %abbrev) {
        if ($abbrev{$class} eq lc($abbrev)) {
            return $class;
        }
    }
    return undef;
}

# start a zwrite command to the given abbreviation and optional instance
# To use ":zabv abbreviation, instance"
sub abbrev_write ($;$) {
    my ($abbrev, $instance) = @_;
    my $class = abbrev_lookup($abbrev);
    owl::command("zwrite -c '$class' -i '$instance'");
}

sub abbrev_init () {
    owl::command('alias zabv perl abbrev_write');
    owl::command('bindkey recv "Z" command start-command zabv ');
}

1;
