Developers: How to Extend Your Shell with Custom Commands

Image_Banner_Academy_Enablement_Seismic_Enablement_ Side_ July2024.gif

During development, we at Celonis type a lot in our IDEs. The good thing about this process is that IDE supports us here a lot. Things like shortcuts, live templates, and other features help us get more code in, with less effort. You do not need to rename class across all places - just hit a shortcut instead. Or, if you need a public constant of a String type in your class, just type psfs and hit Tab. Lastly, if you do not know how to do this or that, just hit Shift key two times and ask IDEA.

Besides IDEs, we also type a lot in the shell (whatever you use, but I prefer zsh). I believe it would be cool to have similar level of convenience there, as well. There are plenty of existing extensions for it that can make your life easier, like kubectx, or fubectl for K8s, etc. However, sometimes it is not that easy to find an extension that does exactly what you want, and gives you exactly what you need daily, because it may be super-specific. To overcome this, you have the possibility of extending your shell with custom commands.

The shell can easily be extended with custom commands using two approaches: aliases and functions.

Alias

It is kind of a shortcut for another command. Let’s say to check the content of the directory with all hidden files, with human-readable size, in a list view, you would need to run something like this: ls -laGh. It is not that long, but you need to remember all the options.

Or, an even easier way is to simply add something like alias ll='ls -laGh' to your ~/.zshrc (or ~/.bashrc) and just be able to type $ ll.

alias.png

    #port check
function port() {
  lsof -i -P -n | grep :$1
}

Alexey Anufriev

Software development enthusiast, open-source contributor. Passionate about innovations in the IT world. Curious about security and performance. In spare time trying to tame JVM, and at work extending clouds.

author
  • Alexey Anufriev