about summary refs log tree commit diff stats
path: root/bin/rsschk
diff options
context:
space:
mode:
Diffstat (limited to 'bin/rsschk')
-rwxr-xr-xbin/rsschk21
1 files changed, 10 insertions, 11 deletions
diff --git a/bin/rsschk b/bin/rsschk
index 5a8de6e..ab74169 100755
--- a/bin/rsschk
+++ b/bin/rsschk
@@ -1,16 +1,15 @@
 #!/bin/sh
-# checks if $1 is a valid URL, and if so, checks to see if it's in newsboat's urls file, and if not, adds it to the file.
+# checks if $1 is a valid URL
+# if so, checks to see if it's in newsboat's urls file
+# if not, adds it to the file.
 if [ "$1" = "-h" ]; then
 	printf 'usage: rsschk [-h]|URL [\"category\"]\n'>/dev/stderr&&return 1
 fi
-XDG_CONFIG_HOME=${XDG_CONFIG_HOME:=~/.config}
-! echo "$1" | grep "http*://\S\+\.[A-Za-z]\+\S*" >/dev/null &&
+# regex for finding urls
+re_urls='https?://[[:alnum:].]*:?[[:alnum:]./@$&%?$#=_-]*\.(rss|xml)'
+
+! echo "$1" | grep -Eq "$re_urls" &&
 	notify-send "Invalid input. rsschk takes http(s) URLs as input." && exit
-RSSFILE="$XDG_CONFIG_HOME/newsboat/urls"
-if grep -E "^$1" "$RSSFILE"; then
-	if [ -z "$2" ]; then
-		echo "$1">>"$RSSFILE"&&notify-send "RSS feed added." "You may want to edit $RSSFILE now."
-	else
-		echo "$1 $2">>"$RSSFILE"&&notify-send "RSS feed added with one category."
-	fi
-fi
+RSSFILE="${XDG_CONFIG_HOME:=~/.config}/newsboat/urls"
+grep -q "^$1" "$RSSFILE" &&
+	{ echo "$1">>"$RSSFILE"&&notify-send "RSS feed added.";}