Improve your dev environment with Z shell and VarDumper

If you are a developer who spends a lot of time in shell every day, you probably find useful the default shell in Ubuntu/Mac OS, but are also looking for some tool that can make everyday tasks a lot easier? The solution could be Z shell. Another problem that I'm facing as PHP/Drupal 8 developer is debugging. The most popular debugging method in PHP still remains the same – showing variables in the browser. With symfony/var-dumper component it has never been easier.

Z shell

Z shell is a very useful tool for interactive tasks. It has autocomplete feature and support for customizable prompts, loadable modules, global alias, etc. It also has more user-friendly interface and looks better than Bash.

Installation

For Debian-based systems, install it with aptitude tool by:

sudo apt install zsh

For installing zsh on different platforms you can refer here Installing ZSH.

There are several ways to replace the default shell with zsh. The best way for switching shell automatically is installing oh-my-zsh. Oh My Zsh is an extension of zsh shell, which provides themes and plug-ins. You can install this in command-line with either curl or wget.

via curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

via wget

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

Once it is installed, your terminal shell will be changed from:
Z shell before

to:
Z shell after

The example above shows git plugin in action but there are other plugins as well.
Plugins and themes can be enabled by editing .zshrc file in your $HOME directory. Open this file in a text editor and find plugins=(git) and ZSH_THEME="robbyrussell". Install your plugins and add them to plugin list. To use a different theme, simply change the value to match the name of your desired theme.

VarDumper

Another tool that I often use is Symfony VarDumper component. VarDumper is a component designed to replace your var_dumps. var_dump generates clumsy and unreadable monochromatic output. If you’re an Xdebug user, you’re probably used to a better-looking output than raw PHP prints. And if you are Drupal 8 developer then you'll probably need tool that provides much more information about objects with better formatting.

Installation

Installing VarDumper is as simple as with any decent modern PHP project composer (also with Drupal 8):

composer require symfony/var-dumper

After installing component you can use dump($var) anywhere in your code and get formatted output of the objects.

paragraph

VarDumper component is not a replacement for Xdebug, but a very useful tool if you want to see nested structure of your object. In Drupal 8 you can use tools like Kint, but I found VarDumper generating better output.

These are the tools that I use on a daily basis to improve my development environment and make it easier for me. If you find this article interesting and useful, follow my future articles, I'll try to keep you informed about the other tools that I use. For more information, browse the links I've posted, or post a comment.