comparison terminal-title.py @ 1:98c1a683d9c1

Update the terminal title when the configuration changes
author Guido Berhoerster <guido+weechat@berhoerster.name>
date Sat, 14 Mar 2015 16:09:47 +0100
parents c54a46719c46
children c86ca2eea6bc
comparison
equal deleted inserted replaced
0:c54a46719c46 1:98c1a683d9c1
102 sys.__stdout__.write(TERM_TEMPLATE % title_str) 102 sys.__stdout__.write(TERM_TEMPLATE % title_str)
103 sys.__stdout__.flush() 103 sys.__stdout__.flush()
104 104
105 return weechat.WEECHAT_RC_OK 105 return weechat.WEECHAT_RC_OK
106 106
107 def config_hook(data, option, value):
108 set_term_title_hook("", "", "")
109
110 return weechat.WEECHAT_RC_OK
107 111
108 if __name__ == '__main__': 112 if __name__ == '__main__':
109 weechat.register(SCRIPT_NAME, AUTHOR, VERSION, 'GPL3', DESCRIPTION, '', '') 113 weechat.register(SCRIPT_NAME, AUTHOR, VERSION, 'GPL3', DESCRIPTION, '', '')
110 114
111 for option, (value, description) in DEFAULT_SETTINGS.iteritems(): 115 for option, (value, description) in DEFAULT_SETTINGS.iteritems():
117 term = os.environ.get("TERM", None) 121 term = os.environ.get("TERM", None)
118 if term: 122 if term:
119 for term_name, term_template in TERM_TEMPLATES: 123 for term_name, term_template in TERM_TEMPLATES:
120 if term.startswith(term_name): 124 if term.startswith(term_name):
121 TERM_TEMPLATE = term_template 125 TERM_TEMPLATE = term_template
122 for hook in ["buffer_switch", "buffer_title_changed", 126 for hook in ['buffer_switch', 'buffer_title_changed',
123 "hotlist_changed", "upgrade_ended"]: 127 'hotlist_changed', 'upgrade_ended']:
124 weechat.hook_signal(hook, "set_term_title_hook", "") 128 weechat.hook_signal(hook, 'set_term_title_hook', '')
125 set_term_title_hook("", "", "") 129 weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME,
130 'config_hook', '')
131 set_term_title_hook('', '', '')
126 break 132 break