Intro

This will be a short-and-sweet one. What is an alias you ask? It’s a shorthand version (macro) pretty much. Welp, let’s use it for something. Essentially, let’s goof off with it, for starters. Instead of using sudo, let’s go with something more … well fun.

Here’s the obligatory screenshot:

“pls” as an alias for sudo

Guide

Step 1.

Open ~/.bashrc with your favourite text editor (nano, vim …)

Step 2.

At the very bottom of the file, add your alias in the following format:

alias='command'

Here’s mine:

The current file setup

Step 3.

Save the file and load the script, by running the following command:

source ~/.bashrc

And you’re done. I’m using this as a goof, but you can map seriously heafty commands to an alias, and you can make your life easier.

A more usable example

PHPCS is an amazing tool for checking code quality, if you’ve never heard of it check it out here: https://github.com/squizlabs/PHP_CodeSniffer

The command to check for PSR compliance is lengthy, and I really don’t want to type it out every time, so let’s make an alias of it.

Base command:

 php phpcs.phar
      -p
      -n
      -d memory_limit=320M
      --standard="${STANDARD}"
      --extensions=php,phtml
      --runtime-set testVersion "${PHP_VER}" app

Mapped as an alias (inside the bashrc file:

Mapped the compliance check in the file

The above line is callable with psrcompliance from the terminal

Great stuff, have fun!

Home