Powershell 的工作环境
Powershell 工作环境
通常都在linux 下开发, 最新需要在window 下面开发,为了提高工作效率就在 Powershell 下面搭建一个简单的工作环境。 这个脚本有了基本的框架,可以方便个人根据各自的工作环境情况进行进一步的定制。
创建快捷方式
在桌面上创建快捷方式,快捷方式中命令行如下:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoExit -File C:\Vingo\ps\devPs.ps1
-File : 后面指向脚本所在的位置, 脚本内容如下(一些敏感配置已经删除):
function Set-PathAliase
{
$pathArray= @{
".."="cd .." ;
'...'='cd ..; cd ..';
"junk"="cd c:/junk";
"src"="cd c:/codes";
'tools'='cd c:/tools';
'vng' = "cd c:/vingo";
'gop' = "cd c:/junk/go";
}
foreach($command in $pathArray.Keys)
{
$funcStr = "function global:{0} {{ {1} }}" -f $command, $pathArray[$command]
Invoke-Expression -Command $funcStr
}
}
function Set-CmdAliase
{
$cmdAlas = @{
'ed' = 'C:\Vingo\tools\MicrosoftVSCode\Code.exe';
'bc' = 'C:\Program Files (x86)\Beyond Compare 3\BCompare.exe'
}
foreach($cmd in $cmdAlas.Keys)
{
Set-Alias -Name $cmd -Value $cmdAlas[$cmd] -Scope global
}
}
function Set-EnvPath {
$pathList = @(
"C:\Vingo\tools\go\bin",
"C:\Program Files\Perforce",
"C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64",
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd"
)
foreach($path in $pathList)
{
$env:Path="$env:Path" + ";" + $path
}
}
function Set-EnvParams {
$paramSet = @{
"GOPATH" = "c:/junk/go";
}
foreach($p in $paramSet.GetEnumerator()) {
[Environment]::SetEnvironmentVariable("$($p.Name)","$($p.Value)", "Process")
}
}
function Set-VsCmd
{
$targetDir = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools"
if (!(Test-Path (Join-Path $targetDir "VsDevCmd.bat"))) {
"Error: Visual Studio 2017 not installed"
return
}
pushd $targetDir
cmd /c "VsDevCmd.bat&set" |
foreach {
if ($_ -match "(.*?)=(.*)") {
Set-Item -force -path "ENV:\$($matches[1])" -value "$($matches[2])"
}
}
popd
}
Set-VsCmd
Set-PathAliase
Set-CmdAliase
Set-EnvPath
Set-EnvParams
write-host "`nSet up environment successfully." -ForegroundColor Yellow