commit fac076363a77fb8326f0acf6dcdaad74d4a0ea6c Author: Teika kazura Date: Wed Feb 15 22:00:32 2017 +0900 Adds pager support for "$ eselect news read". Now the command "$ eselect news read" respects the environment variable PAGER. It is used only to show news items, not for e.g. messages like "no news is a good news". When stdin or stderr is not attached to the console, PAGER will not be used. The original code was written by "Teika kazura" (Swap the at-sign and the dot.) The commited version was contributed at Gentoo forum[1] by "steveL" [2]. The latter was chosen because of improvement in bash coding. [1] https://forums.gentoo.org/viewtopic.php?p=8028864#8028864, [2] https://forums.gentoo.org/profile.php?mode=viewprofile&u=146493 The patch applies against 1.4.5 <= app-admin/eselct <= 1.4.8. diff --git a/modules/news.eselect b/modules/news.eselect index 1c6a981..ad9e837 100644 --- a/modules/news.eselect +++ b/modules/news.eselect @@ -274,7 +274,15 @@ do_read() { && echo "No news is good news." fi + local tmp tmpdir tmpfiles=() + tmpdir=$(mktemp --tmpdir -d eselect.news.XXX) || die 'unable to create tmpdir' + + exec 3>&1 for i; do + tmp=$tmpdir/$i + tmpfiles+=("$tmp") + exec >"$tmp" + if ! is_number "${i}" || [[ ${i} -lt 1 || ${i} -gt ${#items[@]} ]] then write_warning_msg "Bad item number: ${i}" @@ -349,6 +357,16 @@ do_read() { has ${repo} ${repos_upd} || repos_upd="${repos_upd} ${repo}" done + exec >&3 3>&- + if ((${#tmpfiles[*]} )); then + if [[ -n $PAGER ]] && [[ -t 0 && -t 2 ]]; then + $PAGER "${tmpfiles[@]}" + else + cat "${tmpfiles[@]}" + fi + fi + rm -fr "$tmpdir" + # update lists of read/unread items for repo in ${repos_upd}; do write_item_list read ${repo} && write_item_list unread ${repo}