Sometimes an alias is better than a settings file

hacker_compWhich one would you prefer if you are to choose between a simple alias or a full-fledged configuration file for your application? If your application uses XML based configuration, a settings file is inevitable. However, if it’s a terminal based application that does one thing well, you may definitely weigh your options.

The need for a configuration or settings file arises when

  • the options are difficult to memorize
  • there are too many options
  • users would definitely have some preferred (persistent) settings (e.g. currency unit)
  • the persistent options can be overridden on the fly
  • typing-in long commands is a hazard

A configuration file solves all these problems. However, the overhead is you need to open the configuration file on disk, read-in line by line and probably implement another parsing logic if you are using different delimiters or friendlier names for the options. As an example, let an application myutil have the following configuration settings:

value_a=10
value_b=name
value_c=place

Let’s say you are writing an application which accepts options in the short form, e.g. -a, -b and -c corresponding to the above settings. For this simple application, using an alias keeps things simpler. You use the same syntax as your command accepts and it is loaded with your ~/.bashrc. No additional disk access or distinct processing is required. Your simple alias is going to be:

alias util='myutil -a 10 -b name -c place

This is how the above alias covers for the conf file:

  • once you set the alias, no need to remember any option
  • number of options become irrelevant as you can append as many you want to the alias
  • preferred settings go into the alias
  • you can still use the same option in cmdline and override the value in alias
  • the alias makes the command (along with preferred options) shorter

Using aliases can also help simplify existing programs which are difficult to use and has no configuration file.

For live examples, check out the following:

  1. I have taken this approach in my project google-cli and explained the same in the readme for users. No complaints so far.
  2. It is quite easy to simplify existing utilities like sendMail through aliases (check the Improvements section).

One thought on “Sometimes an alias is better than a settings file”

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s