scripts

misc scripts and tools
git clone git://git.2f30.org/scripts
Log | Files | Refs

commit 55bc884e3a04655cc59702fa0cc23074a65dc49c
parent 5f9d6efac6ab6d45a7968d0189bd61369611b8fe
Author: cipher <haris@2f30.org>
Date:   Sat,  7 Dec 2013 14:02:53 +0200

weechat scripts

Diffstat:
Aweechat-scripts/cmus.pl | 17+++++++++++++++++
Aweechat-scripts/pastie.pl | 44++++++++++++++++++++++++++++++++++++++++++++
Aweechat-scripts/shorturl.pl | 17+++++++++++++++++
3 files changed, 78 insertions(+), 0 deletions(-)

diff --git a/weechat-scripts/cmus.pl b/weechat-scripts/cmus.pl @@ -0,0 +1,17 @@ +# weechat plugin to display current playing cmus track +use strict; + +weechat::register("cmus", "cipher <haris\@2f30.org", "0.1", "Public Domain", + "displays cmus artist - song", "", ""); +weechat::hook_command("cmus", "Script to display what cmus is currently playing. Just /cmus and enjoy.", "", "", "", "cmus", ""); + +sub cmus { + my ($data, $buffer, $args) = @_; + my $artistfull = qx(cmus-remote -Q | grep [[:space:]]artist[[:space:]]); + chomp (my $artist = substr($artistfull,10)); + my $songfull = qx(cmus-remote -Q | grep [[:space:]]title[[:space:]]); + chomp (my $song = substr($songfull,10)); + + weechat::command($buffer, "/me cmus playing: $artist - $song"); + return weechat::WEECHAT_RC_OK; +} diff --git a/weechat-scripts/pastie.pl b/weechat-scripts/pastie.pl @@ -0,0 +1,44 @@ +use strict; + +my $SCRIPT_NAME = "pastie"; + +weechat::register("pastie", "cipher <haris\@2f30.org>", "0.1", "Public Domain", "Paste output", "", ""); +weechat::hook_command("pastie", "Just select your text with the cursor, and \"/pastie\" in your window. +By default, it uses \"xsel -o\" to output X selection. + +If you want another application for output, you can set it for example with: + + /set plugins.var.perl.pastie.ext_command \"xsel -o\" + +Replace \"xsel -o\" with your program of choice. +----------------------------------------------", "", "", "", "pastie", ""); + +my $pastie_command; + +init_config(); + +sub init_config { + my %options = ( + "ext_command" => "xsel -o", + ); + foreach my $option (keys %options) { + weechat::config_set_plugin($option, $options{$option}) unless weechat::config_is_set_plugin($option); + } +} + +sub pastie { + my ($data, $command, $return_code, $out, $err) = @_; + my $buffer = $data; + $pastie_command = weechat::config_get_plugin("ext_command"); + my @output = `$pastie_command`; + + weechat::command($buffer, ",--<--"); + + foreach my $output (@output) { + $output =~ s/(.*?)\t/ /g; + weechat::command($buffer, "| $output"); + } + + weechat::command($buffer, "`-->--"); + return weechat::WEECHAT_RC_OK; +} diff --git a/weechat-scripts/shorturl.pl b/weechat-scripts/shorturl.pl @@ -0,0 +1,17 @@ +# weechat script for url shorting +# Needed: WWW::Shorten::TinyURL +use strict; +use WWW::Shorten::TinyURL; +use Clipboard; + +weechat::register("shorten", "cipher <haris\@2f30.org", "0.1", "Public Domain", + "Short url", "", ""); +weechat::hook_command("shorten", "Press \"/shorten\" to output on the channel/buffer the url from clipboard in shortened form", "", "", "", "shorten", ""); + +sub shorten { + my $external = Clipboard->paste; + my ($data, $buffer, $args) = @_; + my $short_url = makeashorterlink($external); + weechat::command($buffer, "url: $short_url"); + return weechat::WEECHAT_RC_OK; +}