Programmer Productivity – Part 2

In the first part of the series I wrote about basic console commands. Those are very useful. But besides the plain commands you can also use aliases or even functions to enhance your command line workflows. For more complex tasks various build systems can be used.

Aliases

Every bash offers the possibility to adapt commands to your personal needs by using aliases. An alias is a symbol for a original command that can be called instead of the original command.

The first and most important alias for me is the alias that lets me open the file which defines the aliases (~/.bash_profile on MacOs):

alias aliases=’subl ~/.bash_profile’

The line starts with the string alias. This tells the bash that you want to define a new one. The name of your new alias comes next, in this case aliases. After an equal sign I define that I want to call “subl ~/.bash_profile” which will call my favourite text editor Sublime Text 2 and open the file .bash_profile. This way I can easily edit my aliases afterwards.

As I use GIT via the command line I created short aliases for commands I use frequently:

alias ga=’git add .’
alias gpl=’git pull’
alias gp=’git push -u origin ‘
alias gs=’git status’
alias gb=’git branch’

I’ve fixed a bug? ga [Enter] gc “bugfix” [Enter] gp master [Enter]. Consider using branches for bugfixes.

Functions

Aliases are great, but they are just aliases. If you need even more advanced functionality and more flexibility you can use functions. As software developer you should be familiar with functions. They have a name, a signature and offer a certain functionality. So you can incorporate complex logic in bash scripts and use the similar to aliases. I’m not an expert on complex functions, but those simple functions help a lot in my git workflow:

function gco() { git checkout $@; }
gco my-branch-or-commit

function gc() { git commit -m “$@” ;}
gc “my commit message”

Build Scripts/Automation

Automation is the key to remove cumbersome work which thwarts other more important tasks. A good way to automate tasks like copying, combining, compiling or even deploying files is to use a build system. There are endless numbers of build systems out there, you will easily be able to find one for your favourite runtime environment and language. Personally I love to use rake, grunt and gulp. All three help to create tasks in a very clean and declarative way without removing the flexibility of using a custom script. Also there a many gems (Rake) and plugins (grunt, gulp) out there, so you probably find one which solves your automation problem.

Conclusion

Automation is what technology is all about. There are many tools out there – especially for developers – that help you to automate repetitive tasks.

Nevertheless I think that automation needs time. Maybe you ask yourself how often you will reach the break-even-point at that the time invested on creating the automation is less than the time spent by manually doing a task. I think that often you won’t reach this point.

But I personally think that even if an automation project will never reach this point it helped you to keep your routine (so the next automation can be implemented faster) and also it saves you from repetitive tasks that can be frustrating and demotivating.

Learn how to automate, keep yourself trained and you will be more productive.