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

flag.sh (970B)


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