Extend eread to allow sorting (bug 413577).
authorSÅ‚awomir Nizio <slawomir.nizio@sabayon.org>
Wed, 25 Apr 2012 22:50:57 +0000 (00:50 +0200)
committerPaul Varner <fuzzyray@gentoo.org>
Thu, 26 Apr 2012 03:31:07 +0000 (22:31 -0500)
bin/eread
man/eread.1

index 7d0a97045006e349d01d35fa202787e22aca4b75..d74a16756f93a2de76c8fb4b4c3ab39034e8fa57 100755 (executable)
--- a/bin/eread
+++ b/bin/eread
@@ -5,6 +5,7 @@
 #
 # Author: Donnie Berkholz <spyderous@gentoo.org>
 # Updated by: Uwe Klosa <uwe.klosa@gmail.com>
+# Updated by: Slawomir Nizio <slawomir.nizio@sabayon.org>
 
 # Get prefix
 EPREFIX=${EPREFIX:-$(portageq envvar EPREFIX)}
@@ -30,9 +31,33 @@ fi
 # Set up select prompt
 PS3="Choice? "
 
+SORT=${EREAD_SORT_ORDER}
+
+find_unsorted() {
+       find . -type f | sed -e "s:\./::g"
+}
+find_by_name() {
+       find . -type f | sort | sed -e "s:\./::g"
+}
+find_by_time() {
+       find . -type f | sort -k 3 -t : | sed -e "s:\./::g"
+}
+find_files() {
+       case ${SORT} in
+               alphabet)
+                       find_by_name
+                       ;;
+               time)
+                       find_by_time
+                       ;;
+               *)
+                       find_unsorted
+               ;;
+       esac
+}
+
 select_loop() {
-       ANY_FILES=$(find . -type f)
-       ANY_FILES=$(echo ${ANY_FILES} | sed -e "s:\./::g")
+       ANY_FILES=$(find_files)
 
        if [[ -z ${ANY_FILES} ]]; then
                echo "No log items to read"
@@ -51,6 +76,12 @@ select_loop() {
                                QUIT="yes"
                                break
                                ;;
+                       a)
+                               SORT="alphabet"
+                               ;;
+                       t)
+                               SORT="time"
+                               ;;
                        *)
                                if [ -f "$FILE" ]; then
                                        ${PAGER} ${FILE}
index 5e18214f957121a91d888549aa1ca7f806f4b77d..c58c7ebb6714ab17593701f0cb0e487e0015257a 100644 (file)
@@ -8,5 +8,18 @@ eread
 .SH "DESCRIPTION"
 .LP 
 This tool is used to display and manage ELOG files produced by portage version 2.1 and higher.
+.SH "USAGE"
+.LP
+You can use the following commands:
+.TP
+.B "q"
+Quit
+.TP
+.B "a"
+Sort alphabetically
+.TP
+.B "t"
+Sort by time
 .SH "ENVIRONMENT VARIABLES"
 The eread utility uses the PAGER environment variable to display the ELOG files. If the variable is not set, it defaults to /usr/bin/less.
+Another environment variable is EREAD_SORT_ORDER which can be set to specify default sort order of ELOG files. Values \fBalphabet\fP and \fBtime\fP are recognized. If EREAD_SORT_ORDER is not set or has another value, the output is unsorted.