Creating your own cowsay messenger


One of the sillier, but still fun, tools available on Linux is called “cowsay”. It’s used to display a phrase along with an ASCII art image of a cow.

The cowsay command allows you to create messages that are less likely to be overlooked and might come across as just a little friendlier than the other thousand or so messages most of us get every day. For example:

$ cowsay This is cowsay!
 _________________
< This is cowsay! >
 -----------------
           ^__^
           (oo)_______
            (__)       )/
                ||----w |
                ||     ||

Once cowsay is installed on your system, you can create cute little messages – and you’re not limited to displaying a cow! In fact, if you wander over to the cowsay‘s directory –  /usr/share/cowsay/cows – you’ll see that there’s a fairly large collection of files available. Each includes a different image. You can choose from images as diverse as a snowman and a stegosaurus. If you want to greet your Australian friends using cowsay, you might try using the koala.

Note that you need to specify the cowsay file that you want to use if you want something other than the standard cow (in this case, koala.cow). You don’t have to include the .cow file extension in your command.

$ cowsay -f koala Hey, how are you?
 ___________________
< Hey, how are you? >
 -------------------
  
   
       ___
     {~._.~}
      ( Y )
     ()~*~()
     (_)-(_)

If you want to be intimidating, on the other hand, you might try a dragon!

$ cowsay -f dragon I dare you to come a little closer
 ____________________________________
< I dare you to come a little closer >
 ------------------------------------
                          /   //
           |___/|      /   //  
            /0  0  __  /    //  |  
           /     /  /_/    //   |    
           @_^_@'/   /_   //    |      
           //_^_/     /_ //     |        
        ( //) |        ///      |          
        ( / /) _|_ /   )  //       |           _
    ( // /) '/,_ _ _/  ( ; -.    |    _ _.-~        .-~~~^-.
  (( / / )) ,-{        _      `-.|.-~-.           .~         `.
 (( // / ))  '/      /                 ~-. _ .-~      .-~^-.  
 (( /// ))      `.   {            }                   /        
  (( / ))     .----~-.        -'                 .~           `. ^-.
             ///.----..>                     _ -~             `.  ^-`  ^-_
               ///-._ _ _ _ _ _ _}^ - - - - ~                     ~-- ,.-~

Personalizing cowsay

You can also create your own cowsay images, and it’s not that hard to do. In the remainder of this post, I’m going to show you how. You will need to have root access to add your new file(s) to the /usr/share/cowsay/cows directory.

Step 1: The art

There are a couple ways to create your ascii art. You can, as I’ve done in this post, create it simply by typing keyboard characters into a file. Alternately, you can use a tool such as jp2a that turns jpg files into ASCII art, but the resultant file is like to be a bit overwhelming. Cowsay art shouldn’t be so complicated that your recipients fail to notice the message! So, I started with two images that I created – a Christmas tree and then a menorah – in honor of the December holidays. My Christmas tree looked like this:

                 *
                / 
               /   
              /  o  
             / *     
            /     o   
            /       * 
           /   o       
          /_       *   _
           / *         
          /       o     
         /__   *       __
           / o     *   
          /   *      o  
         /       o       
        /__ o        *  __
         /      *  o     
        /  *  o        *  
       /  o       *  o     
      /_____________________
                | |
       _________| |_________

I called the image xmas_tree.cow. The extension is required so that cowsay can find and use it.

Step 2: The cowsay setup

To get my image ready for cowsay, I also needed some additional lines. Referencing one of the existing cowsay files, I found it easy to grab the ones I needed. The comments are not required, but the two lines following them are needed.

# a snowman
# 2020 Sandra_H-S <bugfarm@gmail.com>
$the_cow = <<EOF
   $thoughts

As the very last line in the file, I also added EOF. This marks the end of the image and matches the EOF shown in the 3rd line shown above. These delimiting lines are required for cowsay.

I quickly came to understand that the backslashes in my art needed to be “escaped” (i.e., turned into two backslashes each), so I modified my cowsay file, also adding the backslashes shown in the upper left that act as the line connecting the message to the character or image intended to be seen as delivering it. The complete file then looked like this:

# a Christmas tree
# 2020 Sandra_H-S <bugfarm@gmail.com>
$the_cow = <<EOF
   $thoughts
                *
               / 
              /   
             /  o  
            / *     
           /     o   
           /       * 
           /   o       
          /_       *   _
           / *         
          /       o     
         /__   *       __
           / o     *   
          /   *      o  
         /       o       
        /__ o        *  __
         /      *  o     
        /  *  o        *  
       /  o       *  o     
      /_____________________
                | |
       _________| |_________
EOF

Now typing “cowsay -f xmas_tree Merry Christmas!” shows my message as I intended.

$ cowsay -f xmas_tree Merry Christmas!

 __________________
< Merry Christmas! >
 ------------------
   
                *
               / 
              /   
             /  o  
            / *     
           /     o   
           /       * 
           /   o       
          /_       *   _
           / *         
          /       o     
         /__   *       __
           / o     *   
          /   *      o  
         /       o       
        /__ o        *  __
         /      *  o     
        /  *  o        *  
       /  o       *  o     
      /_____________________
                | |
       _________| |_________

Drawing a menorah with my keyboard was a little more trouble, but I came up with this:

$ cowsay -f menorah.cow Happy Hannukah!
 _________________
< Happy Hannukah! >
 -----------------
   
                 ()
                 ||
  ()  ()  ()  ()  ||  ()  ()  ()  ()
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  +  ++  ++  ++  ++  ++  ++  ++  +/
    ||  ||  ||  ||  ||  ||  || //
    ||  ||  ||  ||  ||  ||  ||//
     ||  ||  ||  ||  ||  ||  ||/
        ||  ||  ||  ||  ||  //
       _||__||__||__||__||_//
        ____________________/
                  ||
                  ||
                  ||
                 /  
                /____

To prepare my image, I once again had to double up on the backslashes, but vi commands such as :s//\/g22 helped with that. Notice I had to double up my backslashes again to tell vi to turn every backslash into two backslashes. Even vi needs escapes for some characters. The cowsay file then looked like this:

# a menorah
# 2020 bugfarm <bufarm@gmail.com>
$the_cow = <<EOF
   $thoughts
                 ()
                 ||
  ()  ()  ()  ()  ||  ()  ()  ()  ()
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  ||  ||  ||  ||  ||  ||  ||  ||  ||
  +  ++  ++  ++  ++  ++  ++  ++  +/
   \ ||  ||  ||  ||  ||  ||  || //
    \||  ||  ||  ||  ||  ||  ||//
     ||  ||  ||  ||  ||  ||  ||/
      \  ||  ||  ||  ||  ||  //
       \_||__||__||__||__||_//
        ____________________/
                  ||
                  ||
                  ||
                 /  
                /____

EOF

Notice that my menorah has all of the candles already lit. You could, however, make a group of cowsay files if you want to light them one at a time.

Join the Network World communities on Facebook and LinkedIn to comment on topics that are top of mind.

Copyright © 2020 IDG Communications, Inc.



Source link