# # Copyright (c) 2010 by Nils Görs # # uppercase first letter of last word in input line # This could be useful for german citizens cause we capitalize the first # letter of all nouns. So we get lot of warnings using aspell. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # simply bind this script to a key: # /key bind meta-l /nouns nouns use strict; my $prgname = "nouns"; my $version = "0.1"; my $description = "uppercase first letter of last word in input line"; # default values # first function called by a WeeChat-script. weechat::register($prgname, "Nils Görs ", $version, "GPL3", $description, "", ""); weechat::hook_command($prgname, $description, "", "Example key binding:\n". "+l /key bind meta-l /$prgname nouns\n", "nouns", "settings", ""); return weechat::WEECHAT_RC_OK; sub settings{ my ($getargs) = ($_[2]); if ($getargs eq "nouns"){ nouns(); } } sub nouns{ my $current_buffer = weechat::current_buffer(); my $input_string = weechat::buffer_get_string($current_buffer, "input"); if ($input_string ne ""){ $/ = " "; my $space_killed = chomp($input_string); # last char space? my ($last) = $input_string=~/(\S+)$/; # get last word my $laenge = length($last); # lenght of last word my $uc_word = ucfirst($last); # upper case first letter my $new_string = (substr $input_string, 0, -$laenge).$uc_word; # replace last word with new upper case word if ($space_killed == 1){ $new_string .= " "; } weechat::buffer_set($current_buffer, "input", $new_string); # write back new line } }