Custom Fortune Cookie / Random Tips - Open New Terminal

Apr 12, 2022

Those who are tired of reading the same old repetitive fortune cookies, you have come to the right place to learn the magic of configuring dynamic and more useful tips.

Prerequisites:

Kindly install the following tools from your package manager

Create a Bash Function to pull from your desired website:

For educational purposes, I’m picking up https://til.hashrocket.com.

curl -s https://til.hashrocket.com/random | hxnormalize -x | hxselect 'div.post__content'

In your .rc file (bashrc, .etc,.):

if [ ! "$TIP" ]; then
  fortune 30% linux 30% beam 10% computers 10% science 10% debian 5% wisdom 5% work
else
  echo "$RANDOM_TIP" | w3m -dump -T 'text/html'
  echo "Pulled from https://til.hashrocket.com on $(date +'%d-%m-%Y %H:%M:%S')."
fi
Custom-Random-Tip-on-Terminal-Shell

The end result should look like the above screenshot Whenever you open a new terminal window or tab. Hope you enjoyed the tutorial!


   linux (5) , unix (5) , shell (1) , terminal (1) , til (4)