Skip to content

Instantly share code, notes, and snippets.

@unzan
Last active September 24, 2017 16:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unzan/7fb9b3e415a4a697a37a to your computer and use it in GitHub Desktop.
Save unzan/7fb9b3e415a4a697a37a to your computer and use it in GitHub Desktop.

Weechat Highlight Monitoring Without Script

Requires at least Weechat 1.0 with Trigger and Exec plugin.

This gist is not intended to make highmon.pl or any other highlight monitoring script obsolete. Trigger is very limited. It can't do complex stuffs. We will only create the basic function of highlight monitoring: collect lines that contain highlight and put them all in a buffer.

First we need a trigger that will active everytime there's line printed on weechat's buffer. We'll name it highmon:

/trigger addoff highmon print

I use addoff because it allows me to adjust all trigger options while the trigger itself isn't running.

Next we set its conditions:

/trigger set highmon conditions ${tg_highlight} == 1 && ${tg_displayed} == 1 && ${buffer.notify} > 0

${tg_highlight} == 1 means the line contains a highlight and ${tg_displayed} == 1 means the line isn't filtered (in both variables 1 means yes and 0 means no). The last condition is ${buffer.notify} > 0 which means the buffer where the line is printed has a notify level other than none (see the notify property in the documentation of weechat_buffer_set for explanation of this number).

If you want, you can append another condition like && ${tg_tags} ~= ,notify_message, to make sure the trigger will only collect highlight from chat messages and not part/quit messages or any other texts printed on WeeChat buffer.

Now we need a buffer to put all the lines matching the above conditions. Weechat currently has no command to create a generic buffer. Luckily /exec has an option to redirect its output to a new buffer and it's good enough for our little trigger:

/exec -sw -nosh -norc -buffer highlights true

That will execute /bin/true and redirect its output to a new buffer named exec.highlights (/exec automatically prefixed the name with exec.). But since /bin/true does not output anything, the buffer will be clean for us to use. Before we proceed to our trigger, we need to set our buffer's property because it doesn't show timestamp on each line by default. Run the following command inside exec buffer to change that:

/buffer set time_for_each_line 1

Back to trigger. Set its command to re-print the line in our exec buffer:

/trigger set highmon command /print -buffer exec.highlights -tags notify_none,no_highlight ${buffer.name}\t${tg_prefix}${color:default}: ${tg_message}

Some explanations:

  • The no_highlight tag prevents Weechat from enabling highlight on the new line we just printed. notify_none prevents the buffer from being added into hotlist.

  • ${buffer.name} is the name of buffer that contains highlight. IRC buffers have names in format: <server>.<channel-or-nickname>. If that's too long you can replace ${buffer.name} with ${buffer.short_name} (contains only the channel name/nickname).

  • \t is used to mark the text at the left of it as line prefix and text at the right of it as the message.

  • ${tg_prefix} is the original prefix of the line that contains the highlight (in normal chat message this usually contains the nickname) and ${tg_message} is the original message of that line.

  • ${color:default} resets the color back to default. It is needed because ${tg_prefix} already has color and we don't want that color to "spill" into the message. Alternately you can replace ${tg_prefix} with ${tg_prefix_nocolor} and remove ${color:default}. But you'll lose nick color by doing that.

Now we just need to enable our trigger:

/trigger enable highmon

If everything's set up correctly the next time there's a highlight it will be collected inside buffer exec.highlights.

One last thing, we don't want to manually create exec buffer everytime we run WeeChat. We want WeeChat to do that for us automatically. The weechat.startup.command_after_plugins option is perfect for that:

/set weechat.startup.command_after_plugins "/exec -nosw -nosh -norc -buffer highlights true;/command -buffer exec.highlights core /buffer set time_for_each_line 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment