17

I already know that you can get some nice quotes/jokes using the fortune program.

But I've found in this urwird script a new source of fun that I'd like to have when I open a new terminal.

This time the jokes come from http://www.icndb.com.

26

You can use the icndb RESTful API: http://www.icndb.com/api/.

  1. Install the cowsay, recode and jshon packages:

    sudo apt-get install cowsay recode jshon
    
  2. Then just add the following lines to your .bashrc:

    if [ "$PS1" ]; then
        wget "http://api.icndb.com/jokes/random" -qO- | jshon -e value -e joke -u |
        recode html | cowsay -f tux
    fi
    

    Note: checking if $PS1 is set ensures that the jokes won't be displayed on non-interactive sessions.

  3. Now when I open a gnome-terminal I get:

    enter image description here

10
  • 3
    If you're installing cowsay, you might as well install jshon too. It makes parsing the JSON a lot more concise (and probably faster): wget "http://api.icndb.com/jokes/random" -qO- | jshon -e value -e joke -u – Oli Sep 23 '14 at 12:52
  • 1
    I'm not sure you'll need that (recode) with JSON. And jshon's -u should return a decoded string anyway. – Oli Sep 23 '14 at 13:10
  • 1
    Fair enough. That's icndb.com's fault more than JSON. – Oli Sep 23 '14 at 13:14
  • 1
    I'm pretty sure the default ~/.bashrc already checks if it's an interactive shell ([[ $- != *i* ]] && return). – nyuszika7h Sep 23 '14 at 13:32
  • 2
    No need for a backslash for line continuation after a pipe. The pipe causes the line to be continued by itself. – Dennis Williamson Sep 23 '14 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.