分享我的windows開發環境

rufo發表於2022-01-05

在使用過mac和window做開發,我個人感覺還是windows開發效率高。
比如有utool這些工具,還是powershell加docker,直接上天。

最終效果如圖:

分享我的windows開發環境

安裝docker

直接去官網下載安裝

安裝php環境

推薦使用https://github.com/yeszao/dnmp,
我自己也用 docker-compose 搞了個,不過沒別人的方便。

安裝Scoop

使用scoop來管理軟體,以管理員身份執行PowerShell,執行

Set-ExecutionPolicy RemoteSigned -scope CurrentUser

然後執行安裝命令

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
# 或者
iwr -useb get.scoop.sh | iex

更換 scoop 源,依次執行

scoop config SCOOP_REPO https://gitee.com/squallliu/scoop
scoop update

scoop bucket add java https://hub.fastgit.org/ScoopInstaller/Java.git
scoop bucket add php https://hub.fastgit.org/ScoopInstaller/PHP.git
scoop bucket add versions https://hub.fastgit.org/ScoopInstaller/Versions.git
scoop bucket add nightlies https://hub.fastgit.org/ScoopInstaller/Nightlies.git
scoop bucket add extras https://hub.fastgit.org/lukesampson/scoop-extras.git

基本使用

scoop install [app]@[版本號] 

使用conda虛擬環境(python可選)

conda install -n root -c pscondaenvs pscondaenvs

安裝oh-my-posh主題和powershell外掛

管理員許可權開啟powershell,將CurrentUserExecutionPolicy(執行許可權)從原來的Undefined更改成RemoteSigned,同時信任來自PSGallery的所有模組:


Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Set-PSRepository -Name PSGallery -InstallationPolicy Trusted

安裝外掛

# ls顏色外掛
Install-Module -AllowClobber Get-ChildItemColor -Scope CurrentUser
# Docker外掛
Install-Module DockerCompletion -Scope CurrentUser
# oh-my-posh主題
Install-Module oh-my-posh -Scope CurrentUser
# PSReadLine外掛
Install-Module -Name PowerShellGet -Force
Install-Module -Name PSReadLine -AllowPrerelease -Force
# 類似zsh的jump外掛
Install-Module ZLocation -Scope CurrentUser
#安裝顏色外掛
Install-Module -AllowClobber Get-ChildItemColor -Scope CurrentUser

安裝字型

建議使用JetBrainsMono字型,下載地址:www.nerdfonts.com/font-downloads

我的配置

需要更新配置檔案$PROFILE,類似於Linux Bash的.bashrc,輸入:

code $PROFILE

在開啟的檔案中新增:

Import-Module posh-git
Import-Module DockerCompletion
Import-Module oh-my-posh
Import-Module PSReadLine
Import-Module Get-ChildItemColor

Set-PSReadLineKeyHandler -Key Tab -Function Complete
Set-PSReadLineKeyHandler -Key "Ctrl+d" -Function MenuComplete 

#Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
#Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -PredictionSource History

Set-PSReadLineOption -PredictionViewStyle ListView

Set-PoshPrompt  negligible

# function prompt { "Lunar $pwd" }
function cd... { Set-Location ..\.. }
Set-Alias dc docker-compose -Option "AllScope"

function which
{
    $results =New-Object System.Collections.Generic.List[System.Object];
    foreach ($command in $args)
    {
        $path = (Get-Command $command).Source
        if ($path)
        {
            $results.Add($path);
        }
    }
    return $results;
}
Set-Alias cat Get-Content -Option "AllScope"

#設定別名
function dp([string]$msg) { 
    if($msg -eq "a"){
        Write-Output "docker ps -a"
        docker ps -a
    }else{
        echo "docker ps "
        docker ps
    }
}

function dphp { 
     docker exec -it php /bin/sh
}


function build([string]$msg) { 
    Set-Location D:\Projects\docker_env
    docker-compose stop $msg 
    docker-compose build $msg
    docker-compose up -d $msg
}

function sh([string]$msg) { 
   docker exec -it $msg /bin/sh
}
function bash([string]$msg) { 
   docker exec -it $msg /bin/bash
}
function dr([string]$msg) { 
   docker restart $msg
}

# 3. 檢視目錄 ls & ll
function ListDirectory {
    (Get-ChildItem).Name
    Write-Host("")
}

# 設定ls和ll
$GetChildItemColorTable.File['Directory'] = "Red"
ForEach ($Exe in $GetChildItemColorExtensions.ExecutableList) {
    $GetChildItemColorTable.File[$Exe] = "Green"
}

Set-Alias -Name ll -Value Get-ChildItem
Set-Alias l Get-ChildItem -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope

# 下面是conda的別名
function workon($name){
    activate $name
    # echo "切換到環境:"+[string]$name
}
function in($name){
    activate $name
    # echo "切換到環境:"+[string]$name
}
function out{
    deactivate
}

我使用的windows terminal主題:

{
            "background": "#1B1B23",
            "black": "#000000",
            "blue": "#564D9B",
            "brightBlack": "#5D3225",
            "brightBlue": "#867AED",
            "brightCyan": "#EAEAEA",
            "brightGreen": "#29E620",
            "brightPurple": "#A05EEE",
            "brightRed": "#FF6388",
            "brightWhite": "#BFA3FF",
            "brightYellow": "#F08161",
            "cursorColor": "#A063EB",
            "cyan": "#808080",
            "foreground": "#877A9B",
            "green": "#37A415",
            "name": "Urple",
            "purple": "#6C3CA1",
            "red": "#B0425B",
            "selectionBackground": "#A063EB",
            "white": "#87799C",
            "yellow": "#AD5C42"
        }

到此就配置差不多了

本作品採用《CC 協議》,轉載必須註明作者和本文連結
What is worth doing is worth doing well.

相關文章