I have a PowerShell script that opens all files and programs related to my development environment. Rather than typing
> &.\mysetup.ps1
Run Code Online (Sandbox Code Playgroud)
is there some way I can alias it to just type
> gosetup
Run Code Online (Sandbox Code Playgroud)
?
Ideally I'll use this functionality for other PowerShell scripts as well! For reference, I want to run these commands from the Git PowerShell window.
Dav*_*vid 10
在您的个人资料中,添加以下行:
$ps_script_dir = "C:\path\to\scripts"
New-Alias <alias name> $ps_script_dir\<script name>
Run Code Online (Sandbox Code Playgroud)打开一个新shell,你应该能够通过别名调用你的脚本.
更新/附加信息
如果您只想简单地将一行代码或一小段代码分配给别名,则无需将其放入脚本文件中,如上所述,您只需在配置文件中创建一个函数:
function someUsefulOneliner
{
# Your one-liner goes here
}
set-item -path alias:<alias name> -value someUsefulOneliner
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6679 次 |
| 最近记录: |