<commit_before>#!/usr/bin/env sh
# <NAME> V Kanakarakis (http://c00kiemon5ter.github.com)
# for noncopyright information see UNLICENSE file http://unlicense.org/ .
#
# frontend to ii/iim for a single channel
# follows the tail of the out file
# and redirects input to the in file

: "${n:=$USER}"             # the user's nickname
: "${i:=$HOME/irc}"         # root irc dir
: "${s:=irc.freenode.net}"  # server
: "${c:=""}"                # channel
: "${m:=12}"                # max nick lenght
: "${w:=120}"               # max characters per mesg - fold after limit
: "${h:=20}"                # lines from history
: "${p:=1}"                 # prefity - colors and special patterns

[ "$1" != '-r' ] && exec rlwrap -a -r -S "${c:-$s}> " -pGREEN "$0" -r

infile="$i/$s/$c/in"
outfile="$i/$s/$c/out"
sepr='|'

# colors
reset="$(tput sgr0)"
dark="$(tput setaf 8)"
bright="$(tput setaf 3)"

# markup
sb="$(tput bold; tput setaf 9)"
eb="$(tput sgr0; tput sgr0)"
su="$(tput smul; tput setaf 11)"
eu="$(tput rmul; tput sgr0)"
si="$(tput sitm; tput setaf 13)"
ei="$(tput ritm; tput sgr0)"

[ -p "$infile"  ] || exit 1
[ -e "$outfile" ] || { touch "$outfile" || exit 1; }

tail -f -n "$h" "$outfile" | while IFS= read -r line
do
	unset date time nick mesg ctcp

	date="${line%% *}" line="${line#* }"
	time="${line%% *}" line="${line#* }"
	nick="${line%% *}" line="${line#* }"

	# strip '<nick>' to 'nick'
	nick="${nick#<}" nick="${nick%>}"

	# do not notify of server messages
	[ "$nick" != '-!-' ] && tput bel

	# prettify
	if [ "$p" -ne 0 ]
	then
		unset clrdate clrnick clrsepr clrmesg

		clrdate="${dark}"
		case "$line" in *"$n"*) clrdate="${bright}" ;; esac

		clrnick="$(printf '(%d ^ %d + %d)' "${#nick}" "'$nick" "'${nick#?}")"
		clrnick="$(( clrnick % 14 + 1 ))"
		clrnick="$(tput setaf "$clrnick")"

		clrsepr="${dark}"

		clrmesg="${reset}"
		[ "$nick" = '-!-' ] && clrmesg="${dark}"

		[ "${line#}" != "${line}" ] && clrmesg="${clrnick}"
	fi

	# handle CTCP messages
	if [ "${line#}" != "${line}" ]
	then
		line="${line#}"
		line="${line%}"
		ctcp="${line%% *}"
		line="${line#* }"

		if [ "$ctcp" != 'ACTION' ]
		then line="[CTCP:${ctcp}]${reset} ${line}"
		else line="${nick}${reset} ${line}" nick="*"
		fi
	fi

	# fold lines breaking on spaces if message is greater than 'w' chars
	echo "$line" | fold -s -w "$w" | while IFS= read -r mesg; \
	do
		[ "$p" -gt 1 ] && mesg="$(echo "$mesg" | sed \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([_][[:alnum:][:punct:]]\+[_]\)\([[:punct:][:space:]]\|$\),\1${su}\2${eu}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([_][[:alnum:][:punct:]]\+[_]\)\([[:punct:][:space:]]\|$\),\1${su}\2${eu}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([/][[:alnum:][:punct:]]\+[/]\)\([[:punct:][:space:]]\|$\),\1${si}\2${ei}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([/][[:alnum:][:punct:]]\+[/]\)\([[:punct:][:space:]]\|$\),\1${si}\2${ei}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([*][[:alnum:][:punct:]]\+[*]\)\([[:punct:][:space:]]\|$\),\1${sb}\2${eb}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([*][[:alnum:][:punct:]]\+[*]\)\([[:punct:][:space:]]\|$\),\1${sb}\2${eb}\3,g")"
<commit_msg>iii: if maximum width is greater than available use the latter<commit_after>#!/usr/bin/env sh
# <NAME> Kanakarakis (http://c00kiemon5ter.github.com)
# for noncopyright information see UNLICENSE file http://unlicense.org/ .
#
# frontend to ii/iim for a single channel
# follows the tail of the out file
# and redirects input to the in file

: "${n:=$USER}"             # the user's nickname
: "${i:=$HOME/irc}"         # root irc dir
: "${s:=irc.freenode.net}"  # server
: "${c:=""}"                # channel
: "${m:=12}"                # max nick lenght
: "${w:=120}"               # max characters per mesg - fold after limit
: "${h:=20}"                # lines from history
: "${p:=1}"                 # prefity - colors and special patterns

[ "$1" != '-r' ] && exec rlwrap -a -r -S "${c:-$s}> " -pGREEN "$0" -r

infile="$i/$s/$c/in"
outfile="$i/$s/$c/out"
sepr='|'

# colors
reset="$(tput sgr0)"
dark="$(tput setaf 8)"
bright="$(tput setaf 3)"

# markup
sb="$(tput bold; tput setaf 9)"
eb="$(tput sgr0; tput sgr0)"
su="$(tput smul; tput setaf 11)"
eu="$(tput rmul; tput sgr0)"
si="$(tput sitm; tput setaf 13)"
ei="$(tput ritm; tput sgr0)"

[ -p "$infile"  ] || exit 1
[ -e "$outfile" ] || { touch "$outfile" || exit 1; }

tail -f -n "$h" "$outfile" | while IFS= read -r line
do
	unset date time nick mesg ctcp

	date="${line%% *}" line="${line#* }"
	time="${line%% *}" line="${line#* }"
	nick="${line%% *}" line="${line#* }"

	# strip '<nick>' to 'nick'
	nick="${nick#<}" nick="${nick%>}"

	# do not notify of server messages
	[ "$nick" != '-!-' ] && tput bel

	# prettify
	if [ "$p" -ne 0 ]
	then
		unset clrdate clrnick clrsepr clrmesg

		clrdate="${dark}"
		case "$line" in *"$n"*) clrdate="${bright}" ;; esac

		clrnick="$(printf '(%d ^ %d + %d)' "${#nick}" "'$nick" "'${nick#?}")"
		clrnick="$(( clrnick % 14 + 1 ))"
		clrnick="$(tput setaf "$clrnick")"

		clrsepr="${dark}"

		clrmesg="${reset}"
		[ "$nick" = '-!-' ] && clrmesg="${dark}"

		[ "${line#}" != "${line}" ] && clrmesg="${clrnick}"
	fi

	# handle CTCP messages
	if [ "${line#}" != "${line}" ]
	then
		line="${line#}"
		line="${line%}"
		ctcp="${line%% *}"
		line="${line#* }"

		if [ "$ctcp" != 'ACTION' ]
		then line="[CTCP:${ctcp}]${reset} ${line}"
		else line="${nick}${reset} ${line}" nick="*"
		fi
	fi

	# fold lines breaking on spaces if message is greater than 'w' chars or does not fit
	mw="$(($(tput cols) - ${#date} - ${#time} - $m - 5))"
	[ "$mw" -gt "$w" ] && mw="$w"
	echo "$line" | fold -s -w "$mw" | while IFS= read -r mesg; \
	do
		[ "$p" -gt 1 ] && mesg="$(echo "$mesg" | sed \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([_][[:alnum:][:punct:]]\+[_]\)\([[:punct:][:space:]]\|$\),\1${su}\2${eu}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([_][[:alnum:][:punct:]]\+[_]\)\([[:punct:][:space:]]\|$\),\1${su}\2${eu}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([/][[:alnum:][:punct:]]\+[/]\)\([[:punct:][:space:]]\|$\),\1${si}\2${ei}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([/][[:alnum:][:punct:]]\+[/]\)\([[:punct:][:space:]]\|$\),\1${si}\2${ei}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([*][[:alnum:][:punct:]]\+[*]\)\([[:punct:][:space:]]\|$\),\1${sb}\2${eb}\3,g" \
			-e "s,\(^\|[[:space:]][[:punct:]]*\)\([*][[:alnum:][:punct:]]\+[*]\)\([[:punct:][:space:]]\|$\),\1${sb}\2${eb}\3,g")"

{'fraction_non_alphanumeric': 0.33426443202979517, 'fraction_numerical': 0.015673494723774054, 'mean_word_length': 3.5259831460674156, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25012', 'n_tokens_mistral': 2932, 'n_tokens_neox': 2720, 'n_words': 567}