Skip to content

Commit

Permalink
switch to awk to handle bold underline italics and links and add colo…
Browse files Browse the repository at this point in the history
…rs to denote each
  • Loading branch information
c00kiemon5ter committed Nov 6, 2012
1 parent cdbe647 commit 6cb087e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions iii.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ tail -f -n "$h" "$i/$n/$c/out" | while read -r date time nick mesg; do

# pretify special symbols around words
# *bold* _underline_ /italics/ and underline urls
mesg="$(echo "$mesg" \
| sed "s#\(^\|[[:space:]*_]\)/\([^[:space:]\]*\)/\([,*_[:space:]]\|$\)#\1$(tput sitm)/\2/$(tput ritm)\3#g" \
| sed "s#\(^\|[[:space:]*m]\)_\([^[:space:]]*\)_\([,*[:space:]]\|$\)#\1$(tput smul)\2$(tput rmul)\3#g" \
| sed "s#\(^\|[[:space:]]\)\*\([^[:space:]]*\)\*\([,[:space:]]\|$\)#\1$(tput bold; tput setaf 1)*\2*$wht\3#g" \
| sed "s#\(http\|www\)://[^[:space:]]\+#$(tput smul)&$(tput rmul)#g"
)"
mesg="$(echo "$mesg" | awk -vis="$(tput sitm; tput setaf 05)" -vie="$(tput ritm)${wht}" \
-vus="$(tput smul; tput setaf 03)" -vue="$(tput rmul)${wht}" \
-vbs="$(tput bold; tput setaf 01)" -vbe="$(tput sgr0)${wht}" \
-vls="$(tput smul; tput setaf 11)" -vle="$(tput rmul)${wht}" '
{
for (i=1; i<=NF; i++)
if ($i ~ /^_[^_]/ && $i ~ /[^_]_$/) {
sub($i, us substr($i, 2, length($i) - 2) ue)
} else if ($i ~ /^[*]/ && $i ~ /[*]$/) {
sub($i"[*]", bs $i be)
} else if ($i ~ /^[/]/ && $i ~ /[/]$/) {
sub($i, is $i ie)
} else if ($i ~ /^http/) {
sub($i, ls $i le)
}
print
}'
)"

# value between 1 and 14 - avoid black and white (though there's 7 and 8 in there)
# color value is based on the length and first and second letter of the nick
Expand Down

0 comments on commit 6cb087e

Please sign in to comment.