Zum Inhalt

The Newsboat RSS Feedreader - RSS-Reader für die CLI

The Newsboat RSS Feedreader ist ein praktischer RSS-Feed-Reader für die Kommandozeile, der es Nutzern ermöglicht, Nachrichtenquellen schnell und effizient zu abonnieren und zu durchsuchen. Er unterstützt eine Vielzahl von Funktionen wie das Markieren von Artikeln, das Anpassen von Tastenkürzeln und das Verwenden von externen Programmen, z.B. Nextcloud News, zur Anzeige von Inhalten. Mit seiner einfachen, aber leistungsstarken Benutzeroberfläche richtet sich Newsboat besonders an Nutzer, die gerne ohne grafische Benutzeroberflächen arbeiten und eine textbasierte Alternative suchen.

Auf weitere Beschreibungen und Aufzählung der Tastenkürzel von Newsboat wird in diesem Beitrag verzichtet. Mit ? lässt sich die Hilfe aufrufen und die Tastenkürzel werden aufgelistet.

Newsboat - Konfigurationsdateien

url-Datei

Die RSS Feeds werden der Reihe nach in einer normalen Text-Datei mit dem Namen url eingetragten. Die url-Datei ist im Verzeichnis ~/.newsboat-nextcloud/newsboat/urls abzuspeichern.

Beispiel:

---UNREAD_📖---
"query:Unread Articles:unread = \"yes\""
---Blog_😎---
https://strobelstefan.de/feed_rss_created.xml "Privat 😎" "~Blog 😎"
https://mastodon.social/@strobelstefan.rss "Privat 😎" "Mastodon 🐘" "~Mastodon 🐘"
---Netzpolitik---
https://www.ccc.de/de/rss/updates.xml "Netzpolitik"
http://netzpolitik.org/feed/ "Netzpolitik"
https://noyb.eu/de/rss "Netzpolitik"
https://digitalcourage.de/rss.xml "Netzpolitik"
---Mastodon_Personen_🐘👤---
https://mamot.fr/@roofjoke.rss "Mastodon 🐘👤"
https://mastodon.social/@ckoever.rss "Mastodon 🐘👤"
---Linux_🐧---
http://planet.ubuntuusers.de/feeds/full/25/ "Linux 🐧"
https://planet.debianforum.de/rss10.xml "Linux 🐧"
---Release_Notes---
https://github.com/advplyr/audiobookshelf/releases.atom "Release Notes"
https://github.com/jellyfin/jellyfin/releases.atom "Release Notes"
https://github.com/louislam/uptime-kuma/releases.atom "Release Notes"
https://forgejo.org/rss.xml "Release Notes"
https://blog.gitea.com/rss.xml "Release Notes" "~Gitea Release Notes"
https://www.openmediavault.org/?feed=rss2 "Release Notes" "~openmediavault Release Notes"
https://github.com/openwrt/openwrt/releases.atom "Release Notes" "~Openwrt Release Notes"
https://pi-hole.net/feed/ "Release Notes" "~Pi-hole Release Notes"
https://github.com/photoprism/photoprism/releases.atom "Release Notes"

config-Datei

Die Konfigurationsdatei nennt sich config und liegt ebenfalls in ~/.newsboat-nextcloud/newsboat/urls.

Tip

Zum Testen wird empfohlen die Funktion auto-reload yes mit # zu deaktivieren.

auto-reload yes
reload-time 60
reload-threads 0
history-limit 100
always-display-description true
notify-screen yes
save-path "$HOME/downloads/"

### HEADLINES ###
highlight feedlist "---.*---" green default bold
highlight feedlist ".*0/0.." default default invis

### MACROS ###
macro k open; reload; quit  -- "enter feed to reload it"
macro o open-in-browser; toggle-article-read "read"

### BROWSER ###
#browser "open -g -a 'Firefox' %u"
browser "open -g -a 'Mullvad\ Browser' %u"

### Bookmarks ###
bookmark-cmd "$HOME/.newsboat/bookmark.sh"

# inspired inkpod
# https://github.com/newsboat/newsboat/blob/master/contrib/colorschemes/inkpot
color background         default default
color listnormal         default default
color listnormal_unread  color15 default bold
color listfocus          green   default reverse
color listfocus_unread   color10 default reverse bold
color title              color46    default reverse bold
color info                color247   color235
#color hint-description   magenta default
color article            default default
color end-of-text-marker color8  default

# Highlight URLs with regex
highlight article "^(Feed|Link):.*$" color46 default
highlight article "^(Title|Date|Author):.*$" color39 default bold
highlight article "https?://[^ ]+" color46 default underline
highlight article "\\[[0-9]+\\]" color63 default bold
highlight article "\\[image\\ [0-9]+\\]" color63 default bold
highlight feedlist "^─.*$" color61 color235 bold

Bookmarks - 🔖 Lesezeichen

Newsboat kann Artikel in eine eigene Datei schreiben und damit 🔖 bookmarken.

In der Config-Datei ist die Zeile bookmark-cmd "$HOME/.newsboat/bookmark.sh" für die Konfiguration von Lesezeichen zuständig.

Beim Drücken der Tasten Strg + b wird das Shell Script aufgerufen und der Artikel in die Datei $HOME/downloads/bookmarks.md und $HOME/downloads/bookmarks.txt geschrieben.

Die Informationen url, titel, description, feed_title erhält das Skript direkt von Newsboat.

Das Datum date_time wird vom eigenen Client bereitgestellt und ermöglicht eine Sortierung der gespeicherten Artikel absteigend nach Datum.

#!/usr/bin/env bash

url="$1"
title="$2"
description="$3"
feed_title="$4"
date_time=$(date "+%Y-%m-%d")  # Get only the current date

# Bookmark files
bookmarks_file_md="$HOME/downloads/newsboat-bookmarks/bookmarks.md"
bookmarks_file_txt="$HOME/downloads/newsboat-bookmarks/bookmarks.txt"

# Check if the last entry in the file already has today's date
last_date=$(tail -n 1 $HOME/downloads/newsboat-bookmarks/bookmarks.md | cut -d' ' -f2)

# If the last date in the file is different from today's date, add today's date as a header
if [[ "$last_date" != "$date_time" ]]; then
  echo "Date: ${date_time}" >> $bookmarks_file_md
fi

# Add the feed details
echo "- ${feed_title}; [${title}](${url}) ${date_time} - 📝 ${description}" >> $bookmarks_file_md

# If the last date in the file is different from today's date, add today's date as a header
if [[ "$last_date" != "$date_time" ]]; then
  echo "Date: ${date_time}" >> $bookmarks_file_txt
fi

# Add the feed details
echo "- ***${url}*** ${feed_title} ###${title}### - 📝 ${description} - ${date_time}" >> $bookmarks_file_txt

#url title description feed_title

exit 0

Download aller Bookmarks als PDF-Datei

Die bookmarks.txt wurde angelegt, um alle Artikel als einzelne PDF-Datein herunterladen zu können.

#!/bin/bash

# Path to the bookmarks file
bookmarks_file="$HOME/downloads/newsboat-bookmarks/bookmarks.txt"
path="$HOME/downloads/newsboat-bookmarks/"
date_time=$(date "+%Y-%m-%d")

# Ensure the path ends with a slash
if [[ ! "$path" =~ /$ ]]; then
  path="$path/"
fi

# Check if bookmarks file exists
if [[ ! -f "$bookmarks_file" ]]; then
  echo "Bookmarks file not found!"
  exit 1
fi

# Iterate over each line in bookmarks.txt
while IFS= read -r line || [[ -n "$line" ]]; do
  # Trim leading/trailing whitespace
  line=$(echo "$line" | xargs)

  # Debugging: print the line being processed
  echo "Processing line: '$line'"

  # Extract the URL between the *** markers and title between ### markers
  if [[ "$line" =~ \*\*\*(https?://[^\*]+)\*\*\*.*\#\#\#([^\#]+)\#\#\# ]]; then
    url="${BASH_REMATCH[1]}"  # Extract the URL from between *** markers
    title="${BASH_REMATCH[2]}"  # Extract the title from between ### markers

    # Debugging: print the extracted URL and title
    echo "Extracted URL: '$url'"
    echo "Extracted Title: '$title'"

    # Remove leading/trailing spaces from the URL and title
    url=$(echo "$url" | xargs)
    title=$(echo "$title" | xargs)

    # Ensure the URL is valid and starts with http:// or https://
    if [[ ! "$url" =~ ^https?:// ]]; then
      echo "Invalid URL: $url"
      continue  # Skip to next URL if it's not valid
    fi

    # Download the article content (HTML) using curl
    echo "Downloading article from: $url"

    # Use curl with a user-agent to avoid being blocked
    curl -s -L -o article.html -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" "$url"

    # Check if the download was successful
    if [[ ! -f article.html ]]; then
      echo "Failed to download the article: $url"
      continue  # Skip to next URL if the download failed
    fi

    # Debugging: Verify the contents of the downloaded file
    echo "Article downloaded successfully. Checking the content..."
    head -n 20 article.html  # Display the first 20 lines of the HTML file

    # Generate a valid filename for the PDF (replace spaces with underscores, for example)
    sanitized_title=$(echo "$title" | tr '[:space:]' '_')

    # Ensure the PDF filename is unique (add a suffix if needed)
    pdf_name="${date_time}_${sanitized_title}.pdf"  # Add the .pdf extension
    counter=1
    while [[ -f "${path}${pdf_name}" ]]; do
      pdf_name="${sanitized_title}_${counter}.pdf"
      counter=$((counter + 1))
    done

    # Convert HTML to PDF using Pandoc with the specified CSS and pdflatex engine
    pandoc article.html -o "${path}${pdf_name}" --css="$css_file" --pdf-engine=pdflatex



    # Check if the PDF was generated
    if [[ -f "${path}${pdf_name}" ]]; then
      echo "PDF saved as ${path}${pdf_name}"
    else
      echo "Failed to convert the LaTeX to PDF."
    fi

    # Clean up temporary files
    rm article.html

  else
    echo "No valid URL or title found in line: '$line'"
  fi

done < "$bookmarks_file"

Für das einfach Ausführen des Shell Scripts kann man sich einen Alias in der .zshrc anlegen, wie z.B. nnb.

nano .zshrc

Einfach in der Datei .zshrc die Zeile eintragen und das Terminal neu starten.

alias nnb='sh $HOME/.newsboat/export.sh'

Gibt man nun im Terminal nnb gefolgt von Enter ↵ ein, wird das Shell Script ausgeführt und für alle URLs eine eigene PDF-Datei erstellt.


Mehrere Instanzen von Newsboat

Nextcloud News in Newsboat

Neben der normalen Newsboat Instanz, die die Feeds aus der url-Datei aufruft, können z.B. auch die Feeds von Nextcloud News in einer zweiten Newsboat Instanz abgerufen werden.

Dafür wird ein neuer Ordner mit dem Namen .newsboat-nextcloud angelegt. Dort wird die gleiche Ordner- und Datei Struktur wie bei der Hauptinstanz erstellt.

mkdir ~/.newsboat-nextcloud
mkdir ~/.newsboat-nextcloud/newsboat

Newsboat benötigt die Anmeldedaten für die Nextcloud, um Zugriff auf die Feeds zu erhalten.

In Nextcloud erstellt man dazu einfach ein anwendungsspezifisches Passwort.1

Es gibt zwei Optionen, wie das Passwort in Newsboat gespeichert werden kann:

  1. als Klartext in der config-Datei
  2. in einer GPG-verschlüsselten Datei

Zu empfehlen ist die zweite Option. Wer einen Yubikey oder Nitrokey besitzt, kann den Token damit auch zum Entsperren der Passwortdatei verwenden und die Feeds in Newsboat lesen.

Passwortdatei erstellen

Die Passwortdatei kann mit dem Befehl auf der CLI erstellt werden.

$ gpg --encrypt --default-recipient-self --output ~/.newsboat/nextcloud-password.gpg

config

Es kann die gleiche config-Datei der Hauptinstanz verwendet werden und im Verzeichnis ~/.newsboat-nextcloud/newsboat/config abgelegt werden. Für die Nextcloud ist am Ende einzufügen:

...

### NEXTCLOUD ###
urls-source "ocnews"
ocnews-url "https://next.example.de/"
ocnews-login "user"
ocnews-passwordeval "gpg --decrypt ~/.newsboat/nextcloud-password.gpg"
  • ocnews-url = URL der eigenen Nextcloud
  • ocnews-login = Benutzername
  • ocnews-passwordeval = Der Speicherort der Passwortdatei ist ggf. anzupassen

url

Die url-Datei wird im Verzeichnis /.newsboat-nextcloud/newsboat/urls angelegt. Es sind die zwei Zeilen ausreichend.

---UNREAD_📖---
"query:Unread Articles:unread = \"yes\""

Alias in .zshrc anlegen

Mit einem Alias-Eintrag in der zsh.rc oder der bash.rc kann eine zweite Instanz von Newsboat mit einem Kürzel schnell aufgerufen werden. Die Eingabe des langen Befehls ist nicht mehr notwendig.

nano ~/.zsh.rc

In der Datei ist die Zeile einzufügen und das Terminalfenster neu zu starten.

...
#Newsboat 
alias nnc='XDG_CONFIG_HOME=~/.newsboat-nextcloud XDG_DATA_HOME=.newsboat-nextcloud newsboat'
...

Newsboat kann ab sofort über die Eingabe von nnc + Enter ↵ gestartet werden.

Tip

Für die Hauptinstanz von Newsboat kann ebenfalls ein Alias in ~/.zsh.rc oder bash.rc angelegt werden, z.B. nn + Enter ↵

alias nn='newsboat'

iTerm2 Fenster für newsboat

Newsboat kann auch in einem eigenen iTerm2-Fenster gestartet werden. Dort kann z.B. Font, Schriftgröße, Schriftfarbe, etc. angepasst werden.

Es wird ein Skript iterm-newsboat.sh in einem beliebigen Verzeichnis, z.B. .config/scripts/, angelegt.

#!/usr/bin/env bash

PROFILE="${1-newsboat}"

# Öffne iTerm2 mit dem angegebenen Profil und speichere die Fenster-ID
WINDOW_ID=$(osascript -e "tell application \"iTerm\"
    set newWindow to (create window with profile \"$PROFILE\")
    id of newWindow
end tell")

# Wartet 10 Sekunden, bis Newsboat geladen wurde
# Bei Probleme ist der Wert zu erhöhen
sleep 10

# Warte, bis der Newsboat-Prozess endet
while pgrep -x "newsboat" > /dev/null; do
    sleep 2
done

# Schließe nur das Fenster mit der gespeicherten Fenster-ID, wenn Newsboat beendet ist
osascript -e "tell application \"iTerm\"
    close (every window whose id is $WINDOW_ID)
end tell"

Das Skript wird ausführbar gemacht:

chmod +x iterm-newsboat.sh

Das iTerm2-Profil newsboat wird angelegt.

iTerm2 Profile für Newsboat erstellen

Image caption: iTerm2 Profile für Newsboat erstellen

Der Eintrag in Send text at start funktioniert nur, wenn zuvor der Alias in zshrc definiert wurde.

Möchte man das Script direkt starten, ist der komplette Pfad in das Feld Directory einzutragen.

Mit einem eigenen Alias lässt sich das iTerm2-Fenster mit Newsboat dann bequem mit nnn + Enter ↵ starten.

#Alias in .zshrc
alias nnn='sh ./.config/scripts/iterm-newsboat.sh "newsboat"'

# Alias für Nextcloud News
alias nnm='sh ./.config/scripts/iterm-newsboat.sh "newsboat-nextcloud"'

Weitere Informationen:



Gib mir gerne einen Kaffee ☕ aus 😀

Gib mir gerne einen Kaffee ☕ aus !

Wenn dir meine Beiträge gefallen und geholfen haben, dann kannst du mir gerne einen Kaffee ☕️ ausgeben.

Donation via PayPalDonation via LiberaPay

Donation via Bitcoin
Bitcoin Address: bc1qfuz93hw2fhdvfuxf6mlxlk8zdadvnktppkzqzj

Source
  • Teile des Artikels wurden mit maschineller Hilfe erstellt.
  • Photo by Artak Petrosyan on Unsplash