Skip to content

Instantly share code, notes, and snippets.

@pascalpoitras
Last active January 18, 2022 02:00
Show Gist options
  • Save pascalpoitras/ae1f147c7840dc191415a3ed6a23fa1b to your computer and use it in GitHub Desktop.
Save pascalpoitras/ae1f147c7840dc191415a3ed6a23fa1b to your computer and use it in GitHub Desktop.

WeeChat Screenshot

Here I will show you how to create a bar very similar to the nicklist bar, but instead of showing nickname, it will show znc commands, whenever you click on a command, weechat will send a "help the_command_you_just_clicked" and insert the name of the command in the input bar, then enter any arguments required to the command and press enter.

You will need the following script

  1. text_item.py

Let's create the bar

/bar add znc_commands window right 14 1 znc_commands
/set weechat.bar.znc_commands.conditions "${buffer.full_name} =~ \.*status$ && ${window.number} == 1"
/set weechat.bar.znc_commands.size_max 14

This bar will be visible only in *status query.

Now lets add an item to the bar

/set plugins.var.python.text_item.znc_commands "private "

We will fill this items with the znc commands later.

Now here is the options that contains each commands

For znc 1.6

/set plugins.var.znc_commands Version ListMods ListAvailMods ListNicks ListServers AddNetwork DelNetwork ListNetworks MoveNetwork JumpNetwork AddServer DelServer AddTrustedServerFingerprint DelTrustedServerFingerprint ListTrustedServerFingerprints EnableChan DisableChan Detach Topics PlayBuffer ClearBuffer ClearAllChannelBuffers ClearAllQueryBuffers SetBuffer AddBindHost DelBindHost ListBindHosts SetBindHost SetUserBindHost ClearBindHost ClearUserBindHost ShowBindHost Jump Disconnect Connect Uptime LoadMod UnloadMod ReloadMod UpdateMod ShowMOTD SetMOTD AddMOTD ClearMOTD ListPorts AddPort DelPort Rehash SaveConfig ListUsers ListAllUserNetworks ListChans ListClients Traffic Broadcast Shutdown Restart

For znc 1.7

/set plugins.var.znc_commands Version ListMods ListAvailMods ListNicks ListServers AddNetwork DelNetwork ListNetworks MoveNetwork JumpNetwork AddServer DelServer AddTrustedServerFingerprint DelTrustedServerFingerprint ListTrustedServerFingerprints EnableChan DisableChan Attach Detach Topics PlayBuffer ClearBuffer ClearAllBuffers ClearAllChannelBuffers ClearAllQueryBuffers SetBuffer SetBindHost SetUserBindHost ClearBindHost ClearUserBindHost ShowBindHost Jump Disconnect Connect Uptime LoadMod UnloadMod ReloadMod UpdateMod ShowMOTD SetMOTD AddMOTD ClearMOTD ListPorts AddPort DelPort Rehash SaveConfig ListUsers ListAllUserNetworks ListChans ListClients Traffic Broadcast Shutdown Restart

Now we have a bar, an item and the list of commands. We are now ready to fill the items with the znc commands. We are also ready to create a hsignal, this hsignal will translate the line number you click to the name of the command, for example Version = 0, ListMods = 1 and so on

Fun part

/trigger add hsignal_znc_commands hsignal znc_commands
/trigger set hsignal_znc_commands command "/command -buffer ${buffer.full_name} * /quote znc help ${_bar_item_line};/command -buffer ${buffer.full_name} * /input delete_line;/command -buffer ${buffer.full_name} * /input insert ${_bar_item_line}\x20"  

/eval /ruby eval -oc print "/set trigger.trigger.hsignal_znc_commands.regex #{%w[${plugins.var.znc_commands}].map.with_index { |command, line| "/^%s$/%s/_bar_item_line" % [line, command]; }.join(' ')}"

/eval /ruby eval -oc print "/set plugins.var.python.text_item.znc_commands private #{%w[${plugins.var.znc_commands}].map { |command| suffix = command.gsub(/.*?([A-Z][A-Z]+|[A-Z][a-z]+)$/, '\1').gsub(/([^s])s$/, '\1'); '\${color:\${info:nick_color_name,%s}}%s\${\n}' % [suffix, command]; }.join}" 

Finally, we bind mouse left button to the hsignal

/key bindctxt mouse @item(znc_commands):button1 hsignal:znc_commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment