From 722c8b23635c2d0b6d178d6866700ec2881b4443 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Mon, 4 Sep 2017 22:38:26 +0200 Subject: [PATCH] [FIXUP] Append unread news items It's always guaranteed that unread news items from 'newsUnreadIdsFile' are not already present in 'newsUnreadIdsFile'. Thanks @nonsequitur! --- home-manager/home-manager | 13 +++++-------- home-manager/home-manager.nix | 7 ++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index b0a42154..f94c1c3e 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -194,14 +194,11 @@ function doShowNews() { return 1 esac - local newsReadIdsFile - newsReadIdsFile="$(newsReadIdsFile)" - - local tempNewReadIdsFile - tempNewReadIdsFile="$(mktemp -t hm-news-read-ids.XXXXXXXXXX)" - - sort -u "$newsReadIdsFile" "$newsUnreadIdsFile" > "$tempNewReadIdsFile" - mv -f "$tempNewReadIdsFile" "$newsReadIdsFile" + if [[ -s "$newsUnreadIdsFile" ]]; then + local newsReadIdsFile + newsReadIdsFile="$(newsReadIdsFile)" + cat "$newsUnreadIdsFile" >> "$newsReadIdsFile" + fi } function doHelp() { diff --git a/home-manager/home-manager.nix b/home-manager/home-manager.nix index b81c58e5..390ecbf9 100644 --- a/home-manager/home-manager.nix +++ b/home-manager/home-manager.nix @@ -61,8 +61,13 @@ let ) env.newsEntries ); + # File where each line corresponds to an unread news entry + # identifier. If non-empty then the file ends in "\n". newsUnreadIdsFile = pkgs.writeText "news-unread-ids" ( - concatMapStringsSep "\n" (entry: entry.id) newsFiltered + let + text = concatMapStringsSep "\n" (entry: entry.id) newsFiltered; + in + text + optionalString (text != "") "\n" ); newsInfo = pkgs.writeText "news-info.sh" ''