tailcat

#!/usr/bin/env rc
# output last part of a file to stderr, concatenate files and print on stdout
# use with ii irc client: cd irc/chat.frenode.org/'#cat-v'; tailcat out > in
if (test -z $1) {
  echo 'Usage: '^$0^' [FILE]'
  exit 1
}
fn sigexit sigint sigquit sigtrap sighup {
  tput rmcup >[1=2]
  test $apids && kill -$apids
}
tput smcup >[1=2]
file=$1
thome=`{tput home}
tsc=`{tput sc}
trc=`{tput rc}
fn _init {
  cols=`{tput cols}
  lines=`{expr `{tput lines} - 1}
  tdlil=`{tput dl $lines; tput il $lines}
}
fn _render {
  echo -n $tsc$thome$tdlil
  tail -n$lines $1 | fmt -w$cols -s | tail -n$lines
  echo -n $trc
}
_init
tail -n$lines $file | fmt -w$cols -s | tail -n$lines >[1=2]
tail -n0 -f $file | while (line >/dev/null) {_render $file >[1=2]} &
cat