I was wondering about… Why we don’t have a $this
keyword implemented in git CLI, Today we will go through it via a workaround to add it yourself.
Table of contents
- What on the earth is aliases. ( prerequisite )
-
What is the shell. ( prerequisite )
- Set an alias for (this) keyword.
Note: Prerequisites can be skipped.
1) What on the earth is aliases
Alias in my terms is a some sort of bundling or referencing, or even can be called labeling any command - with additional flags attached (in most of the cases) - to can use this command later with the new label.
In general, it used as a shortcut for commands specially when it comes to long command.
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.
In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI), depending on a computer’s role and particular operation. It is named a shell because it is the outermost layer around the operating system (wiki).
Different types of shells in linux
If you now understand what a kernel is, what a shell is, and why a shell is so important for Linux systems, let’s move on to learning about the different types of shells that are available.
Each of these shells has properties that make them highly efficient for a specific type of use over other shells. So let us discuss the different types of shells in Linux along with their properties and features.
The bourne shell (sh)
Developed at AT&T Bell Labs by Steve Bourne, the Bourne shell is regarded as the first UNIX shell ever. It is denoted as sh. It gained popularity due to its compact nature and high speeds of operation.
This is what made it the default shell for Solaris OS. It is also used as the default shell for all Solaris system administration scripts.
The GNU bourne-again shell (bash)
More popularly known as the Bash shell, the GNU Bourne-Again shell was designed to be compatible with the Bourne shell. It incorporates useful features from different types of shells in Linux such as Korn shell and C shell.
It allows us to automatically recall previously used commands and edit them with help of arrow keys, unlike the Bourne shell.
The complete path-name for the GNU Bourne-Again shell 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 was developed to include useful programming features like in-built support for arithmetic operations and a syntax similar to the C programming language.
Further, it incorporated command history which was missing in different types of shells in Linux like the Bourne shell. Another prominent feature of a C shell is “aliases”.
The complete path-name for the C shell is
/bin/csh
. By default, it uses the prompthostname#
for the root user andhostname%
for the non-root users.
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. The Korn shell is essentially a superset of the Bourne shell.
Besides supporting everything that would be supported by the Bourne shell, it provides users with new functionalities. It allows in-built support for arithmetic operations while offereing interactive features which are similar to the C shell.
The Korn shell runs scripts made for the Bourne shell, while offering string, array and function manipulation similar to the C programming language. It also supports scripts which were written for the C shell. Further, it is faster than most different types of shells in Linux, including the C shell.
The complete path-name for the Korn shell is
/bin/ksh
. By default, it uses the prompt~#
for the root user and~$
for the non-root users.
The Z shell (zsh) the one that i’m using ^^
The Z Shell or zsh is a sh shell extension with tons of improvements for customization. If you want a modern shell that has all the features a much more, the zsh shell is what you’re looking for.
Some noteworthy features of the z shell include:
- Generate filenames based on given conditions
- Plugins and theming support
- Index of built-in functions
- Command completion
3) Set an alias for (this) keyword
- Open your shell source via any editor, Then add an alias - for
$this
specifically - besides the other aliases if you added some before of course :)
here i’m using zshell and i opened it via nano
Add the alias like line 20
# My custom aliases:
1 alias open="nemo"
2 alias golang="go"
...
20 alias this="git branch --show-current"
After adding it… Now you may need to restart your shell, And you’re ready to go
Let’s try:
➜ salih git:(develop) ✗ git add -A
➜ salih git:(develop) ✗ git commit -m "Update."
[develop ae2fe9e] Update.
6 files changed, 45 insertions(+), 19 deletions(-)
delete mode 100644 content/posts/how-to-git-with-the-this-keyword/imgs/main.png
create mode 100644 content/posts/how-to-git-with-the-this-keyword/imgs/open-via-nano.png
➜ salih git:(develop) git push origin `this`
Enumerating objects: 26, done.
Counting objects: 100% (26/26), done.
Delta compression using up to 2 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (14/14), 13.23 KiB | 3.31 MiB/s, done.
Total 14 (delta 7), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (7/7), completed with 7 local objects.
To github.com:salihcodev/salih.git
74f42b0..ae2fe9e develop -> develop
➜ salih git:(develop)
You see? it works, From now no need for mentioning the branch name.