$_ BSDHowTo.ch
How To... Why not..? Scripts Patches RSS logo

More great ideas about sic

Last update: 2020-08-30

Introduction

Discussing my article about the IRC client sic on @bsd.network brought up some ideas about extending the user experience.

Add colors to the output

@prx@bsd.network has written a script which allows you to color the output of sic using terminal escape sequences with sed(1):

#!/bin/sh

BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
LGRAY='\033[0;37m'
DGRAY='\033[1;30m'
LRED='\033[1;31m'
LGREEN='\033[1;32m'
YELLOW='\033[1;33m'
LBLUE='\033[1;34m'
LPURPLE='\033[1;35m'
LCYAN='\033[1;36m'
WHITE='\033[0;37m'
NC='\033[0m'
GREEN='\e[32m'
YELLOW='\e[33m'
BOLD='\e[1m'

# Examples:
# color #openbsd channel name to green
# s/^#openbsd/$(printf ${LGREEN}#openbsd${NC})/
# color own nickname and send bell alert
# s/user/$(printf ${PURPLE}user${NC})$(printf "\a")/

sic -n user -k pass -h localhost -p 6667 |\
    sed -E "/(JOIN|NICK|PART|QUIT)/d
        s/^#openbsd/$(printf ${BOLD}${LGREEN}#openbsd${NC})/
        s/user/$(printf ${PURPLE}user${NC})$(printf "\a")/"

Your tmux(1) window will look similar to this:

sic with colors

Input pane for sic in tmux(1)

@prx@bsd.network had another great idea: Create an input pane for sic in tmux(1). With this you can avoid problems when you receive new messages while you type one yourself. This requires two scripts, one for each pane in tmux(1).

The second script is for the input pane. I call it sicin.sh:

#!/bin/sh

prompt="irc> "
pane="irc.0"

while read -r -u input?"${prompt}" ; do
    tmux send -t ${pane} "${input}" Enter
    [[ "${input}" == ":quit" ]] && exit 0
done

The first script creates the new pane in tmux(1) and executes the second script sicin.sh in the new pane. Then it start your sic session. It is called sicirc.sh:

#!/bin/sh

tmux split-window -t irc -v -l 2 ~/bin/sicin.sh
sic -n user -k pass -h localhost -p 6667 | sed -E  "/(JOIN|QUIT)/d"

The scripts are written in a way that you can start them together with tmux(1). This makes it easy to integrate the whole construct in a graphical environment. A command similar to this one will start this:

$ tmux new -s irc -n #openbsd ~/bin/irc.sh

If you use a graphical environment you must start this command with your preferred terminal emulator.

The whole thing will look similar to this screenshot:

sic with input pane in tmux