Set-StrictMode -Version Latest # $PSVersionTable.OS # Write-Host # User paths if ($IsMacOS) { $userPaths = @( "$HOME/.bin", "$HOME/.cargo/bin", "$HOME/.gem/bin", "/usr/local/opt/ruby/bin", "/usr/local/sbin", "/opt/homebrew/bin", "/opt/homebrew/sbin" ) # APP home # cargo home $env:CARGO_HOME = "$HOME/.cargo" # rustup home $env:RUSTUP_HOME = "$HOME/.rustup" # nvm home $env:NVM_DIR = "$HOME/.nvm" } # User alias if ($IsWindows) { Set-Alias -Name brew -Value scoop } if ($IsMacOS) { if (Get-Command bat) { Set-Alias -Name cat -Value bat } } # Proxy ports $windowsHttpProxyPort = 1080 $macOSHttpProxyPort = 7890 $macOSSocks5hProxyPort = 7891 # Don't touch anything below if you're not orange enough. # https://github.com/PowerShell/PowerShell-RFC/pull/186 if ($IsMacOS) { # if ($PSVersionTable.PSVersion -ge 7) { # Write-Host "Please update PATH related script according to https://github.com/PowerShell/PowerShell-RFC/pull/186." # return # } # macOS PATH # $pathHelperResult = $(/usr/libexec/path_helper).Split('"')[1] $originalPath = $env:PATH try { $env:PATH = $null foreach ($userPath in $userPaths) { $env:PATH += $userPath + ":" } $env:PATH += $originalPath # $env:PATH += $pathHelperResult } catch { $env:PATH = $originalPath } } if ($IsMacOS -Or $IsLinux) { # Set GPG tty to fix git code signing error: gpg failed to sign the data $env:GPG_TTY = $(tty) } # Modules Import-Module posh-git Import-Module nvm # Functions function Enable-HttpProxy { if ($IsMacOS) { $env:http_proxy = $env:https_proxy = $env:all_proxy = "http://localhost:$macOSHttpProxyPort" } elseif ($IsWindows) { $env:http_proxy = $env:https_proxy = $env:all_proxy = "http://localhost:$windowsHttpProxyPort" } else { New-Object System.PlatformNotSupportedException } } function Enable-Socks5hProxy { if ($IsMacOS) { $env:http_proxy = $env:https_proxy = $env:all_proxy = "socks5h://localhost:$macOSSocks5hProxyPort" } else { New-Object System.PlatformNotSupportedException } } function Enable-GitGlobalHttpProxy { if ($IsMacOS) { git config --global http.proxy "http://localhost:$macOSHttpProxyPort" } elseif ($IsWindows) { git config --global http.proxy "http://localhost:$windowsHttpProxyPort" } else { New-Object System.PlatformNotSupportedException } } function Disable-Proxy { if ($IsMacOS -or $IsWindows) { $env:http_proxy = $env:https_proxy = $env:all_proxy = $null git config --global --unset http.proxy } else { New-Object System.PlatformNotSupportedException } } # Enable proxy by default. Enable-HttpProxy Enable-GitGlobalHttpProxy