aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Müller <ulm@gentoo.org>2019-05-26 17:13:43 +0200
committerUlrich Müller <ulm@gentoo.org>2019-05-26 17:13:43 +0200
commit61cb8c82e0ecb918b84a5ecdd7bf2f574bfe5212 (patch)
tree35557897a921cddaac65daf547e53b8d03c04c5b
parentUpdate version to 1.4.14. (diff)
downloadeselect-61cb8c82e0ecb918b84a5ecdd7bf2f574bfe5212.tar.gz
eselect-61cb8c82e0ecb918b84a5ecdd7bf2f574bfe5212.tar.bz2
eselect-61cb8c82e0ecb918b84a5ecdd7bf2f574bfe5212.zip
Allow specification of news item by its name.
* modules/news.eselect (do_read, do_unread): Allow specification of item by its number or name. (describe_read_options, describe_unread_options): Document it. Signed-off-by: Ulrich Müller <ulm@gentoo.org>
-rw-r--r--ChangeLog6
-rw-r--r--modules/news.eselect42
2 files changed, 38 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 20ecfab..bc42d2a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-05-26 Ulrich Mueller <ulm@gentoo.org>
+
+ * modules/news.eselect (do_read, do_unread): Allow specification
+ of item by its number or name.
+ (describe_read_options, describe_unread_options): Document it.
+
2019-02-17 Ulrich Mueller <ulm@gentoo.org>
* configure.ac: Update version to 1.4.14.
diff --git a/modules/news.eselect b/modules/news.eselect
index 5f3303b..15e5cb6 100644
--- a/modules/news.eselect
+++ b/modules/news.eselect
@@ -251,7 +251,7 @@ describe_read_options() {
echo "--raw : Output in raw format"
echo "new : Read unread news items (default)"
echo "all : Read all news items"
- echo "item : Number of item (from 'list' action)"
+ echo "item : Item name or number (from 'list' action)"
}
describe_read_parameters() {
@@ -285,10 +285,21 @@ do_read() {
fi
for i; do
- if ! is_number "${i}" || [[ ${i} -lt 1 || ${i} -gt ${#items[@]} ]]
- then
- write_warning_msg "Bad item number: ${i}"
- continue
+ if is_number "${i}"; then
+ if (( i < 1 || i > n )); then
+ write_warning_msg "Bad item number: ${i}"
+ continue
+ fi
+ else
+ # item can be specified by name
+ item=${i}
+ for (( i = 1; i <= n; i++ )); do
+ [[ ${items[i-1]#*/*/} = "${item}" ]] && break
+ done
+ if (( i > n )); then
+ write_warning_msg "Item not found: ${item}"
+ continue
+ fi
fi
item=${items[--i]}
stat=${item%%/*}; item=${item#*/}
@@ -373,7 +384,7 @@ describe_unread() {
describe_unread_options() {
echo "all : Mark all news items as unread"
- echo "item : Number of item (from 'list' action)"
+ echo "item : Item name or number (from 'list' action)"
}
describe_unread_parameters() {
@@ -393,10 +404,21 @@ do_unread() {
fi
for i; do
- if ! is_number "${i}" || [[ ${i} -lt 1 || ${i} -gt ${#items[@]} ]]
- then
- write_warning_msg "Bad item number: ${i}"
- continue
+ if is_number "${i}"; then
+ if (( i < 1 || i > n )); then
+ write_warning_msg "Bad item number: ${i}"
+ continue
+ fi
+ else
+ # item can be specified by name
+ item=${i}
+ for (( i = 1; i <= n; i++ )); do
+ [[ ${items[i-1]#*/*/} = "${item}" ]] && break
+ done
+ if (( i > n )); then
+ write_warning_msg "Item not found: ${item}"
+ continue
+ fi
fi
item=${items[--i]}
stat=${item%%/*}; item=${item#*/}