I was wondering about… Why we don’t have a $this keyword implemented in git CLI. Today we will go through a workaround to add it yourself.
Note: Prerequisites can be skipped.
1) What on the earth is aliases
Alias, in my terms, is a sort of bundling or referencing — labeling any command (with additional flags attached in most cases) so you can use that command later with the new label.
In general it is used as a shortcut for commands, especially long ones.
2) What is the shell
A shell is a computer program which exposes an operating system’s services to a human user or other programs.
Operating system shells use either a command-line interface (CLI) or a graphical user interface (GUI), depending on a computer’s role. It is named a shell because it is the outermost layer around the operating system.
Different types of shells in Linux
Each of these shells has properties that make them efficient for a specific type of use.
The Bourne shell (sh)
Developed at AT&T Bell Labs by Steve Bourne, the Bourne shell is regarded as the first UNIX shell. It is denoted as sh. It gained popularity due to its compact nature and high speeds of operation. It became the default shell for Solaris OS and is used as the default shell for many Solaris system administration scripts.
The GNU Bourne-again shell (bash)
More popularly known as Bash, the GNU Bourne-Again shell was designed to be compatible with the Bourne shell. It incorporates useful features from shells such as Korn shell and C shell. It allows you to recall previously used commands and edit them with the arrow keys.
The complete path for Bash is
/bin/bash.
The C shell (csh)
The C shell was created at the University of California by Bill Joy. It is denoted as csh. It includes programming features like built-in support for arithmetic operations and a syntax similar to C, plus command history and aliases.
The complete path for the C shell is
/bin/csh.
The Korn shell (ksh)
The Korn shell was developed at AT&T Bell Labs by David Korn to improve the Bourne shell. It is denoted as ksh. It is essentially a superset of the Bourne shell, with interactive features similar to the C shell, and support for string, array, and function manipulation.
The complete path for the Korn shell is
/bin/ksh.
The Z shell (zsh) — the one that I’m using
The Z shell is a sh shell extension with lots of improvements for customization. Noteworthy features include filename generation, plugins and theming, built-in functions, and command completion.
3) Set an alias for the this keyword
Open your shell config in any editor, then add an alias for this alongside your other aliases.
Here I am using zsh and opened it via nano. Add the alias like line 20:
After adding it, restart your shell (or reload the config). You are ready to go.
Try:
You see? It works. From now on there is no need to type the branch name by hand.