Reddit dans le terminal - retour accueil
git clone git://bebou.netlib.re/reddit-curses
Log | Files | Refs | README |
sfeed_content (1587B)
1 #!/bin/sh 2 # Content viewer for sfeed(5) lines. 3 4 # The locale is set to "C" for performance. The input is always UTF-8. 5 6 temp=$(mktemp); trap "rm -rf $temp" EXIT 7 cat > $temp 8 9 cat $temp | 10 if $(grep -q "id : t3_" $temp) 11 then 12 comlink=$(grep -Eo 't3_.{7}' $temp) 13 reddio print -i 4 -c always -l 50 -s top comments/$comlink | 14 sed -E 's,^\[,\x1b[92m[,' | 15 fmt -s | 16 less -R 17 else 18 LC_ALL=C awk -F '\t' ' 19 function unescape(s) { 20 # use the character "\x01" as a temporary replacement for "\". 21 gsub("\\\\\\\\", "\x01", s); 22 gsub("\\\\n", "\n", s); 23 gsub("\\\\t", "\t", s); 24 gsub("\x01", "\\", s); # restore "\x01" to "\". 25 return s; 26 } 27 BEGIN { 28 htmlconv = ENVIRON["SFEED_HTMLCONV"]; 29 if (!length(htmlconv)) 30 htmlconv = "lynx -stdin -dump " \ 31 "-underline_links -image_links " \ 32 "-display_charset=\"utf-8\" -assume_charset=\"utf-8\" "; 33 } 34 { 35 if (previtem) 36 print "\f"; 37 previtem = 1; 38 39 print "Title: " $2; 40 if (length($7)) 41 print "Author: " $7; 42 if (length($9)) { 43 categories = $9; 44 gsub("\\|", ", ", categories); 45 print "Category: " categories; 46 } 47 if (length($3)) 48 print "Link: " $3; 49 if (length($8)) 50 print "Enclosure: " $8; 51 if (!length($4)) 52 next; 53 print ""; 54 if ($5 == "html") { 55 # use the link of the item as the base URL for relative URLs in 56 # HTML content. 57 base = $3; 58 if (length(base)) { 59 gsub("\"", "%22", base); # encode quotes. 60 base = "<base href=\"" base "\"/>\n"; 61 } 62 print base unescape($4) | htmlconv; 63 close(htmlconv); 64 } else { 65 print unescape($4); 66 } 67 }' "$@" | \ 68 ${PAGER:-less -R} 69 fi