A Fun Christmas Tree for the Bash Command Line
By: Al Williams
Tags: Bash, Ubuntu, Command Line, Linux, Programming

Happy holidays with no GUI required!

While not everyone celebrates Christmas, everyone can still appreciate a beautifully decorated tree, especially if there are presents underneath. If you don’t have enough space for a real tree, you can always put one up in your terminal window, thanks to a clever bash script from Sergio Lepore. Even Windows users can get in on the act thanks to things like WSL and Cygwin.

It also is a fun little script if you’d like to try your hand at customizing a bash script. Let’s just set it up first and worry about customizing later, if you are interested.

User Space

The Christmas tree script is on GitHub. While there are lots of ways to get it, if you just want to use the script, the easiest thing to do is download it as a zip file. Go to the GitHub page.

You’ll see a green button marked “Code”:

The green button is near the top of the page and to the right

Click the Code button and select Download ZIP. I am going to assume you know how to unpack a ZIP file. The file you want — unless you want Spanish — is tree-EN.sh. You don’t really need any of the rest which are really things for GitHub or those who want to run with Docker (which is overkill for this).

If the file is not executable — you can tell by using ls -l and looking for the x flag, you’ll need to set the executable bit. It won’t hurt if you set it and it is already set, so if you are in doubt, just do it. If you put the .sh file in your ~/Desktop directory, the command would be:

chmod +x ~/Desktop/tree-EN.sh

You could use the Spanish version (tree-ES.sh), of course. You can also rename the version you want to something like xmastree.sh, if you prefer.

Once you have the file marked as executable, you can run it like anything else. By default, Linux doesn’t have the current directory on the PATH, so if you have the file somewhere that isn’t on the path, you’ll need to point to it:

~/Desktop/tree-EN.sh

That assumes, of course, it is in your Desktop directory. If it is in the current directory, simply execute:

./tree-EN.sh

For Coders Only

If you want to customize the tree, you could follow the same steps, but that isn’t the way you should do things on GitHub. If you just want to play around, you can clone the code from the repository using git (which you may have to install using your system’s package manager):

This will create a directory called ChristBASHTree in your current directory and populate with the stuff from the repository. You can then code away by opening the tree-EN.sh file in your favorite text editor.

If you were making serious changes someone else might want, it would be a good idea to fork the project to your own workspace. There is a Fork button in the top right screen of the page. My GitHub ID is wd5gnr, so after the fork, I’d issue:

The difference is, now I can make changes and then push them up to GitHub for everyone to see and share.

I am not going to do an entire git tutorial, but the basic ideas are simple:

Make your changes to the code after doing the clone. Use git status to see what’s changed Use git add to mark files that you want to include as part of your changes. In our case, git add tree-EN.sh although you’d also need to add any new files you create. Issue a git commit or, if you want to include all tracked changed files (that is, files that have been added at some time in the past) just use git commit -a . You’ll need to enter a comment about what changed in a text editor that will appear. If you are satisfied with your changes, you can send them to GitHub: git push .

So if I added a file, library.sh and made some changes to the main file, a session might look like this:



cd ChristBASHTree.git

cp ~/boilerplate/library.sh . git clone https://github.com/wd5gnr/ChristBASHTree.git cd ChristBASHTree.gitcp ~/boilerplate/library.sh . emacs tree-EN.sh # make changes we want and save

git status # not necessary, but shows you what's going on git add library.sh # Include this file with the commit

git commit -a # An editor will appear to add a comment

git status # also not neccessary git push # send back to GitHub

Try adding your family names to the Christmas tree. It isn’t that hard and it is a good way to get your feet wet with Bash scripting on a fun and festive project! Merry Christmas and Happy New Year from For Linux Users.