Skip to content

Instantly share code, notes, and snippets.

@Flummi
Created February 13, 2018 00:12
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 Flummi/d7c90cc3a16a29f8b0544975c32648bc to your computer and use it in GitHub Desktop.
Save Flummi/d7c90cc3a16a29f8b0544975c32648bc to your computer and use it in GitHub Desktop.
Print Sysinfo in WeeChat
import weechat
weechat.register("inxi", "Flummi", "0.1", "GPL3", "Print Sysinfo in WeeChat", "", "")
cmd_hook_process = ''
cmd_buffer = ''
cmd_stdout = ''
def inxi_cb(data, buffer, args):
"""Callback for /inxi command."""
inxi_exec(buffer, 'inxi')
return weechat.WEECHAT_RC_OK
def inxi_init():
"""Initialize some variables."""
global cmd_hook_process, cmd_buffer, cmd_stdout
cmd_hook_process = ''
cmd_buffer = ''
cmd_stdout = ''
def inxi_process_cb(data, command, rc, stdout, stderr):
"""Callback for hook_process()."""
global cmd_hook_process, cmd_buffer, cmd_stdout
cmd_stdout += stdout
if int(rc) >= 0:
if cmd_stdout:
lines = cmd_stdout.rstrip().split('\n')
for line in lines:
weechat.command(cmd_buffer, '%s' % line)
cmd_hook_process = ''
return weechat.WEECHAT_RC_OK
def inxi_exec(buffer, command):
"""Execute inxi."""
global cmd_hook_process, cmd_buffer, cmd_stdout, cmd_stderr
inxi_init()
cmd_buffer = buffer
cmd_hook_process = weechat.hook_process_hashtable('sh', { 'arg1': '-c', 'arg2': 'inxi' }, 2000, 'inxi_process_cb', 'inxi')
hook = weechat.hook_command("sysinfo", "Print Sysinfo in WeeChat",
"",
"",
"",
"inxi_cb", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment