Customizing bashrc, bash aliases, and more – II

On my the previous post, I explained a few tricks that I use in order to move faster through my project. Básically, you can achieve that by customizing bashrc file on your home directory.

Before moving on to a new topic, I’d like to explain some more tips related to my last post. We created a function called “_sitedirs” that was used just as completion of the input of our function. Well, we can take profit of this function and create many more helpful functions.

For instance, if our application logs all the debug and error messages within a project-relative path, we could easily create a function to display them. In my case, all the projects are running on Magento, so by default the logs are being stored on Project/var/log/*.log. Then It’s fairly easy to display the app logs, but I wanted to display the webserver errors as well. I’m using Nginx, and all the project’s configuration are set to save the logs at /var/log/nginx/Proiect.*.log, where Project is exactly the same name of the proyect’s folder. There are two log files for each nginx’s site: the access and errors. I’m only interested on showing the errors, so this is how my function looks:


#Helper to display project log
function logg() {
 tail -f /var/www/dev.$@*/$@/var/log/* /var/log/nginx/dev.$@.*.error.log
}

And in order to use the tab completion, we just need to add the following line:

complete -F _sitedirs -o dirnames logg  

Now, I can type logg, then type any key and/or press [TAB] to complete the name of the project, and that’s it, you can browse trough your project and check out the console to debug it.

There are many other possible usages, like clearing the cache, enabling/disabling maintenance mode, and many more, your only limit is your imagination!

That’s all from now, on my next post I’ll try to explain my aversion to the passwords and how I try to work without having to type a single one (whenever it’s possible).