Skip to content

Instantly share code, notes, and snippets.

@erikh
Created November 29, 2009 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikh/244924 to your computer and use it in GitHub Desktop.
Save erikh/244924 to your computer and use it in GitHub Desktop.
################################################################
#
# titlebar.rb - context-sensitive xterm title manipulation
#
# based off of titlebar.pl by erikh which is does the same thing
#
# By Erik Hollensbe <erik@hollensbe.org>
#
################################################################
#
# Usage: just throw this in autorun and let it do it's magic.
#
################################################################
Weechat.register(
"titlebar",
"Erik Hollensbe",
"1.0",
"BSD",
"context-sensitive xterm title manipulation",
"",
""
)
def weechat_init
Weechat.hook_signal("hotlist_changed", "change_titlebar", "")
Weechat.hook_signal("buffer_switch", "change_titlebar", "")
end
def change_titlebar(*args)
hotlists = parse_infolist("hotlist")
active = hotlists.map { |x| x[:buffer_number] }
buffers = parse_infolist("buffer")
curbuf = buffers.find { |x| x[:current_buffer] > 0 }
STDERR.print "\033]0;Weechat: #{curbuf[:short_name]}"
if active.size > 0
STDERR.print " | Act: [#{active.join(",")}]"
end
STDERR.print "\007";
return Weechat::WEECHAT_RC_OK
end
def parse_infolist(type)
infolist_ptr = Weechat.infolist_get(type, "", "")
ret = []
while Weechat.infolist_next(infolist_ptr) > 0
h = { }
str = Weechat.infolist_fields(infolist_ptr)
str.split(/,/).collect do |item|
type, name = item.split(/:/)
case type
when 'p'
h[name.to_sym] = Weechat.infolist_pointer(infolist_ptr, name)
when 'i'
h[name.to_sym] = Weechat.infolist_integer(infolist_ptr, name)
when 's'
h[name.to_sym] = Weechat.infolist_string(infolist_ptr, name)
when 'b'
# FIXME: not exposed to script API yet.
# h[name.to_sym] = Weechat.infolist_infolist(infolist_ptr, name)
when 't'
h[name.to_sym] = Weechat.infolist_time(infolist_ptr, name)
else
Weechat.print("", "parse_infolist(): Unknown type for #{name}: #{type}\n")
end
end
ret.push h
end
return ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment