Reputation: 2822
I tried to create an alias for conda acitvate in Powershell but didn't get any luck so far. On my profile.ps1
function Get-CondaActivate { & conda activate} New-Alias -Name ca -Value Get-CondaActivate -Force -Option AllScope
It does nothing when ca myenv
. So I supposed I need argument, then
function Get-CondaActivate { & conda activate $args} New-Alias -Name ca -Value Get-CondaActivate -Force -Option AllScope
I got error msg:
Enter-CondaEnvironment : Cannot process argument transformation on parameter 'Name'. Cannot convert value to type System.String.
So how can I create an alias of ca myenv
to replace conda activate myenv
?
I would also like to have an alias to rename the powershellISE tab:
$psise.PowerShellTabs[1].DisplayName = 'new_name'
I think 1 and new_name needs to be replace by an argument. But totally no idea how to do it. :(
Thanks!
J
Upvotes: 2
Views: 474
Reputation: 174815
If you want a typed parameter in a function you need to declare it!
function Get-CondaActivate {
param([string]$EnvName)
& conda activate $EnvName
}
Otherwise make sure you pass only the argument you need, or convert the $args
array to a string before passing it to conda
:
& conda activate $args[0]
# or
& conda activate "$args"
Upvotes: 5