tlwiki/content/misc/archive/thurstylark-vps/weechat.md

7.6 KiB

title description author date draft
Weechat Because lurking is the best Thurstylark 2021-9-25 false

Current configuration can always be found at https://git.thurstylark.com/vcsh/weechat.git

##Requirements:

  • Not dependent on graphical session (terminal-based client)
  • Use only one nick during normal operation
  • Use multiple computers interchangeably at random
  • Do not require a close/quit process to move between workstations
  • Reduce the ammount of join/part messages caused by me
  • Be reachable through IRC as much as possible (stay online)
  • Have the ability to use a mobile app at will

The best option so far is weechat run in a multiplexer like tmux.


Starting Weechat

Easiest way to get this done is to start weechat at boot with a systemd system service:

[Unit]
Description=Start Weechat as relay and client

[Service]
Type=forking
User=thurstylark
Group=thurstylark
ExecStart=/usr/bin/tmux -f /home/thurstylark/.config/srv-tmux.conf new-session -ds weechat weechat 


[Install]
WantedBy=multi-user.target

Notes

  • When starting tmux with new-session -d as its command, tmux forks to the background, thus requiring Type=forking in order to let systemd keep track of the process.
  • I run this service as my user and group, because I use the default locations for weechat config: ~/.weechat/. This greatly simplifies weechat configuration.
  • tmux configuration needs to be passed to tmux by using -t /path/to/config. Full path is used just to be thorough.

Configuring tmux

tmux needs a configuration to disable the status bar, visual bell, and other things that won't be useful in this setup.

set -g default-terminal "screen-256color"

set-option -g assume-paste-time 1
set-option -g base-index 1
set-option -g pane-base-index 1
set-option -g default-command ""
set-option -g default-shell "/bin/bash"
set-option -g destroy-unattached off
set-option -g detach-on-destroy on
set-option -g display-panes-active-colour red
set-option -g display-panes-colour blue
set-option -g display-panes-time 1000
set-option -g display-time 750
set-option -g history-limit 10000
set-option -g word-separators " -_@"
set-option -g renumber-windows off
set-option -g repeat-time 500
set-option -g set-remain-on-exit off
set-option -g set-titles off
set-option -g set-titles-string "#S:#I:#W - "#T" #{session_alerts}"
set-option -g status off

- Change prefix to C-a
set-option -g prefix C-a

set-option -g status-style fg=black,bg=cyan
set-option -g message-command-style fg=green,bg=black
set-option -g message-style fg=white,bg=red
set-option -g update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

- Set audible bell on, and visual bell off because it is slooooowwwww 
set-option -g bell-action any
set-option -g bell-on-alert on
set-option -g visual-bell off
set-option -g visual-silence off
set-option -g visual-activity off

- Pane active colors
set-option -g pane-active-border-style fg=cyan,bright

- Pane inactive colors
set-option -g pane-border-style fg=colour8

- Use C-a,Shift-R to reload configuration
bind R source-file ~/.tmux.conf \; display-message "Config reloaded..."

- Use C-a,a to send prefix to nested session
bind-key a send-prefix

- Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
- Do the same for HJKL
bind -n M-h select-pane -L
bind -n M-l select-pane -R
bind -n M-k select-pane -U
bind -n M-j select-pane -D

- No delay for escape key press
set -sg escape-time 0

- Various copy mode tweaks
bind-key -t vi-copy Home start-of-line
bind-key -t vi-copy End end-of-line
- Sync copy mode and PRIMARY selection
bind-key -t vi-copy MouseDragEnd1Pane copy-pipe "xsel -i -p -b"
bind-key -t vi-copy Enter copy-pipe "xsel -i -p -b"
bind-key -t vi-copy y copy-pipe "xsel -i -p -b"

Usage

I will usually use this within yet another tmux session, so I end up needing to set up some key bindings to control the differrent sessions

  • C-a a: Send prefix to the terminal
  • C-a a d: Disconnect the nested session from this client.
  • C-a a :: Get command prompt on nested session

Weechat Relay

Here are all the options related to weechat relay:

[cmd] (alias.conf)
  alias.cmd.norelay = "/buffer set localvar_set_relay hard-hide"
[look] (relay.conf)
  relay.look.auto_open_buffer = off  (default: on)
  relay.look.raw_messages = 256
[color] (relay.conf)
  relay.color.client = cyan
  relay.color.status_active = lightblue
  relay.color.status_auth_failed = lightred
  relay.color.status_connecting = yellow
  relay.color.status_disconnected = lightred
  relay.color.status_waiting_auth = brown
  relay.color.text = default
  relay.color.text_bg = default
  relay.color.text_selected = white
[network] (relay.conf)
  relay.network.allow_empty_password = off
  relay.network.allowed_ips = ""
  relay.network.bind_address = "127.0.0.1"  (default: "")
  relay.network.clients_purge_delay = 0
  relay.network.compression_level = 6
  relay.network.ipv6 = off  (default: on)
  relay.network.max_clients = 5
  relay.network.password = "letmein"  (default: "")
  relay.network.ssl_cert_key = "%h/ssl/relay.pem"
  relay.network.ssl_priorities = "NORMAL:-VERS-SSL3.0"
  relay.network.websocket_allowed_origins = ""
[irc] (relay.conf)
  relay.irc.backlog_max_minutes = 1440
  relay.irc.backlog_max_number = 256
  relay.irc.backlog_since_last_disconnect = on
  relay.irc.backlog_since_last_message = off
  relay.irc.backlog_tags = "irc_privmsg"
  relay.irc.backlog_time_format = "[%H:%M] "
[port] (relay.conf)
  relay.port.weechat = 9001  (default: 0)

Notes

  • alias.cmd.norelay = "/buffer set localvar_set_relay hard-hide
    • Creates the /norelay command which is used to hide a buffer from being relayed to any relay client. This is mainly for stopping a buffer from alerting me on mobile.
  • relay.look.auto_open_buffer = off
    • Keeps weechat from opening a buffer with superfluous information every time a client connects or disconnects
  • relay.network.bind_address = "127.0.0.1"
    • Weechat will only accept relay connections from localhost. This means any relay client that wishes to connect will need to tunnel over ssh first, then connect to the relay. Luckily for me, weechat-android does this natively.
  • relay.port.weechat = 9001
    • The relay client will want to know this.

Reference


Workstation Client

By far, the most use of weechat will be from a workstation. With this setup, the only requirements of the client is ssh or mosh. I prefer mosh in this case because of it's reconnect capabilities, making it much less painful to keep a session running on a mobile workstation.

Also, the easiest way to launch this connection is to run literally weechat, so I set up a couple aliases for this in my ~/.bashrc (found here):

# If you don't have weechat installed, connect to the existing tmux session through mosh
[[ ! -s /usr/bin/weechat ]] && alias weechat='mosh vps -- tmux attach -dt weechat'
# If you are thurstylark-vps, connect to the existing tmux session locally
[[ "$HOSTNAME" = "thurstylark-vps" ]] && alias weechat='tmux attach -dt weechat'

This gets run when bash starts, so this allows me to use the same ~/.bashrc on the client and the server. More details on the Bash page.

The only thing not noted is that if the client has weechat installed (to /usr/bin/weechat) and $HOSTNAME is not "thurstylark-vps", an alias for 'weechat' will not be created, and weechat will launch normally.