Simplify your terminal commands

As a fellow developer, I'm sure you've found yourself navigating your terminal to manage files, run scripts, or handle git commands. And let's be honest, some of these tasks can be pretty repetitive, right? Ever wondered, "Is there a faster or easier way to do this?" If not, I bet you will eventually. And that's where this blog comes in handy. Today, I'll show you how to level up your workflow with some terminal tricks.

Take, for instance, being in your system's home folder:

theposintech@cristian in ~
๐Ÿ‘พ

Now, imagine wanting to move to your project folder located at home/Documents/development/projects/myRust_app. Typing out that entire path every time is a drag. Or consider committing changes to your project. It's a whole process, right? But guess what? You can create custom shortcuts for these tasks using something called alias.

What is an alias?

An alias is like a cheat code for your commands. It lets you create shortcuts for lengthy commands, making them quicker to type and easier to remember.

Here's how you structure an alias:

Now, how do we put this into action? Well, we need to move into our shell ๐Ÿš configuration file. In my case, I'm using zsh, so I'll head over to ~/.config and open up nvim .zshrc. If you're using bash, it's .bashrc.

In this file, we'll use the alias property to assign a name to our new command and specify the command it should run.

alias gst="git status"

Save the changes (in neovim, :w to save and :q to close) and then run this command in your terminal (if you're using zsh like me):

exec zsh

Now, you can run your new command in the terminal. But what if you need your alias to do something dynamic, like prompting you for input? Say, when you're committing changes and need to specify a message. In that case, you can define an input for your alias like this:

alias gcm='git commit -m "$reach: $*"'

Then, when you use it in your terminal, you'll replace those parameters with your messages.

gcm feat terminal workflow improved!

Where the final output will be "feat: terminal workflow improved!", Buut if we want to go forther we can use multiple commands in the same alias, let's to continue with our last example.

So, we've committed our changes. Now, let's push them to our repo with git push.

alias gcm='git commit -m "$reach: $*" && git push'

With the &&, the command on the right executes immediately after the left one finishes.

To consider

The alias we configure in our term will just work on our terminal (zsh), and if we want to use them in another one we have to configure them in that specific term too.

Thank you!

I hope this blog helps you streamline your console time and supercharge your developer productivity. If it does, don't hesitate to share it with your friends so they can level up too.

If you wanna share knowledge feel free to say hi on Instagram or GitHub.

Happy coding, folks!๐Ÿง

0
Subscribe to my newsletter

Read articles from Cristian Zapata Arias directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Cristian Zapata Arias
Cristian Zapata Arias

Hello there! I'm Cristian Zapata ๐Ÿ‘ฝ a graphic designer, visual artist and front-end developer focused on JavaScript, Angular and Typescript. Beyond the screen, I'm fascinated by the intricacies of systems, networks, and security, constantly expanding my knowledge in scripting and self-configuring Neovim setups with plugins. I'm also passionate about crafting unique keyboards and merging art with technology to create something truly special. Let's explore the endless possibilities together! ๐Ÿš€