Powershell 的工作环境

在Windows环境下,为提高开发效率,本文档介绍了如何在Powershell下搭建工作环境,特别是如何创建快捷方式来启动带有自定义配置的Powershell会话。用户可以根据个人需求进一步定制这个基本框架。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值