My lazy (and smart?) encounter with aliases for Git
Earlier in the evening, I was working on updating my
dotfiles. Nothing fancy, adding a quick alias for some housekeeping on my
I had an eureka moment, out of nowhere. In that moment I realised this:
Tools should augment your creativity, not scream at your mistakes.
~ © 2020 Mrugesh Mohapatra.
Sounds ridiculous? Bear with me.
Have you ever been half asleep, and still go about doing routine chore in your dev or regular life? I tend to do that all the time, so much so it is almost subconscious to me.
Here is the story.
I have aliased several common typos that I make when I type in the command
git in my terminal. Here is a snippet of all the synonyms of
git in my lazy world:
# I can accidentally type 't' before 'i' alias gti="git" # I can accidentally type 'u' or 'o' which are neighbors to 'i' alias got="git" alias gut="git"
Of course, I am not the first person to do this. I am sure many of you use something similar too. Right? Anyway continuing with the the story; I was half asleep, (on a wednesday night. Again!), and needed to update a file, so I did this:
dotfiles on ⎇ master [!] ❯ vi ~/.alias
I added some changes, managed to save and exit out of
vi. And continued on in my exhausted life with:
dotfiles on ⎇ master [!] took 2s ❯ git status On branch master Your branch is up to date with 'origin/master'. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: home/.alias no changes added to commit (use "git add" and/or "git commit -a")
So far so good. And, all systems were normal, so my brain decided to get more sleepy. I dozed off for a couple seconds and I typed this:
dotfiles on ⎇ master [!] ❯ got doff WARNING: You called a Git command named 'doff', which does not exist. Continuing in 0.1 seconds, assuming that you meant 'diff'. ────────────────────────────────────────────── modified: home/.alias ────────────────────────────────────────────── @ home/.alias:100 @ if $(type bat > /dev/null 2>&1) && $(type fd > /dev/null 2>&1) && $(type fzf > / alias v='vi $(pbv)' fi #----------------------------- # update brew packages #----------------------------- alias letupdatebrew="brew update ; brew upgrade ; brew cask upgrade ; brew cleanup ; brew doctor ; brew file push"
Its very subtle, but it glares at your face when you look at it again. Yeah, I typed
got doff instead of
git diff!!! It had worked regardless.
Two things had happened here:
- My "genius" insight had worked. The alias had taken over and substituted the command I intended to run, i.e 'git' and not 'got'.
- Git which is way smarter than you think, had guessed the correct task that I intended to run, i.e is 'diff' and not 'doff'.
Isn't that cool?
I did not realise my mistake because it freaking did what I wanted. It has shown me a diff. I couldn't care more, and I continued to drift into my subconscious. And here is what I typed:
dotfiles on ⎇ master [!] ❯ gti add .
Yes, people yes. I had managed to mistype a command in a new way, yet one more time. And the best part is, it worked without any fuss! And continued to drive under influence, oblivious to what was happening with this next one:
dotfiles on ⎇ master [+] ❯ gut commit -m "feat(homebrew): alias to update and upgrade all" [master 0507c0d] feat(homebrew): alias to update and upgrade all 1 file changed, 6 insertions(+) dotfiles on ⎇ master [⇡] ❯
Can you believe that? I had used all of my typo aliases in a streak.
But then, of course I woke up. I looked at the terminal, I was shocked and laughed out aloud (quite literally). As I was contemplating my life decisions it dawned to me, this is good. I know it sounds silly and normal, but the bigger picture is the tools that I had chosen to use had helped my ass, and saved me some frustration when I was the most vulnerable. Exhausted and weary. Trying to save some work and be done for the day.
The lesson I learnt was:
Tools should always augment you & your creativity. They should "ideally" not scream at you. A nudge about a mistake is fine. IMHO, any hack that you can do to make your life easy is great. It does not make you lazy, it makes you smarter. It helps you avoid pitfalls and frustration.
Hope you liked this story. Until the next one (Hopefully on a sleepy wednesday!).
Stay safe and stay home. We got this.