You are not logged in.
Hello everyone.
I wrote these two functions for my .bashrc:
#!/bin/bash
if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi
if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi
feed() {
if [ ! -d $FEED_BOOKMARKS ]; then mkdir $FEED_BOOKMARKS; fi
if [ ! -n "$1" ]; then
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ feed \\e[01;31m<url>\\e[00m \\e[01;31m<new bookmark?>\\e[00m\\n\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m\\n"
return 1;
fi
local rss_source="$(curl --silent $1 | sed -e ':a;N;$!ba;s/\n/ /g')";
if [ ! -n "$rss_source" ]; then
echo "The feed is empty";
return 1;
fi
# THE RSS PARSER
# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
echo -e "$(echo $rss_source | \
sed -e 's/>/>/g' \
-e 's/</</g' \
-e 's/<\/a>/£/g' \
-e 's/href\=\"/§/g' \
-e 's/<title>/\\n\\n\\n :: \\e[01;31m/g' -e 's/<\/title>/\\e[00m ::\\n/g' \
-e 's/<link>/ [ \\e[01;36m/g' -e 's/<\/link>/\\e[00m ]/g' \
-e 's/<description>/\\n\\n\\e[00;37m/g' -e 's/<\/description>/\\e[00m\\n\\n/g' \
-e 's/<p>\|<br\s*\/\?>/\n/g' \
-e 's/<b>\|<strong>/\\e[01;30m/g' -e 's/<\/b>\|<\/strong>/\\e[00;37m/g' \
-e 's/<u>/\\e[4;37m/g' -e 's/<\/u>/\\e[00;37m/g' \
-e 's/<b>\|<code>/\\e[00m/g' -e 's/<\/b>\|<\/code>/\\e[00;37m/g' \
-e 's/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g' \
-e 's/<li>/\n \\e[01;34m*\\e[00;37m /g' \
-e 's/<!\[CDATA\[\|\]\]>\|>\s*<//g' \
-e 's/<[^>]*>/ /g' \
-e 's/[<>£§]//g')\n\n";
# END OF THE RSS PARSER
if [ -n "$2" ]; then
echo "$1" > $FEED_BOOKMARKS/$2
echo -e "\\n\\t\\e[01;37m==> \\e[01;31mBookmark saved as \\e[01;36m\\e[04m$2\\e[00m\\e[01;37m <==\\e[00m\\n"
fi
}
deef() {
if test -n "$1"; then
if [ ! -r "$FEED_BOOKMARKS/$1" ]; then
echo -e "\\n \\e[01;31mBookmark \\e[01;36m\\e[04m$1\\e[00m\\e[01;31m not found.\\e[00m\\n\\n \\e[04mType:\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m (without arguments)\\n\\n to get the complete list of all currently saved bookmarks.\\n";
return 1;
fi
local url="$(cat $FEED_BOOKMARKS/$1)";
if [ ! -n "$url" ]; then
echo "The bookmark is empty";
return 1;
fi
echo -e "\\n\\t\\e[01;37m==> \\e[01;31m$url\\e[01;37m <==\\e[00m"
feed "$url";
else
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ deef \\e[01;31m<bookmark>\\e[00m\\n\\n \\e[04mCurrently saved bookmarks\\e[00m\\n";
for i in $(find $FEED_BOOKMARKS -maxdepth 1 -type f);
do echo -e " \\e[01;36m\\e[04m$(basename $i)\\e[00m";
done;
echo -e "\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ feed\\e[00m\\n";
fi;
}
It's a very simple rss reader written in bash with two functions.
The first one:
$ feed <url> <new bookmark?>
prints the parsed content of <url> and possibly save the url as <new bookmark?>, if specified.
For example:
$ feed http://www.archlinux.org/feeds/news/
or
$ feed http://www.archlinux.org/feeds/news/ archnews
The second one:
$ deef <bookmark>
reads the url previously saved as <bookmark> and prints its content.
For example:
$deef archnews
I'd like you to test it and suggest whatever you want
The parser is very very simple.
**EDIT**
A better version of this script is this.
Last edited by grufo (2012-08-15 02:41:19)
Offline
Cool idea!
But holy sed pipes batman ... I think this would be a perfect place to get a little practice with awk. One awk invocation could replace all those seds and remove the need for the double nested echos. If you aren't familiar with awk, then at least you could use sed's "-e" parameter to use one invocation of sed rather than piping through a dozen independent processes (each one requiring the loading and unloading of sed).
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Post your code suggestions! :-)
I'm also not fully persuaded about the colors I choose...
Last edited by grufo (2012-08-11 01:26:16)
Offline
It would take a bit to translate it into awk, but the sed "-e" option would look like the following excerpt:
echo -e "$(echo $rss_source | sed -e \
's/>/>/g' -e \
's/</</g' -e \
's/<\/a>/£/g' -e\
's/href\=\"/§/g' -e\
...
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thnx. I've updated it
Last edited by grufo (2012-08-11 01:50:00)
Offline
I have no ideas on how to render the italic style. Suggestions?
Offline
You don't need -e, you can just enclose all the expressions in one script:
echo -e "$(echo $rss_source | sed 's/>/>/g
s/</</g
s/<\/a>/£/g
s/href\=\"/§/g
...
'
sed applies every line that matches the address pattern. No address pattern and it tries to apply the substitution to every line.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
It doesn't work in this way...
Offline
I added a red background for italic style and also enforced the parsing process with more possibilities...
#!/bin/bash
if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi
if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi
feed() {
if [ ! -d $FEED_BOOKMARKS ]; then mkdir $FEED_BOOKMARKS; fi
if [ ! -n "$1" ]; then
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ feed \\e[01;31m<url>\\e[00m \\e[01;31m<new bookmark?>\\e[00m\\n\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m\\n"
return 1;
fi
local rss_source="$(curl --silent $1 | sed -e ':a;N;$!ba;s/\n/ /g')";
if [ ! -n "$rss_source" ]; then
echo "The feed is empty";
return 1;
fi
# THE RSS PARSER
# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
echo -e "$(echo $rss_source | \
sed -e 's/&/\&/g' \
-e 's/<\|</</g' \
-e 's/>\|>/>/g' \
-e 's/<\/a>/£/g' \
-e 's/href\=\"/§/g' \
-e 's/<title>/\\n\\n\\n :: \\e[01;31m/g' -e 's/<\/title>/\\e[00m ::\\n/g' \
-e 's/<link>/ [ \\e[01;36m/g' -e 's/<\/link>/\\e[00m ]/g' \
-e 's/<description>/\\n\\n\\e[00;37m/g' -e 's/<\/description>/\\e[00m\\n\\n/g' \
-e 's/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g' \
-e 's/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g' -e 's/<\/b>\|<\/strong>/\\e[00;37m/g' \
-e 's/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g' -e 's/<\/i>\|<\/em>/\\e[00;37m/g' \
-e 's/<u\( [^>]*\)\?>/\\e[4;37m/g' -e 's/<\/u>/\\e[00;37m/g' \
-e 's/<code\( [^>]*\)\?>/\\e[00m/g' -e 's/<\/code>/\\e[00;37m/g' \
-e 's/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g' \
-e 's/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g' \
-e 's/<!\[CDATA\[\|\]\]>//g' \
-e 's/\|>\s*<//g' \
-e 's/ *<[^>]\+> */ /g' \
-e 's/[<>£§]//g')\n\n";
# END OF THE RSS PARSER
if [ -n "$2" ]; then
echo "$1" > $FEED_BOOKMARKS/$2
echo -e "\\n\\t\\e[01;37m==> \\e[01;31mBookmark saved as \\e[01;36m\\e[04m$2\\e[00m\\e[01;37m <==\\e[00m\\n"
fi
}
deef() {
if test -n "$1"; then
if [ ! -r "$FEED_BOOKMARKS/$1" ]; then
echo -e "\\n \\e[01;31mBookmark \\e[01;36m\\e[04m$1\\e[00m\\e[01;31m not found.\\e[00m\\n\\n \\e[04mType:\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m (without arguments)\\n\\n to get the complete list of all currently saved bookmarks.\\n";
return 1;
fi
local url="$(cat $FEED_BOOKMARKS/$1)";
if [ ! -n "$url" ]; then
echo "The bookmark is empty";
return 1;
fi
echo -e "\\n\\t\\e[01;37m==> \\e[01;31m$url\\e[01;37m <==\\e[00m"
feed "$url";
else
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ deef \\e[01;31m<bookmark>\\e[00m\\n\\n \\e[04mCurrently saved bookmarks\\e[00m\\n";
for i in $(find $FEED_BOOKMARKS -maxdepth 1 -type f);
do echo -e " \\e[01;36m\\e[04m$(basename $i)\\e[00m";
done;
echo -e "\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ feed\\e[00m\\n";
fi;
}
Last edited by grufo (2012-08-11 17:06:33)
Offline
It doesn't work in this way...
That'll teach me to answer programming stuff on my phone. I'll try again when on my laptop. Sorry.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Right, this worked for me:
echo -e "$(echo $rss_source | \
sed 's/&/\&/g
s/<\|</</g
s/>\|>/>/g
s/<\/a>/£/g
s/href\=\"/§/g
s/<title>/\\n\\n\\n :: \\e[01;31m/g
s/<\/title>/\\e[00m ::\\n/g
s/<link>/ [ \\e[01;36m/g
s/<\/link>/\\e[00m ]/g
s/<description>/\\n\\n\\e[00;37m/g
s/<\/description>/\\e[00m\\n\\n/g
s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g
s/<\/b>\|<\/strong>/\\e[00;37m/g
s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g
s/<\/i>\|<\/em>/\\e[00;37m/g
s/<u\( [^>]*\)\?>/\\e[4;37m/g
s/<\/u>/\\e[00;37m/g
s/<code\( [^>]*\)\?>/\\e[00m/g
s/<\/code>/\\e[00;37m/g
s/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g
s/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g
s/<!\[CDATA\[\|\]\]>//g
s/\|>\s*<//g
s/ *<[^>]\+> */ /g
s/[<>£§]//g')\n\n";
Note, I may have made a mistake so the formatting may not be perfect, but the output was generally good.
If you want to put two items on the same line, they should be able to just be separated by a ;
Last edited by skanky (2012-08-11 17:45:46)
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Right, this worked for me:
Great!
This is the script with your suggestions:
#!/bin/bash
if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi
if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi
feed() {
if [ ! -d $FEED_BOOKMARKS ]; then mkdir $FEED_BOOKMARKS; fi
if [ ! -n "$1" ]; then
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ feed \\e[01;31m<url>\\e[00m \\e[01;31m<new bookmark?>\\e[00m\\n\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m\\n"
return 1;
fi
local rss_source="$(curl --silent $1 | sed -e ':a;N;$!ba;s/\n/ /g')";
if [ ! -n "$rss_source" ]; then
echo "The feed is empty";
return 1;
fi
# THE RSS PARSER
# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
echo -e "$(echo $rss_source | \
sed -e 's/&/\&/g
s/<\|</</g
s/>\|>/>/g
s/<\/a>/£/g
s/href\=\"/§/g
s/<title>/\\n\\n\\n :: \\e[01;31m/g; s/<\/title>/\\e[00m ::\\n/g
s/<link>/ [ \\e[01;36m/g; s/<\/link>/\\e[00m ]/g
s/<description>/\\n\\n\\e[00;37m/g; s/<\/description>/\\e[00m\\n\\n/g
s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g; s/<\/b>\|<\/strong>/\\e[00;37m/g
s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g; s/<\/i>\|<\/em>/\\e[00;37m/g
s/<u\( [^>]*\)\?>/\\e[4;37m/g; s/<\/u>/\\e[00;37m/g
s/<code\( [^>]*\)\?>/\\e[00m/g; s/<\/code>/\\e[00;37m/g
s/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g
s/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g
s/<!\[CDATA\[\|\]\]>//g
s/\|>\s*<//g
s/ *<[^>]\+> */ /g
s/[<>£§]//g')\n\n";
# END OF THE RSS PARSER
if [ -n "$2" ]; then
echo "$1" > $FEED_BOOKMARKS/$2
echo -e "\\n\\t\\e[01;37m==> \\e[01;31mBookmark saved as \\e[01;36m\\e[04m$2\\e[00m\\e[01;37m <==\\e[00m\\n"
fi
}
deef() {
if test -n "$1"; then
if [ ! -r "$FEED_BOOKMARKS/$1" ]; then
echo -e "\\n \\e[01;31mBookmark \\e[01;36m\\e[04m$1\\e[00m\\e[01;31m not found.\\e[00m\\n\\n \\e[04mType:\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m (without arguments)\\n\\n to get the complete list of all currently saved bookmarks.\\n";
return 1;
fi
local url="$(cat $FEED_BOOKMARKS/$1)";
if [ ! -n "$url" ]; then
echo "The bookmark is empty";
return 1;
fi
echo -e "\\n\\t\\e[01;37m==> \\e[01;31m$url\\e[01;37m <==\\e[00m"
feed "$url";
else
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ deef \\e[01;31m<bookmark>\\e[00m\\n\\n \\e[04mCurrently saved bookmarks\\e[00m\\n";
for i in $(find $FEED_BOOKMARKS -maxdepth 1 -type f);
do echo -e " \\e[01;36m\\e[04m$(basename $i)\\e[00m";
done;
echo -e "\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ feed\\e[00m\\n";
fi;
}
Last edited by grufo (2012-08-11 20:08:15)
Offline
Very nice script mate!
I'm going to use it.
I've a suggestion. You could assign the color values to variables and use them throughout the script. That'd enhance the readability of the script, also it would be easier to modify later or users can assign their own colors of choice to the variables.
Last edited by debdj (2012-08-12 07:44:50)
Offline
This is great, thanks! I certainly like using newsbeuter, but the simplicity of this is amazing.
Offline
Very nice script mate!
I'm going to use it.I've a suggestion. You could assign the color values to variables and use them throughout the script. That'd enhance the readability of the script, also it would be easier to modify later or users can assign their own colors of choice to the variables.
You are right. But unfortunately this was only an "experiment" and I have no idea on how to put the result of a variable inside a sed script. Anyone can help me?
This is great, thanks! I certainly like using newsbeuter, but the simplicity of this is amazing.
^__^
Offline
You are right. But unfortunately this was only an "experiment" and I have no idea on how to put the result of a variable inside a sed script. Anyone can help me?
Break the '' :-
sed 's/abc/'$VARIABLE'/'
You can split the sed script to a separate file, which would mean that you could have different types of file or streams that could be converted...should you wish.
"...one cannot be angry when one looks at a penguin." - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle
Offline
Here.
I just replaced the color codes with variables in the parser. Others are intact. Working for me.
#!/bin/bash -x
#black=`tput setaf 0`
red=`tput setaf 1`
#green=`tput setaf 2`
#yellow=`tput setaf 3`
blue=`tput setaf 4`
#magenta=`tput setaf 5`
cyan=`tput setaf 6`
white=`tput setaf 7`
norm=`tput sgr0`
bold=`tput bold`
ulbegin=`tput smul`
ulend=`tput rmul`
title="$bold$red"
text="$white"
link="$bold$cyan"
brace="$bold$blue" #also for lists
embedul="$ulbegin$white"
#alert="$bold$white"
#strong="$bold$black"
if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi
if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi
feed() {
if [ ! -d $FEED_BOOKMARKS ]; then mkdir $FEED_BOOKMARKS; fi
if [ ! -n "$1" ]; then
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ feed $title<url>\\e[00m $title<new bookmark?>\\e[00m\\n\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m\\n"
return 1;
fi
local rss_source="$(curl --silent $1 | sed -e ':a;N;$!ba;s/\n/ /g')";
if [ ! -n "$rss_source" ]; then
echo "The feed is empty";
return 1;
fi
# THE RSS PARSER
# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
echo -e "$(echo $rss_source | \
sed -e "s/>/>/g" \
-e "s/</</g" \
-e "s/<\/a>/£/g" \
-e "s/href\=\"/§/g" \
-e "s/<title>/\\n\\n\\n :: $title/g" -e "s/<\/title>/$norm ::\\n/g" \
-e "s/<link>/ [ $link/g" -e "s/<\/link>/$norm ]/g" \
-e "s/<description>/\\n\\n$text/g" -e "s/<\/description>/$norm\\n\\n/g" \
-e "s/<p>\|<br\s*\/\?>/\n/g" \
-e "s/<b>\|<strong>/\\e[01;30m/g" -e "s/<\/b>\|<\/strong>/$text/g" \
-e "s/<u>/$embedul/g" -e "s/<\/u>/$norm$text/g" \
-e "s/<b>\|<code>/$norm/g" -e "s/<\/b>\|<\/code>/$text/g" \
-e "s/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/$title\2$text $brace[$norm$text $ulbegin\1$ulend$brace ]$norm$text/g" \
-e "s/<li>/\n $brace*$norm$text /g" \
-e "s/<!\[CDATA\[\|\]\]>\|>\s*<//g" \
-e "s/<[^>]*>/ /g" \
-e "s/[<>£§]//g")\n\n";
# END OF THE RSS PARSER
if [ -n "$2" ]; then
echo "$1" > $FEED_BOOKMARKS/$2
echo -e "\\n\\t\\e[01;37m==> $titleBookmark saved as \\e[01;36m\\e[04m$2\\e[00m\\e[01;37m <==\\e[00m\\n"
fi
}
deef() {
if test -n "$1"; then
if [ ! -r "$FEED_BOOKMARKS/$1" ]; then
echo -e "\\n $titleBookmark \\e[01;36m\\e[04m$1\\e[00m$title not found.\\e[00m\\n\\n \\e[04mType:\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m (without arguments)\\n\\n to get the complete list of all currently saved bookmarks.\\n";
return 1;
fi
local url="$(cat $FEED_BOOKMARKS/$1)";
if [ ! -n "$url" ]; then
echo "The bookmark is empty";
return 1;
fi
echo -e "\\n\\t\\e[01;37m==> $title$url\\e[01;37m <==\\e[00m"
feed "$url";
else
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ deef $title<bookmark>\\e[00m\\n\\n \\e[04mCurrently saved bookmarks\\e[00m\\n";
for i in $(find $FEED_BOOKMARKS -maxdepth 1 -type f);
do echo -e " \\e[01;36m\\e[04m$(basename $i)\\e[00m";
done;
echo -e "\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ feed\\e[00m\\n";
fi;
}
EDIT: I started modifying the first script (I saved) and didn't notice the later ones.
Last edited by debdj (2012-08-13 09:44:53)
Offline
Break the '' :-
sed 's/abc/'$VARIABLE'/'
You can split the sed script to a separate file, which would mean that you could have different types of file or streams that could be converted...should you wish.
Thank you
So, if you prefer a version with formatting variables...
#!/bin/bash
if [ ! -n "$FEED_BOOKMARKS" ]; then export FEED_BOOKMARKS=$HOME/.feed_bookmarks; fi
if [ ! -d "$FEED_BOOKMARKS" ]; then mkdir -p $FEED_BOOKMARKS; fi
feed() {
if [ ! -d $FEED_BOOKMARKS ]; then mkdir $FEED_BOOKMARKS; fi
if [ ! -n "$1" ]; then
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ feed \\e[01;31m<url>\\e[00m \\e[01;31m<new bookmark?>\\e[00m\\n\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m\\n"
return 1;
fi
local rss_source="$(curl --silent $1 | sed -e ':a;N;$!ba;s/\n/ /g')";
if [ ! -n "$rss_source" ]; then
echo "The feed is empty";
return 1;
fi
# THE RSS PARSER
# Formatting
local f_title="\\\\e[01;31m"
local f_descr="\\\\e[00;37m"
local f_ref="\\\\e[01;36m"
local f_bold="\\\\e[01;36m"
local f_italic="\\\\e[41;37m"
local f_underline="\\\\e[4;37m"
local f_code="\\\\e[00m"
local f_linklabel="\\\\e[01;31m"
local f_linkurl="\\\\e[04m"
local f_formatchrs="\\\\e[01;34m"
# The characters "£, §" are used as metacharacters. They should not be encountered in a feed...
echo -e "$(echo $rss_source | \
sed -e 's/&/\&/g
s/<\|</</g
s/>\|>/>/g
s/<\/a>/£/g
s/href\=\"/§/g
s/<title>/\\n\\n\\n :: '$f_title'/g; s/<\/title>/\\e[00m ::\\n/g
s/<link>/ [ '$f_ref'/g; s/<\/link>/\\e[00m ]/g
s/<description>/\\n\\n'$f_descr'/g; s/<\/description>/\\e[00m\\n\\n/g
s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/'$f_bold'/g; s/<\/b>\|<\/strong>/'$f_descr'/g
s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/'$f_italic'/g; s/<\/i>\|<\/em>/'$f_descr'/g
s/<u\( [^>]*\)\?>/'$f_underline'/g; s/<\/u>/'$f_descr'/g
s/<code\( [^>]*\)\?>/'$f_code'/g; s/<\/code>/'$f_descr'/g
s/<a[^§]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/'$f_linklabel'\2'$f_descr' '$f_formatchrs'['$f_descr' '$f_linkurl'\1'$f_descr''$f_formatchrs' ]'$f_descr'/g
s/<li\( [^>]*\)\?>/\n '$f_formatchrs'*'$f_descr' /g
s/<!\[CDATA\[\|\]\]>//g
s/\|>\s*<//g
s/ *<[^>]\+> */ /g
s/[<>£§]//g')\n\n";
# END OF THE RSS PARSER
if [ -n "$2" ]; then
echo "$1" > $FEED_BOOKMARKS/$2
echo -e "\\n\\t\\e[01;37m==> \\e[01;31mBookmark saved as \\e[01;36m\\e[04m$2\\e[00m\\e[01;37m <==\\e[00m\\n"
fi
}
deef() {
if test -n "$1"; then
if [ ! -r "$FEED_BOOKMARKS/$1" ]; then
echo -e "\\n \\e[01;31mBookmark \\e[01;36m\\e[04m$1\\e[00m\\e[01;31m not found.\\e[00m\\n\\n \\e[04mType:\\e[00m\\n\\n \\e[01;37m\$ deef\\e[00m (without arguments)\\n\\n to get the complete list of all currently saved bookmarks.\\n";
return 1;
fi
local url="$(cat $FEED_BOOKMARKS/$1)";
if [ ! -n "$url" ]; then
echo "The bookmark is empty";
return 1;
fi
echo -e "\\n\\t\\e[01;37m==> \\e[01;31m$url\\e[01;37m <==\\e[00m"
feed "$url";
else
echo -e "\\n \\e[04mUsage\\e[00m\\n\\n \\e[01;37m\$ deef \\e[01;31m<bookmark>\\e[00m\\n\\n \\e[04mCurrently saved bookmarks\\e[00m\\n";
for i in $(find $FEED_BOOKMARKS -maxdepth 1 -type f);
do echo -e " \\e[01;36m\\e[04m$(basename $i)\\e[00m";
done;
echo -e "\\n \\e[04mSee also\\e[00m\\n\\n \\e[01;37m\$ feed\\e[00m\\n";
fi;
}
Offline
Hi,
How can I restrict the number of news items shown?
Thank you,
Offline
@grufo:
There is a small bug in the parser (as you also can see in the wiki-entry simulation): the link target is not correct.
Change
s/<a[^§] ...
to
s/<a[^§|t] ...
to make it work as expected, otherwise sed will match for "<atomic ...", which is the feed link itself.
Btw: I hacked together an extended function for the login message like suggested in the wiki. It will only print the top message and tries to avoid needless downloads and views. Any interest?
Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse
Offline
@grufo:
There is a small bug in the parser (as you also can see in the wiki-entry simulation): the link target is not correct.
Thank you very mutch!
For now I have not enough time, but I think you can also fix the Wiki (I don't use this script, so I am unable to search for bugs)...
Btw: I hacked together an extended function for the login message like suggested in the wiki. It will only print the top message and tries to avoid needless downloads and views. Any interest?
Of course! Post it!
Offline
For now I have not enough time, but I think you can also fix the Wiki (I don't use this script, so I am unable to search for bugs)...
Fixed.
Of course! Post it!
It needs some polish, if done i will replace the wiki entry if you like it. However, it will take some time, because i am quite busy right now.
Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse
Offline
Hello,
do you guys have the same version of the script, but without the parsing of the content ? Without the content mark in fact.
Sincerely
Offline
This is awesome!
However, I want to have this run every time I open a terminal, so I would like to shorten it to one or tow entrie if possible. Is there a way to do that?
Offline
I did something that perhaps is what you are looking for. The code is a modified version from the Archwiki site to return the top N news with only its headers and links.
You can modified the code to suit your needs. My code is more of a hack so you can cut out the relevant pieces and stick it in those posted here.
Hope this can be helpful.
# Set N to be the number of latest news to fetch
NEWS=$(echo -e $(curl --silent https://www.archlinux.org/feeds/news/ | awk ' NR == 1 {N = 3 ; while (N) {print;getline; if($0 ~ /<\/item>/) N=N-1} ; sub(/<\/item>.*/,"</item>") ;print}'))
# Remove some tags
NEWS=$(echo -e $NEWS | \
awk '{
# uncomment to remove first line which is usually not a news item
sub(/<lastBuildDate[^>]*>([^>]*>)/,"");sub(/<language[^>]*>([^>]*>)/,"");sub(/<title[^>]*>([^>]*>)/,"");sub(/<link[^>]*>([^>]*>)/,"");
while (sub(/<guid[^>]*>([^>]*>)/,""));
while (sub(/<dc:creator[^>]*>([^>]*>)/,""));
while (sub(/<description[^>]*>([^>]*>)/,"")); print }' | \
sed -e ':a;N;$!ba;s/\n/ /g')
echo -e "$(echo -e $NEWS | \
sed -e 's/&/\&/g
s/<\|</</g
s/>\|>/>/g
s/<\/a>/£/g
s/href\=\"/§/g
s/<title>/\\n\\n :: \\e[01;31m/g; s/<\/title>/\\e[00m ::/g
s/<link>/\\n [ \\e[01;36m/g; s/<\/link>/\\e[00m ]\\n/g
s/<p\( [^>]*\)\?>\|<br\s*\/\?>/\n/g
s/<b\( [^>]*\)\?>\|<strong\( [^>]*\)\?>/\\e[01;30m/g; s/<\/b>\|<\/strong>/\\e[00;37m/g
s/<i\( [^>]*\)\?>\|<em\( [^>]*\)\?>/\\e[41;37m/g; s/<\/i>\|<\/em>/\\e[00;37m/g
s/<u\( [^>]*\)\?>/\\e[4;37m/g; s/<\/u>/\\e[00;37m/g
s/<code\( [^>]*\)\?>/\\e[00m/g; s/<\/code>/\\e[00;37m/g
s/<a[^§|t]*§\([^\"]*\)\"[^>]*>\([^£]*\)[^£]*£/\\e[01;31m\2\\e[00;37m \\e[01;34m[\\e[00;37m \\e[04m\1\\e[00;37m\\e[01;34m ]\\e[00;37m/g
s/<li\( [^>]*\)\?>/\n \\e[01;34m*\\e[00;37m /g
s/<!\[CDATA\[\|\]\]>//g
s/\|>\s*<//g
s/ *<[^>]\+> */ /g
s/[<>£§]//g')"
The most uninteresting quote is also interesting
Offline