WeeChat DevCenter

Tag - script

Entries feed

Friday, February 26 2021

Script anti_password.py

You've sent your password to the wrong window (ie: WeeChat), and it is now public, viewed by 1,500 people?
For now, you have to change your password.

For the future, a new script is now available: anti_password.py.

How does it work?

When you press Enter to send text to a buffer, the script detects if the input is a password, in two ways:

  1. If the input matches a condition: number of words, lower/upper/digit/special chars.
  2. If a secured data value is in the input (reminder: secured data is the recommended way to store all your passwords in WeeChat) (requires WeeChat ≥ 3.1).

If a password is detected, the text is not sent to the buffer (3 times with the default config).

Note: the WeeChat commands (ie /xxx) are ignored and are always sent.

Options

There are 4 options to configure the script (see /fset anti_password for a list of options with help):

  • allowed_regex: allowed regular expression (checked first)
  • password_condition: the condition used to detect a password
  • check_secured_data: whether the script checks for secured data (disabled, input equals secured data or secured data included in input)
  • max_rejects: the number of times the same input is rejected; after this number, the input is finally sent to the buffer.

Keep your passwords safe!

Updated on 2021-03-13: added option allowed_regex.

Saturday, November 4 2017

Split of scripting Debian packages

Starting on Sunday, Nov 3rd 2017 at 02:00 (CET), the Debian packaging will change in weechat.org Debian/Ubuntu/Raspbian repositories: the scripting plugins are split into multiple packages, so that Perl, Python, Ruby, ... can be installed separately.

Only development packages will be updated, the released versions (1.9.1 and earlier) will not be updated.

Important: if you are using the WeeChat development packages from weechat.org, you will have to install manually the scripting packages (according to the languages you'll use in WeeChat).

Old packaging (until 2017-11-04):

  • weechat
  • weechat-core
  • weechat-curses
  • weechat-dbg
  • weechat-dev
  • weechat-doc
  • weechat-plugins
  • weechat-plugins (14 plugins):
    • aspell
    • exec
    • fifo
    • guile
    • javascript
    • lua
    • perl
    • php
    • python
    • relay
    • ruby
    • script
    • tcl
    • trigger

New packaging, with 8 new packages:

  • weechat
  • weechat-core
  • weechat-curses
  • weechat-dbg
  • weechat-dev
  • weechat-doc
  • weechat-plugins
  • weechat-plugins (6 plugins remaining):
    • aspell
    • exec
    • fifo
    • relay
    • script
    • trigger
  • weechat-python
  • weechat-perl
  • weechat-ruby
  • weechat-lua
  • weechat-tcl
  • weechat-guile
  • weechat-javascript
  • weechat-php

GitHub issue: https://github.com/weechat/weechat/issues/1085

Tuesday, October 17 2017

Automatic tests of scripting API

Automatic tests of the scripting API have been added a few days ago. For now only a small part of API functions are checked.

This is done with 3 new Python scripts in directory tests/scripts/python:

  • unparse.py: convert Python code to other languages (including Python itself)
  • testapigen.py: generate scripts in all languages to test the API
  • testapi.py scripting API tests

The script unparse.py can convert Python code to other languages: Python, Perl, Ruby, Lua, TCL, Guile, JavaScript and PHP (new plugin in version 2.0). The Python code is first parsed using AST (ast.parse), and then this tree is recursively scanned to produce code in Python or another language (note: only part of AST is supported, the minimum for WeeChat tests).

Example of code conversion in other languages:

$ ./unparse.py --language all
Enter the code to convert (Enter + ctrl+D to end)

def test_list_new():
    ptr_list = weechat.list_new()
    check(ptr_list != '')
    check(weechat.list_size(ptr_list) == 0)

python:
def test_list_new():
    ptr_list = weechat.list_new()
    check(ptr_list != '')
    check(weechat.list_size(ptr_list) == 0)

perl:
sub test_list_new
{
    $ptr_list = weechat::list_new();
    check($ptr_list ne "");
    check(weechat::list_size($ptr_list) == 0);
}

ruby:
def test_list_new
    ptr_list = weechat.list_new()
    check(ptr_list != '')
    check(weechat.list_size(ptr_list) == 0)
end

lua:
function test_list_new()
    ptr_list = weechat.list_new()
    check(ptr_list ~= '')
    check(weechat.list_size(ptr_list) == 0)
end

tcl:
proc test_list_new {} {
    set ptr_list [weechat::list_new]
    check [expr {$ptr_list ne ""}]
    check [expr {[weechat::list_size $ptr_list] == 0}]
}

guile:
(define (test_list_new)
    (let ((ptr_list (weechat:list_new)))
        (begin
            (check (string<> ptr_list ""))
            (check (= (weechat:list_size ptr_list) 0))
        )
    )
)

javascript:
function test_list_new() {
    ptr_list = weechat.list_new()
    check(ptr_list != '')
    check(weechat.list_size(ptr_list) == 0)
}

php:
function test_list_new()
{
    $ptr_list = weechat_list_new();
    check($ptr_list != "");
    check(weechat_list_size($ptr_list) == 0);
}

The script testapigen.py generates scripts in all supported languages. These scripts are loaded in WeeChat during tests, and print the results of tests, for example in Python:

>>> Running command: /script load -q ./tmp_weechat_test/testapi/testapi.py
>>> Running command: /testapi.py
>>>
>>> ------------------------------
>>> Testing python API
  > TESTS: 57
  > test_plugins
      TEST OK: weechat.plugin_get_name('') == 'core'
      TEST OK: weechat.plugin_get_name(weechat.buffer_get_pointer(weechat.buffer_search_main(), 'plugin')) == 'core'
  > test_strings
      TEST OK: weechat.charset_set('iso-8859-15') == 1
      TEST OK: weechat.charset_set('') == 1
      TEST OK: weechat.iconv_to_internal('iso-8859-15', 'abc') == 'abc'
      TEST OK: weechat.iconv_from_internal('iso-8859-15', 'abcd') == 'abcd'
      TEST OK: weechat.gettext('abcdef') == 'abcdef'
      TEST OK: weechat.ngettext('file', 'files', 1) == 'file'
      TEST OK: weechat.ngettext('file', 'files', 2) == 'files'
      TEST OK: weechat.strlen_screen('abcd') == 4
      TEST OK: weechat.string_match('abcdef', 'abc*', 0) == 1
      TEST OK: weechat.string_eval_path_home('test ${abc}', {}, {'abc': '123'}, {}) == 'test 123'
      TEST OK: weechat.string_mask_to_regex('test*mask') == 'test.*mask'
      TEST OK: weechat.string_has_highlight('my test string', 'test,word2') == 1
      TEST OK: weechat.string_has_highlight_regex('my test string', 'test|word2') == 1
      TEST OK: weechat.string_remove_color('test', '?') == 'test'
      TEST OK: weechat.string_is_command_char('/test') == 1
      TEST OK: weechat.string_is_command_char('test') == 0
      TEST OK: weechat.string_input_for_buffer('test') == 'test'
      TEST OK: weechat.string_input_for_buffer('/test') == ''
      TEST OK: weechat.string_input_for_buffer('//test') == '/test'
      TEST OK: weechat.string_eval_expression('100 > 50', {}, {}, {'type': 'condition'}) == '1'
      TEST OK: weechat.string_eval_expression('${buffer.full_name}', {}, {}, {}) == 'core.weechat'
  > test_lists
      TEST OK: ptr_list != ''
      TEST OK: weechat.list_size(ptr_list) == 0
      TEST OK: weechat.list_size(ptr_list) == 1
      TEST OK: weechat.list_size(ptr_list) == 2
      TEST OK: weechat.list_search(ptr_list, 'abc') == item_abc
      TEST OK: weechat.list_search(ptr_list, 'def') == item_def
      TEST OK: weechat.list_search(ptr_list, 'ghi') == ''
      TEST OK: weechat.list_search_pos(ptr_list, 'abc') == 0
      TEST OK: weechat.list_search_pos(ptr_list, 'def') == 1
      TEST OK: weechat.list_search_pos(ptr_list, 'ghi') == -1
      TEST OK: weechat.list_casesearch(ptr_list, 'abc') == item_abc
      TEST OK: weechat.list_casesearch(ptr_list, 'def') == item_def
      TEST OK: weechat.list_casesearch(ptr_list, 'ghi') == ''
      TEST OK: weechat.list_casesearch(ptr_list, 'ABC') == item_abc
      TEST OK: weechat.list_casesearch(ptr_list, 'DEF') == item_def
      TEST OK: weechat.list_casesearch(ptr_list, 'GHI') == ''
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'abc') == 0
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'def') == 1
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'ghi') == -1
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'ABC') == 0
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'DEF') == 1
      TEST OK: weechat.list_casesearch_pos(ptr_list, 'GHI') == -1
      TEST OK: weechat.list_get(ptr_list, 0) == item_abc
      TEST OK: weechat.list_get(ptr_list, 1) == item_def
      TEST OK: weechat.list_get(ptr_list, 2) == ''
      TEST OK: weechat.list_string(item_def) == 'def2'
      TEST OK: weechat.list_next(item_abc) == item_def
      TEST OK: weechat.list_next(item_def) == ''
      TEST OK: weechat.list_prev(item_abc) == ''
      TEST OK: weechat.list_prev(item_def) == item_abc
      TEST OK: weechat.list_size(ptr_list) == 1
      TEST OK: weechat.list_get(ptr_list, 0) == item_def
      TEST OK: weechat.list_get(ptr_list, 1) == ''
      TEST OK: weechat.list_size(ptr_list) == 0
  > TESTS END

>>> Tests python: 57 tests, 57 OK, 0 errors, 0 unexpected messages, 9 ms

Saturday, March 14 2015

New plugin Javascript

A new plugin called "javascript" has been added to WeeChat. You can now load and execute Javascript scripts in WeeChat!

This plugin uses Google's v8 engine.

WeeChat now supports Python, Perl, Ruby, Lua, Tcl, Guile and Javascript!

To load/unload JS scripts, you can use the /script or /javascript command.

An example of script is available here: https://weechat.org/files/temp/scripts/example.js.

Tuesday, August 14 2012

Scripts manager

A new scripts manager has been added, the plugin is called "script" and provides the /script command.

This plugin will replace two scripts: weeget.py (the current scripts manager) and script.pl (providing a /script command to load/unload/reload scripts for any language).

The new /script command is similar to command /weeget with some minor differences (see /help script for more info).

The plugin provides a buffer with list of scripts in repository, which makes installation or removal of scripts very fast: just press alt+i on this buffer, and the script is installed! Not satisfied with the script? Key alt+r and the script is gone!

The buffer allows you to search string in scripts (description, tags, ...) and to sort scripts with many keys. Columns displayed can be fully customized (order, columns displayed), as well as colors.

For list of options, just do: /set script.*

List of scripts (click for full size):

Script plugin: list of scripts

Detail of a script (click for full size): Script plugin: detail of a script

Enjoy!

Friday, March 16 2012

SameGame

A new script samegame.py is now available! More info about this game is available at http://en.wikipedia.org/wiki/SameGame.

If you are using weeget, just do: /weeget install samegame.py

Mouse is required, so you must have WeeChat >= 0.3.6.

For help: /help samegame.

Screenshot (click for full size):

SameGame

Enjoy!

Monday, October 31 2011

Shorten URLs with own HTTP server

Don't panic with long URLs and don't give your private URLs any more to shortening services!
A new script urlserver.py has been added. This script shortens URLs displayed and serve them using own HTTP server, which can be used to display a list of all URLs as well.

Many options are available to customize shortening of URLs, display in WeeChat and HTML page (see /help urlserver and /set plugins.var.python.urlserver.*).

The URLs are saved into ~/.weechat/urlserver_list.txt when script is unloaded, so that URLs are persistent when you restart WeeChat.

A screenshot of HTML page with list of URLs (click for full size):

Urlserver

Thursday, October 27 2011

New plugin Guile

A new plugin called "guile" has been added to WeeChat. You can now load and execute Scheme scripts in WeeChat!

WeeChat now supports Python, Perl, Ruby, Lua, Tcl and Guile!

To load/unload scheme scripts, command is /guile with same syntax as other script languages:

/guile load /path/to/example.scm
/guile reload example
/guile unload example

An example of script:

;; example.scm
(weechat:register "example" "FlashCode" "0.1" "GPL3" "Scheme script" "" "")
(weechat:print "" "Hey, I'm a scheme script for WeeChat!")

Sunday, October 2 2011

Game Minesweeper

A new script minesweeper.py is now available, the famous Minesweeper game!

If you are using weeget, just do: /weeget install minesweeper.py

256 colors mode is highly recommended, and mouse support (with WeeChat >= 0.3.6). If you have 16 colors or less, you can do: /minesweeper 16col

For help: /help minesweeper.

Screenshot (click for full size):

Minesweeper

Enjoy!

Saturday, August 20 2011

Game Flood'it

A new script floodit.py is now available! You can now play to Flood'it inside WeeChat, with following features:

  • single mode
  • versus mode (play vs computer)
  • demo mode
  • 3 different board sizes.

If you are using weeget, just do: /weeget install floodit.py

For help: /help floodit.

Note: mouse is supported with latest devel version of WeeChat (0.3.6-dev).

Screenshot (click for full size):

Flood'it

Enjoy!

Saturday, May 2 2009

Data for callbacks in script API

Major changes were done in script API: data string was added to all callbacks. C plugin API is already ok (there is data pointer for callbacks).
Therefore, all scripts for development version are incompatible with this new version. All official scripts have been updated on plugins page.

This data string must be added after each callback function in arguments of functions. For example in python :

weechat.hook_command("go", "Quick jump to buffers", "", "", "", "go_cmd")
(...)
def go_cmd(buffer, args):

becomes:

weechat.hook_command("go", "Quick jump to buffers", "", "", "", "go_cmd", "")
(...)
def go_cmd(data, buffer, args):

Tuesday, April 7 2009

Script weeget.py, a script manager!

A new script weeget.py is now available. It is a scripts manager: you can install, remove, upgrade your scripts using command /weeget.

Following actions are available :

  • update local cache (list of scripts, which automatically expires after one hour by default),
  • show detailed info about scripts,
  • install scripts,
  • remove scripts,
  • upgrade all obsolete scripts,
  • check status of local scripts.

Weeget uses its own configuration file, called wg.conf.

You can setup some options with /set:

  • /set wg.color.installed color (default: yellow)
  • /set wg.color.language color (default: lightblue)
  • /set wg.color.obsolete color (default: lightmagenta)
  • /set wg.color.running color (default: lightgreen)
  • /set wg.color.script color (default: cyan)
  • /set wg.color.unknown color (default: lightred)
  • /set wg.scripts.cache_expire time (default: 60)
  • /set wg.scripts.dir directory (default: %h/weeget)
  • /set wg.scripts.url url (default: http://www.weechat.org/files/plugins.xml.gz)

Updated on 2012-09-29: since version 0.3.9, weeget.py has been replaced by a C plugin called "script" (command /script), see Scripts manager.

Screenshot: WeeChat weeget

Sunday, March 8 2009

Script vdm.py

A new script vdm.py is now available. With that script, you can read fmylife.com and viedemerde.fr websites in WeeChat, using command /vdm.
Help is available with /help vdm when script is loaded.

You can setup some options with /set:

  • /set plugins.var.python.vdm.auto_switch on/off (default: on)
  • /set plugins.var.python.vdm.blank_line on/off (default: on)
  • /set plugins.var.python.vdm.color_number color (default: cyan)
  • /set plugins.var.python.vdm.colors color1;color2;... (default: default;green;brown)
  • /set plugins.var.python.vdm.lang fr/en (default: en)
  • /set plugins.var.python.vdm.numberasprefix on/off (default: on)
  • /set plugins.var.python.vdm.reverse on/off (default: off)
  • /set plugins.var.python.vdm.url url (default: http://api.betacie.com/view/%s?key=readonly&language=%s)

Screenshot: WeeChat vdm

Friday, March 6 2009

New hook "process"

New hook type "process" has been added to WeeChat. You can use it in C plugins, and all scripts languages (perl, python, ruby, lua and tcl).

It runs a command with fork, and send you result (return code, stdout and stderr) via a callback, when command has ended, or if WeeChat output buffer is full (then it will be partial result of command). There is optional timeout (in milliseconds), to kill process if it's still running after given time.

The script shell.py has been updated to use that new hook.

Sunday, February 8 2009

Script go.py

A new script go.py is now available. With that script, you can quickly jump to other buffers, by typing some letters. You can use Tab and shift-Tab keys to select next/previous buffer in list.
Help is available with /help go when script is loaded.

Screenshot: WeeChat go

Sunday, January 4 2009

New version of script iset.pl

Script iset.pl has been improved. Now you can setup colors for option names, types and values. And null values are displayed with different color (for IRC server options). There's new config options, you can set with /set command:

  • /set plugins.var.perl.iset.colorbgselected color
  • /set plugins.var.perl.iset.color_option color
  • /set plugins.var.perl.iset.coloroptionselected color
  • /set plugins.var.perl.iset.color_type color
  • /set plugins.var.perl.iset.colortypeselected color
  • /set plugins.var.perl.iset.color_value color
  • /set plugins.var.perl.iset.colorvalueselected color
  • /set plugins.var.perl.iset.colorvalueundef color
  • /set plugins.var.perl.iset.colorvalueundef_selected color

A screenshot is better than long speech: weechat_iset_2009-01-04.png

Updated on 2017-06-26: the script is now obsolete, replaced by the builtin fset plugin.

Thursday, November 13 2008

Script mastermind.pl

A new script mastermind.pl is now available!

Screenshot: Mastermind

Keys are displayed on buffer displayed by /mastermind, enjoy!

Tuesday, September 2 2008

New version of script buffers.pl

Script buffers.pl has been improved. Now you can hide categories, and there's color for lines according to hotlist (activity on buffers). There's new config options, you can set with /set command:

Hide categories:

  • /set plugins.var.perl.buffers.show_category off

Change colors (replace "color" by your color, which may be "fg" or "fg,bg"):

  • /set plugins.var.perl.buffers.color_number color
  • /set plugins.var.perl.buffers.color_slash color
  • /set plugins.var.perl.buffers.color_hotlist_low color
  • /set plugins.var.perl.buffers.color_hotlist_message color
  • /set plugins.var.perl.buffers.color_hotlist_private color
  • /set plugins.var.perl.buffers.color_hotlist_highlight color

A screenshot is better than long speech: weechat_bar_buffers_2008-09-02.png

Updated on 2017-05-13: the script is now obsolete, replaced by the builtin buflist plugin, introduced in version 1.8.

Saturday, April 19 2008

Script iset.pl

A new script iset.pl is now available. With that script, you can change WeeChat options with better interface than /set.
Help is available with /help iset when script is loaded.

Screenshot: WeeChat iset

Updated on 2017-06-26: the script is now obsolete, replaced by the builtin fset plugin.

Saturday, March 29 2008

Script weetris.pl

A new script weetris.pl is now available! You can now play to your favorite game inside WeeChat :)

Screenshot: WeeTris

Short instructions:

  • keys are:
    • Left/Right/Bottom: move
    • Up: rotate
    • Alt+n: start a new game
  • number of lines are displayed

Incoming features:

  • pause key
  • view of next form
  • save/resume game
  • network game: vs other players (over IRC or other network protocol)

Updated on 2019-09-29: the script has been rewritten in Python: weetris.py.

Saturday, March 15 2008

Bars

Bars have been added to WeeChat. They are used to display informations around chat area. In near future, some existing items will become real bars (like title, nicklist, status, input).
Plugin and script API is now ready for using these bars. Following screenshot is a demo of scripts buffers.pl and uptime.pl:

Updated on 2008-10-12: new bars are now used: title, nicklist, status, input.

weechat_bars_buffers_uptime.png