rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | README | LICENSE

news.sh (1279B)


      1 #!/bin/bash
      2 
      3 reset="$(tput sgr0)"
      4 titleformat="$(tput bold)"
      5 idformat="$(tput bold)"
      6 dateformat="$(tput setaf 3)"
      7 subjectformat="$reset"
      8 
      9 first=1
     10 
     11 cols=$(tput cols)
     12 
     13 while read -r line;
     14 do
     15 	id=$(echo -n "$line" | cut -f 1 | sed 's,^rp:,rpo:,')
     16 	date=$(echo -n "$line" | cut -f 2 | head -c 10)
     17 	subject=$(echo -n "$line" | cut -f 4)
     18 
     19 	if [ $first -eq 1 ];
     20 	then
     21 		#printf "${titleformat}%8s  %10s  %s\n" "$id" "$date" \
     22 		#	"$subject"
     23 		first=0
     24 	else
     25 		ostr="$(printf "${dateformat}%10s${reset}" "$date")"
     26 		flen=$(($(utf8expr length "$date") + 2))
     27 		ostr="${ostr}  $(printf "${idformat}%s${reset}" "$id")"
     28 		flen=$(($flen + $(utf8expr length "$id") + 2))
     29 		scols=$(($cols - $flen))
     30 
     31 		printf "%s  " "${ostr}"
     32 		slen=$(utf8expr length "$subject")
     33 		if [ $scols -lt 1 ] || [ $scols -gt $slen ];
     34 		then
     35 			printf "${subjectformat}%s${reset}\n" "$subject"
     36 		else
     37 			pos=1
     38 			while [ $slen -gt 0 ];
     39 			do
     40 				if [ $slen -gt $scols ];
     41 				then
     42 					sslen=$scols
     43 				else
     44 					sslen=$slen
     45 				fi
     46 
     47 				sstr=$(utf8expr substr "$subject" $pos \
     48 					$sslen | sed 's,^[[:space:]]*,,g')
     49 				if [ $pos -gt 1 ];
     50 				then
     51 					printf "%${flen}s" " "
     52 				fi
     53 				printf "${subjectformat}%s${reset}\n" \
     54 					"$sstr"
     55 
     56 				pos=$(($pos + $sslen))
     57 				slen=$(($slen - $sslen))
     58 			done
     59 		fi
     60 	fi
     61 done
     62