Guest User

Untitled

a guest
Feb 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import weechat
  2.  
  3. weechat.register("inxi", "Flummi", "0.1", "GPL3", "Print Sysinfo in WeeChat", "", "")
  4.  
  5. cmd_hook_process = ''
  6. cmd_buffer = ''
  7. cmd_stdout = ''
  8.  
  9. def inxi_cb(data, buffer, args):
  10. """Callback for /inxi command."""
  11. inxi_exec(buffer, 'inxi')
  12. return weechat.WEECHAT_RC_OK
  13.  
  14. def inxi_init():
  15. """Initialize some variables."""
  16. global cmd_hook_process, cmd_buffer, cmd_stdout
  17. cmd_hook_process = ''
  18. cmd_buffer = ''
  19. cmd_stdout = ''
  20.  
  21. def inxi_process_cb(data, command, rc, stdout, stderr):
  22. """Callback for hook_process()."""
  23. global cmd_hook_process, cmd_buffer, cmd_stdout
  24. cmd_stdout += stdout
  25. if int(rc) >= 0:
  26. if cmd_stdout:
  27. lines = cmd_stdout.rstrip().split('\n')
  28. for line in lines:
  29. weechat.command(cmd_buffer, '%s' % line)
  30. cmd_hook_process = ''
  31. return weechat.WEECHAT_RC_OK
  32.  
  33. def inxi_exec(buffer, command):
  34. """Execute inxi."""
  35. global cmd_hook_process, cmd_buffer, cmd_stdout, cmd_stderr
  36. inxi_init()
  37. cmd_buffer = buffer
  38. cmd_hook_process = weechat.hook_process_hashtable('sh', { 'arg1': '-c', 'arg2': 'inxi' }, 2000, 'inxi_process_cb', 'inxi')
  39.  
  40. hook = weechat.hook_command("sysinfo", "Print Sysinfo in WeeChat",
  41. "",
  42. "",
  43. "",
  44. "inxi_cb", "")
Add Comment
Please, Sign In to add comment