Skip to content
Sébastien Helleu edited this page Nov 6, 2022 · 52 revisions

Tips, keybindings, ideas...

Image of color settings

settings

Nick color palettes for 256-color terminal

saturation 1.0, value 0.53, suitable for light background

/set weechat.color.chat_nick_colors 88,94,100,64,28,29,30,24,18,54,90,89
saturation 0.31, value 1.0, suitable for dark background

/set weechat.color.chat_nick_colors 217,223,229,193,157,158,159,153,147,183,219,218

Keybindings

Modify a key binding

/key bind meta-+ /input insert /bind\x20; /input grab_key_command

Scroll an hour up/down (alt-shift-p/n)

/key bind meta-P /window scroll -1h
/key bind meta-N /window scroll +1h

Filter

Filter nick changes in which only letter case changes

/filter add changesamenick * irc_nick ^(\S+) is now known as \1$

Filter join/left/quit/nick messages in backlog (for english only!)

/filter add backlogtidy * logger_backlog ^\S+ \(\S+\) has (joined|left|quit) |^\S+ is now known as \S+$

Miscellaneous

Go to cursor mode on the last chat line

/cursor go status ; /cursor move up ; /cursor move area_right ; /cursor move up ; /cursor move up

Swap two non-active windows

/window swap -window 2 right

Add colors to places without a dedicated color setting

/eval /set weechat.look.hotlist_prefix "${color:red}H: "

Use normal nick suffix in same nick prefix

/eval /set weechat.look.prefix_same_nick ${color:${weechat.color.chat_nick_suffix}}${weechat.look.nick_suffix}

Backup weechat configs

tar --exclude ~/.weechat/logs -acvf ~/weechat-backup-$(date +%y-%m-%d).tar.gz ~/.weechat
/exec -sh -bg tar --exclude ~/.weechat/logs -acvf ~/weechat-backup-$(date +%y-%m-%d).tar.gz ~/.weechat

Autostart tmux + WeeChat

## Environment
# To avoid having to type absolute paths, append output of `printf "$PATH"`
PATH=
# Locale you wish to use
LANG=fi_FI.UTF-8
# Timezone
TZ=Europe/Helsinki

# The actual autostart magic
@reboot sleep 300 && tmux -2u new-session -s auto -d weechat
  • @reboot = tell cron to do this on reboot
  • sleep 300 = the shell where I intent to use this primarily is using NFS and I think it’s reasonable to expect everything to be mounted in five minutes.
  • tmux -2u = force enable 256 colors & UTF-8
  • new-session -s auto -d weechat = start a new session with name auto (as in automatically started), detach it and run command weechat in it

Aggregate old logs

  • I assume logger.file.mask="$plugin.$name/%Y/%m/%d.log"
  • Clean up per day logs manually after this script has run successfully
  • Have backups, be careful and improve this script :)
cd ~/.weechat/logs/
for ITEM in */ ; do
        for YEAR in $(seq 2014 2017) ; do
                test -d "$ITEM/$YEAR" || continue
                test -f "$ITEM/$YEAR.log" && continue
                echo -n "${ITEM%%/*} :: $YEAR ::       " >&2
                for MONTH in $(seq  -f "%02.0f" 1 12) ; do
                        test -d "$ITEM/$YEAR/$MONTH" || continue
                        echo -n -e "\b\b\b\b\b\b$MONTH :: " >&2
                        for DAY in $(seq -f "%02.0f" 01 31) ; do
                                test -f "$ITEM/$YEAR/$MONTH/$DAY.log" \
                                        && cat "$ITEM/$YEAR/$MONTH/$DAY.log"
                        done
                done > "$ITEM/$YEAR.log"
                echo -e "\b\b\b\b\b\bdone ($(du -h "$ITEM/$YEAR.log" |sed -e 's,\s.*,,'))" >&2
        done
done

Script to filter weechat logs to remove non-user messages

This will show a log file excluding lines that have --, <--, or --> in the third column. It also optional can take a start and end date to filter the range it will show from.
(This outputs to stdout and does not modify the log file, so you can pipe, or redirect the output wherever you need.)

#!/bin/sh

#==========================
#
# TODO: 
#  1. Add checks for correct date format, trigger showHelp if bad
#
#==========================

showHelp() {
    printf '==== Weechat Log Filter ====\n\n'
    printf 'Usage: %s <log file> [start date] [end date]\n\n' "$(basename "${0}")"
    printf 'Start and end dates should be in dashed ISO 8601 Format\n    Example: 2018-01-01\n\n'
}

case "${1}" in
    "-h"|"--help")
        showHelp
        exit 0
        ;;
esac

if [ -n "${1}" ] && [ -f "${1}" ]; then
    if [ -n "${2}" ]; then
        if [ -n "${3}" ]; then
            awk \
                -v startdate="${2}" \
                -v enddate="${3}" \
                '$3 !~ "<?-->?" && $1>=startdate && $1<=enddate {print $0}' "${1}"
        else
            awk \
                -v startdate="${2}" \
                '$3 !~ "<?-->?" && $1>=startdate {print $0}' "${1}"
        fi
    else
        awk '$3 !~ "<?-->?" { print $0 }' "${1}"
    fi
else
    echo "File Not Specified or Specified File Does Not Exist"
fi

Simple ZNC connection with terminal dialog password prompt (.bashrc)

alias weechat='ZNCPASS=$(dialog --passwordbox "Enter ZNC Bouncer Password" 0 0 3>&1- 1>&2- 2>&3-) ; weechat -t -r "/set irc.server_default.ssl_verify off ; /server add freenode ${ZNC_SERVER_IP}/${ZNC_SERVER_PORT} -ssl -username=${YOUR_USERNAME}/freenode -password=${YOUR_ZNC_PASSWORD} -autoconnect"'

text_item.py examples, create your own items.

IMPORTANT: all these items are for WeeChat ≤ 3.5. For WeeChat ≥ 3.6 use the /item command.

Show status of global filter AND filter per buffer (item name: 'filter_item')

/set plugins.var.python.text_item.filter_item "!all|*filters* ${if:${info:filters_enabled}==1?${color:yellow}F:${color:243}F}${if:${buffer.filter}==1?${color:yellow}@:${color:243}@}"

Show number of relay clients (item name: 'relay_count')

/set plugins.var.python.text_item.relay_count "all|relay_client_* ${info:relay_client_count,connected}"

Show different text for away (item name: 'my_away')

/set plugins.var.python.text_item.my_away "!all|buffer_switch ${if:${away}!=0?${color:gray}zZzZ}"

Show terminal size (item name: 'dimension')

/set plugins.var.python.text_item.dimension "all|signal_sigwinch width: ${info:term_width} height: ${info:term_height}"

Replace the original 'scroll' (-MORE-) item (item name: 'my_scroll')

/set plugins.var.python.text_item.my_scroll "!all|window_scrolled ${if:${window.scroll.lines_after}==0?:${color:*yellow}${window.scroll.lines_after}}"

Show Loglevel for current buffer (item name: 'loglevel')

/set plugins.var.python.text_item.loglevel "all|buffer_switch ${if:${logger.level.${window.buffer.full_name}}>0?${logger.level.${window.buffer.full_name}}:}"

Show the char "C" when you are in cursor mode (item name: 'cursor_mode')

For Weechat <= 3.1:

/set plugins.var.python.text_item.cursor_mode "all|key_combo_cursor ${if:${info:cursor_mode}==1?${color:yellow}C}"

For WeeChat ≥ 3.2 (less CPU usage!):

/set plugins.var.python.text_item.cursor_mode "all|cursor_* ${if:${info:cursor_mode}==1?${color:yellow}C}"

The dict indicator will also show the status of the spell plugin (enabled|disabled) (item name: 'my_spell_dict')

/set plugins.var.python.text_item.my_spell_dict "!all|buffer_switch ${if:${eval:${spell.dict.${buffer.full_name}}}!=''?${if:${eval:${spell.check.enabled}}==1?${color:yellow}${eval:${spell.dict.${buffer.full_name}}}:${color:238}${eval:${spell.dict.${buffer.full_name}}}}:}"
Clone this wiki locally