windwo怎么配置alias别名使用

使用 PowerShell Profile

powershell
# 检查是否存在 profile
Test-Path $PROFILE

# 如果不存在则创建
New-Item -Type File -Path $PROFILE -Force

编辑 Profile 文件

powershell
notepad $PROFILE

在文件中添加函数

#powershell
function Start-Proxy {
    $Env:http_proxy="http://192.168.21.111:7890"
    $Env:https_proxy="http://192.168.21.111:7890"
}

function Stop-Proxy {
    set HTTP_PROXY=
    set HTTPS_PROXY=
}

function Show-Proxy {
    Write-Output "Current proxy settings:"
    netsh winhttp show proxy
}

# 设置别名
Set-Alias startproxy1 Start-Proxy
Set-Alias stopproxy1 Stop-Proxy
Set-Alias proxystatus Show-Proxy

重新加载 Profile

powershell
. $PROFILE

注意这是在powershell里面是这样设置的,使用是在powershell里面使用

如果在cmd环境下添加一个bat文件到有环境变量可以识别的目录就可以
比如添加一个startproxy.bat,使用的时候在cmd下startproxy就可以了

set HTTP_PROXY=http://192.168.21.111:7890
set HTTPS_PROXY=http://192.168.21.111:7890
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容