Created
September 22, 2010 19:55
-
-
Save jhsu/592418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Author: Joseph "jshsu" Hsu <[email protected]> | |
# File: query_nexto.rb | |
# | |
# Create a buffer next to current buffer | |
# | |
# Copyright (C) 2010 Joseph Hsu | |
# | |
# 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 <http://www.gnu.org/licenses/>. | |
SCRIPT_NAME = 'query_nexto' | |
SCRIPT_AUTHOR = 'Joseph Hsu <[email protected]>' | |
SCRIPT_DESC = 'Create a query buffer next to current buffer' | |
SCRIPT_VERSION = '0.1' | |
SCRIPT_LICENSE = 'GPL3' | |
def weechat_init | |
Weechat.register SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", "" | |
# command, discription, args, args_description, completion, callback, callback_data | |
Weechat.hook_command(SCRIPT_NAME, SCRIPT_DESC, | |
'nick <message>', | |
' nick: user nick' + | |
"\n" + | |
' message: message to send to nick', '', SCRIPT_NAME, '') | |
return Weechat::WEECHAT_RC_OK | |
end | |
def current_buffer | |
Weechat.current_buffer() | |
end | |
def current_buffer_number | |
Weechat.buffer_get_integer(current_buffer, "number") | |
end | |
def next_buffer_number | |
current_buffer_number + 1 | |
end | |
def create_query(nick, message) | |
Weechat.command(current_buffer, "/query #{nick} #{message}") | |
end | |
def move_buffer_to(buffer, number) | |
Weechat.buffer_set(buffer, "number", "#{number}") | |
end | |
def query_nexto(data, buffer, args) | |
argv = args.strip.split(' ') | |
unless argv.empty? | |
nick = argv.shift | |
message = argv.join(' ') | |
next_number = next_buffer_number | |
create_query(nick, message) | |
move_buffer_to(current_buffer, next_number) | |
end | |
return Weechat::WEECHAT_RC_OK | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment