Simplify Commands In Window Using These Simple Steps

Mario Gunawan
3 min readNov 28, 2022

--

Let’s get straight to the point, there are A LOT of ways of doing this. But, in this article, I’m gonna be discussing only two approach that each serve a different purpose (and both are popular). So let’s get into it!

Using Doskeys To Create Alias

The first and the most native approach — also the one that shows up when you search on google — is doskey. Let’s assume you want to shorten ping google.com -t command, which pings google to measure your internet connection. You can type this in your command prompt:

doskey ping_google=ping google.com -t

Now try ping_google command in your command prompt (to stop pinging, type ctrl + c in your cmd prompt).

What if I want to make arguments passable? For example, I don’t want to use the -t flag by default, I could use the $* for the doskey to accept additional arguments. Try running this command:

doskey ping_google=ping google.com $*

Now, you can run it vanilla with ping_google which ping google 4 times or run ping_google -t which ping google endlessly (until you stop). You can try this in your terminal

ping_google result

This is not permanent when you close the terminal, you need to run the doskeycommand again. To make the command alias permanent, follow Argyli’s answer in stackoverflow.

Using Makefile To Create Different Scripts For A Project

When dealing with a project — more often than not — we need to create more than one repeatable commands. Using the above approach works, but it could be better if the commands are easy to understand, change, and share for your colleagues. That’s when Makefile comes in. Steps to use make in windows

  1. Download chocolatey
  2. Run choco install make
  3. Restart your terminal
  4. Create a file with the name Makefile that have those text:
ping_google_endlessly: # this is called target
ping google.com -t # the command to be run

ping_google:
ping google.com

Save the file, then run this command in terminal

make

it should ping google endlessly, because the first target is always the default to be run with make . To run the second command, use

make ping_google

It will ping google 4 times and tells you the report. You can add more targets as you grow your project. But remember, this approach is project-specific, meaning that you have to create a new Makefilein every directory that you want to have repeated scripts in.

Sadly, make doesn’t have any easy way to add optional arguments. To add arguments, you can refer to this SO.

Hope this helps. See ya!

--

--

Mario Gunawan

I'm a mobile / web developer. I'm mostly writing articles about software development.