From: SÅ‚awomir Nizio Date: Wed, 25 Apr 2012 22:50:57 +0000 (+0200) Subject: Extend eread to allow sorting (bug 413577). X-Git-Tag: gentoolkit-0.3.0.7~27 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a6a159cd3f8c8a89eccbba57689623a747fea73f;p=gentoolkit.git Extend eread to allow sorting (bug 413577). --- diff --git a/bin/eread b/bin/eread index 7d0a970..d74a167 100755 --- a/bin/eread +++ b/bin/eread @@ -5,6 +5,7 @@ # # Author: Donnie Berkholz # Updated by: Uwe Klosa +# Updated by: Slawomir Nizio # 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} diff --git a/man/eread.1 b/man/eread.1 index 5e18214..c58c7eb 100644 --- a/man/eread.1 +++ b/man/eread.1 @@ -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.