Create equivalent bash alias in Windows terminal
Is it possible to create a Windows terminal or Powershell alias that works like this one? If so, how?
alias dep="dep -fdeploy/deploy.php"
Solution 1:
You can create a batch file that executes the command and name it what you wish the alias to be. If you then place the batch file in a location that is inside your PATH environmental variable, you can type your command anywhere and it will execute your batchfile, and thus your series of commands.
For example,
If you place the following script in your C:\Windows folder (this folder is by default in your PATH environment, so it should work, you can call it from anywhere.
Script name: deploy.cmd
Script content:
echo Starting deploy.php...
cd /d c:\path\to\dep
dep -fdeploy/deploy.php
The only limitation here is that your .cmd file cannot have the same extension as the executable you wish to run. Because the .exe file has priority over the .cmd file, if you were in the folder where dep.exe is located, typing dep without .cmd will call dep.exe instead without parameters. You can rename dep.exe too of course.
If you really want dep.cmd and dep.exe to exist side-by-side, then you will have to type dep.cmd if you are in the same folder for it to work, but can use dep without the .cmd everywhere else.
In my example here, I called the alias deploy and kept dep.exe the same. You could now type deply anywhere in a windows terminal or powershell session.
Note that Powershell does have the ability to create aliases too, but they don't cross over to the command prompt, so they would only work on Powershell.