DEV Community

Avinash Tiwari
Avinash Tiwari

Posted on

Perform cumbersome repetitive terminal commands with few clicks

Being a developer, I know that everyone loves to be in the terminal all the time ๐Ÿ˜. I mean who doesn't like that blackish background with a blinking little cursor, the hostname in green color, and those sweet sweet commands! (Uh oh! I think romantic me has kicked in ๐Ÿ˜…๐Ÿ˜ฌ Back to the topic). So, I know how cool it looks to be using the terminal all the time, but we hate it switching to the terminal for some basic regular tasks ๐Ÿ˜“, like starting the server, deploying stuff, checking the logs, etcetra etcetra...๐Ÿ˜ช

What if I tell you, we can have a button to make it all possible with just a single click? How cool it will be to just click on the button and woosh! It's done!๐Ÿ˜‰ Okay, if you've imagined till this way...let's add some more spice to it! What if I tell you, you can use it directly using your favorite text editor? You guessed it right! VS Code!

"Enough of the showreel Avinash! Let's get to the business๐Ÿ™„" - Okay Okay, so let's learn what things you'll need to do in order to have the same spell in your system!

VSCode extension Quick Task
tasks.json file in the directory
So, let me tell you the spell on how to do this magic trick on your system, trust me it's really very simple๐Ÿ˜‰.

  • Go to the extension section of VSCode and search for "Quick Task". Install it

Image description

  • We now, need to create some tasks in VSCode for the extension to pick them up. So, open the command palette by clicking the combination of Ctrl (Command for Mac) + Shift + P.
  • Type in "task" and select "Configure Default Build Task".

Image description

  • You'll see an option to create a custom task, select it.

Image description

  • You need to tell the type of command the task will perform. We can choose "Others" in this case, as we are going to automate some shell commands.

Image description

  • Now, a file named tasks.json will be created containing all the tasks. You can add label, command and leave the type to be shell.

Image description

  • Enter the shell command you want to automate and it's done! Reload your VSCode for the extensions to pick up the tasks from tasks.json.
  • You'll see an icon in the bottom bar to open all the tasks available in your workspace. It will also, show you tasks from package.json file, if you are using javascript.

Image description

Image description

You must be thinking, "Avinash, what if the command requires an input? How to do it then?๐Ÿค”". Don't worry, I have got you covered!๐Ÿ˜‰

We just need to specify the inputs and use them in our command in tasks.json. It will prompt to take input while running and performing a task.

Here is an example of such a task:-

Image description
This example will ask for a commit message from you when you run this specific task. So, you can automate some repetitive tasks that you do daily with these easy steps. Thanks for reading.

Let me know about any shortcomings in the comments below!

Stay tuned for more such tips & tricks!

Top comments (0)