I'm trying to set up a Windows PowerShell alias to run MinGW's g++ executable with certain parameters. However, these parameters need to come after the file name and other arguments. I don't want to go through the hassle of trying to set up a function and all of that. Is there a way to simply say something like:
alias mybuild="g++ {args} -lib1 -lib2 ..."
or something along those lines? I am not all that familiar with PowerShell, and I'm having a difficult time finding a solution. Anyone?
To build an function, store it as an alias, and persist the whole thing in your profile for later, use:
where you have replaced
ALIAS
with the alias you want andCOMMANDS
with the command or string of commands to execute.Of course, instead of doing that you can (and should!) make an alias for the above by:
Just in case your brain got turned inside out from all the recursion (aliasing of aliases, etc.), after pasting the second code block to your PowerShell (and restarting PowerShell), a simple example of using it is:
or without args:
Iff you don't have a profile yet
The above method will fail if you don't have a profile yet! In that case, use
New-Item -type file -path $profile -force
from this answer.You want to use a function, not an alias, as Roman mentioned. Something like this:
To try this out, here's a simple example:
You might also want to put this in your profile in order to have it available whenever you run PowerShell. The name of your profile file is contained in
$profile
.There is not such a way built-in. IMHO, a wrapper function is the best way to go so far. But I know that some workarounds were invented, for example:
https://web.archive.org/web/20120213013609/http://huddledmasses.org/powershell-power-user-tips-bash-style-alias-command
This is a sample function that will do different things based on how it was called: