aboutsummaryrefslogtreecommitdiff
path: root/.i3-blocks/blocks/feed
blob: 0030939f83d439b79f5ba46b48b31869eed85523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

# WARNING: This has a LIMIT of 32 characters for now!
# If your URL is longer you should use an URL shortener
# Caused by https://github.com/vivien/i3blocks/blob/01a4f4a9ca1e3d0b3c95d1d62000ad8506bdff1a/include/block.h#L50
# Example: https://goo.gl/
FEED_URL="${BLOCK_INSTANCE:-https://www.archlinux.org/feeds/news/}"

if [[ "${FEED_URL}" = "" ]]; then
  exit
fi

# Follows redirects!
FEED_CONTENT=$(curl ${FEED_URL} -s -L)
FEED_TITLE=$(echo "${FEED_CONTENT}" | grep -v "xmlns:atom" | grep -o '<title>.*</title>' | head -n 1 | sed 's/\(<title>\|<\/title>\)//g')
FEED_LINK=$(echo "${FEED_CONTENT}"  | grep -v "xmlns:atom" | grep -o '<link>.*</link>' | head -n 1 | sed 's/\(<link>\|<\/link>\)//g')

if [[ "${FEED_TITLE}" = *404* ]]; then
  echo "${FEED_URL}"
  echo "${FEED_URL}"
  echo ""
  exit 33
fi

if [[ "${BLOCK_BUTTON}" -eq 1 ]]; then
  xdg-open "${FEED_LINK}"
fi

echo "${FEED_TITLE}"
echo "${FEED_TITLE}"
echo ""