DEV Community

Cover image for Simplify your terminal commands
Cristian Zapata
Cristian Zapata

Posted on • Updated on

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 ~
πŸ‘Ύ
Enter fullscreen mode Exit fullscreen mode

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:

Image description

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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: $*"'
Enter fullscreen mode Exit fullscreen mode

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

gcm feat terminal workflow improved!
Enter fullscreen mode Exit fullscreen mode

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'
Enter fullscreen mode Exit fullscreen mode

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 on say hi on Instagram or GitHub.

Happy coding, folks!🐧

Top comments (0)