# -*- coding: utf-8 -*- # # Copyright (c) 2013 by MuxMouse # # Save the current window number by escaping weechat and jump to this # window after starting weechat. If you turn auto_save off weechat will # always jump to the same window. # # 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 . # # 2012-03-28: , MuxMouse (freenode.#weechat-de) # 0.1 : initial release # # requires: WeeChat version 0.3.0 ###################################################################################### # --> IMPORTANT <-- # ###################################################################################### # For running lastwindow at startup add "/wait 1ms /script load lastwindow.py" to # weechat.startup.command_after_plugins. Separate more than one command with ";". # /set weechat.startup.command_after_plugins "/wait 1ms /script load lastwindow.py" # /set weechat.startup.command_after_plugins "/wait 1ms /script load lastwindow.py;..." try: import weechat,re except Exception: print("This script must be run under WeeChat.") print("Get WeeChat now at: http://www.weechat.org/") quit() SCRIPT_NAME = "lastwindow" SCRIPT_AUTHOR = "MuxMouse>" SCRIPT_VERSION = "0.1" SCRIPT_LICENSE = "GPL" SCRIPT_DESC = "Save the current window number by escaping weechat and jump to this window after starting weechat. If you turn auto_save off weechat will always jump to the same window." OPTIONS = { 'last_window' : ('1', 'Window number by escaping weechat.'), 'auto_save' : ('on', 'Autosave the current window number by escaping weechat.'), } Hooks = {'quit': ''} # ================================[ save current window ]========================================= def saveIntOfCurrentWindow_cb(signal, callback, callback_data): if weechat.window_get_integer(weechat.current_window(), "number") > 1 and OPTIONS['auto_save'].lower() == 'on': weechat.config_set_plugin("last_window", str(weechat.window_get_integer(weechat.current_window(), 'number'))) return weechat.WEECHAT_RC_OK # ================================[ jump to current window ]====================================== def jumpToCurrentWindow(): if int(OPTIONS["last_window"]) > 1: weechat.command(weechat.current_window(), "/window %s" % OPTIONS["last_window"]) # ================================[ weechat options & description ]=============================== def init_options(): for option,value in list(OPTIONS.items()): weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0])) if not weechat.config_is_set_plugin(option): weechat.config_set_plugin(option, value[0]) OPTIONS[option] = value[0] else: OPTIONS[option] = weechat.config_get_plugin(option) def toggle_refresh_cb(pointer, name, value): global OPTIONS option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):] # get optionname OPTIONS[option] = value # save new value if OPTIONS['auto_save'].lower() == "off": if Hooks['quit']: Hooks['quit'] = '' weechat.unhook(Hooks['quit']) elif OPTIONS['auto_save'].lower() == "on": if not Hooks['quit']: Hooks['quit'] = weechat.hook_signal('quit', 'saveIntOfCurrentWindow_cb', '') return weechat.WEECHAT_RC_OK # =========================================[ main ]=============================================== if __name__ == "__main__": if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''): version = weechat.info_get("version_number", "") or 0 # if int(version) >= 0x00030600: # else: # weechat.prnt("","%s%s %s" % (weechat.prefix("error"),SCRIPT_NAME,": needs version 0.3.6 or higher"))# weechat.command("","/wait 1ms /python unload %s" % SCRIPT_NAME) init_options() weechat.hook_config( 'plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh_cb', '' ) Hooks['quit'] = weechat.hook_signal('quit', 'saveIntOfCurrentWindow_cb', '') jumpToCurrentWindow()