From 5a95ecaec756cc02a1c7493811c5f86bd7747a91 Mon Sep 17 00:00:00 2001 From: Teika Kazura Date: Thu, 9 Apr 2020 10:16:32 +0900 Subject: [PATCH] eselect-1.4.16 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 to 1.4.16. --- modules/news.eselect | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/news.eselect b/modules/news.eselect index 15e5cb6..5817164 100644 --- a/modules/news.eselect +++ b/modules/news.eselect @@ -284,7 +284,17 @@ 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}"; then if (( i < 1 || i > n )); then write_warning_msg "Bad item number: ${i}" @@ -370,6 +380,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} -- 2.24.1