Totorosay

Totorosay

How to customize the Linux cowsay command with your favorite character

I regret to inform you, that I never liked the 'cow{say,think}' Linux command. Sorry for that, I never felt the need to incorporate a speaking cow in my scripts or to get the quote of the day:

marco@xps:~$ fortune | cowsay 
 ____________________________________
/ Generosity and perfection are your \
\ everlasting goals.                 /
 ------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Also, I never liked the cow itself! That's the topic of this post, what if we can change the character to a more pleasant one? Maybe a cat, or even better: Totoro!

Cowsay has a man page

Well, I did not expect that but there is documentation, of course, there is!

The authors already envisaged the possibility to change characters. The so-called "COWFILE"s are located in the /usr/share/cowsay/cows directory. Unless a specific one is indicated with the -f option the "default.cow" will be used. The collection of animals also includes the Linux Mascotte:

marco@xps:~$ echo Hi! | cowsay -f tux
 _____
< Hi! >
 -----
   \
    \
        .--.
       |o_o |
       |:_/ |
      //   \ \
     (|     | )
    /'\_   _/`\
    \___)=(___/

But let's stick to the original plan. Follow the steps:

mkdir ~/.cows
vim ~/.cows/default.cow

Once you open the default.cow file and paste inside the following code:

$the_cow = <<"EOC";
 $thoughts      |\\__/|
   $thoughts    /0 ~ 0\\
      >/ __-__ \\<
      / /^ ^ ^\\ \\
     / /^ ^ ^ ^\\ \\
     /||..      ||\\
     "\\\\..      //"
      \\ \\._____/ /
        ^^^ ^^^
EOC

The strings $thoughts will be replaced with the speech balloon. Instead, if you plan to customize the ASCII code, remember that you have to escape all the \ characters otherwise will not be visible (e.g. \\ )

Finally, let's run the command setting the COWPATH env variable:

COWPATH=~/.cows cowsay 'Hi!'

You can make this change permanent by exporting the variable in your .bashrc file.

Conclusions

You learned how to customize the cowsay command at will, also it is possible to set a specific location for our ASCII artwork without interfering with the OS installation.

Nobody asked me to do that.. anyway from now on I will be keener to use cowsay!

What is your favorite character? Show me your ASCII masterpiece in the comments!

Did you find this article valuable?

Support Marco's blog by becoming a sponsor. Any amount is appreciated!