问题
I would like to know how to do set-alias in PowerShell for the cmd used in developing Firefox extension:
cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp
I've added the following to Microsoft.PowerShell_profile.ps1:
Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
But when PowerShell is launched, it shows the error:
Set-Alias : A positional parameter cannot be found that accepts argument 'run'.
At D:\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:2 char:1
+ Set-Alias cfxp cfx run -p "C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profil ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Alias], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetAliasCommand
Also tried:
Set-Alias cfxp "cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
with another error:
cfxp : The term 'cfx run -p C:\Users\username\AppData\Roaming\Mozilla\Firefox\Profiles\ripltbxm.cfxp' is not recognized
as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ cfxp
+ ~~~~
+ CategoryInfo : ObjectNotFound: (cfx run -p C:\U...s\ripltbxm.cfxp:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
回答1:
In PowerShell aliases can be defined only for commands or cmdlets, not for entire commandlines with parameters:
NAME
New-Alias
SYNOPSIS
Creates a new alias.
[...]
DESCRIPTION
The New-Alias cmdlet creates a new alias in the current Windows
PowerShell session. Aliases created by using New-Alias are not
saved after you exit the session or close Windows PowerShell. You
can use the Export-Alias cmdlet to save your alias information to
a file. You can later use Import-Alias to retrieve that saved
alias information.
PARAMETERS
[...]
-Value <String>
Specifies the name of the cmdlet or command element that is
being aliased.
You'll need a custom function if you want a shorthand for running a particular command with parameters.
function cfxp {
& cfx run -p "$env:APPDATA\Mozilla\Firefox\Profiles\ripltbxm.cfxp"
}
来源:https://stackoverflow.com/questions/30327065/alias-syntax-for-firefox-cfx-run-profile-dir