#!/usr/bin/env pwsh #350 check if windows user run as admin # this allows us to call ps1 files, which allows us to have spaces in filenames # ('powershell "$Env:USERPROFILE\test.ps1" foo' will fail if it has a space in # the path but '& "$Env:USERPROFILE\test.ps1" foo' will work even with a space) Set-ExecutionPolicy -Scope Process Bypass # If a command returns an error, halt the script. $ErrorActionPreference = 'Stop' # Ignore progress events from cmdlets so Invoke-WebRequest is not painfully slow $ProgressPreference = 'SilentlyContinue' $Env:WEBI_HOST = 'https://webi.run' $Env:WEBI_PKG = 'vim-zig@2025.11.15-15.42.45' $Env:PKG_NAME = 'vim-zig' $Env:WEBI_VERSION = '2025.11.15-15.42.45' $Env:WEBI_GIT_TAG = 'master' $Env:WEBI_PKG_URL = 'https://ghfast.top/https://github.com/ziglang/zig.vim.git' $Env:WEBI_PKG_FILE = 'zig.vim-v2025.11.15-15.42.45' $Env:WEBI_PKG_PATHNAME = 'zig.vim-v2025.11.15-15.42.45' # Switch to userprofile Push-Location $Env:USERPROFILE # Make paths New-Item -Path "$Env:USERPROFILE\Downloads" -ItemType Directory -Force | Out-Null New-Item -Path "$Env:USERPROFILE\.local\bin" -ItemType Directory -Force | Out-Null New-Item -Path "$Env:USERPROFILE\.local\opt" -ItemType Directory -Force | Out-Null # {{ baseurl }} # {{ version }} # See # - # - $Esc = [char]27 $TTask = "${Esc}[36m" $TName = "${Esc}[1m${Esc}[32m" $TUrl = "${Esc}[2m" $TPath = "${Esc}[2m${Esc}[32m" $TCmd = "${Esc}[2m${Esc}[35m" $TDim = "${Esc}[2m" $TReset = "${Esc}[0m" function Invoke-DownloadUrl { Param ( [string]$URL, [string]$Params, [string]$Path, [switch]$Force ) IF (Test-Path -Path "$Path") { IF (-Not $Force.IsPresent) { Write-Host " ${TDim}Found${TReset} $Path" return } Write-Host " Updating ${TDim}${Path}${TDim}" } $TmpPath = "${Path}.part" Remove-Item -Path $TmpPath -Force -ErrorAction Ignore Write-Host " Downloading ${TDim}from${TReset}" Write-Host " ${TDim}${URL}${TReset}" IF ($Params.Length -ne 0) { Write-Host " ?$Params" $URL = "${URL}?${Params}" } curl.exe '-#' -f -sS -A $Env:WEBI_UA -L $URL | Out-File $TmpPath Remove-Item -Path $Path -Force -ErrorAction Ignore Move-Item $TmpPath $Path Write-Host " Saved ${TPath}${Path}${TReset}" } function Get-UserAgent { # This is the canonical CPU arch when the process is emulated $my_arch = "$Env:PROCESSOR_ARCHITEW6432" IF ($my_arch -eq $null -or $my_arch -eq "") { # This is the canonical CPU arch when the process is native $my_arch = "$Env:PROCESSOR_ARCHITECTURE" } IF ($my_arch -eq "AMD64") { # Because PowerShell is sometimes AMD64 on Windows 10 ARM # See https://oofhours.com/2020/02/04/powershell-on-windows-10-arm64/ $my_os_arch = (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture # Using -clike because of the trailing newline IF ($my_os_arch -clike "ARM 64*") { $my_arch = "ARM64" } } "PowerShell+curl Windows/10+ $my_arch msvc" } function webi_path_add($pathname) { # C:\Users\me => C:/Users/me $my_home = $Env:UserProfile $my_home = $my_home.replace('\\', '/') $my_home_re = [regex]::escape($my_home) # ~/bin => %USERPROFILE%/bin $pathname = $pathname.replace('~/', "$Env:UserProfile/") # C:\Users\me\bin => %USERPROFILE%/bin $my_pathname = $pathname.replace('\\', '/') $my_pathname = $my_pathname -ireplace $my_home_re, "%USERPROFILE%" $all_user_paths = [Environment]::GetEnvironmentVariable("Path", "User") $user_paths = "${all_user_paths}".Trim(';').Split(';') $exists_in_path = $false foreach ($user_path in $user_paths) { # C:\Users\me\bin => %USERPROFILE%/bin $my_user_path = $user_path.replace('\\', '/') $my_user_path = $my_user_path -ireplace $my_home_re, "%USERPROFILE%" if ($my_user_path -ieq $my_pathname) { $exists_in_path = $true } } if (-Not $exists_in_path) { $all_user_paths = "${pathname};${all_user_paths}".Trim(';') [Environment]::SetEnvironmentVariable("Path", $all_user_paths, "User") $null = Sync-EnvPath } } function Sync-EnvPath { $UserPath = [Environment]::GetEnvironmentVariable("Path", "User").Trim(';') $MachinePath = [Environment]::GetEnvironmentVariable("Path", "Machine").Trim(';') $Env:Path = "${UserPath};${MachinePath}" [Environment]::SetEnvironmentVariable("Path", $Env:Path) $Env:Path } $Env:WEBI_UA = Get-UserAgent #$has_local_bin = echo "$Env:PATH" | Select-String -Pattern '\.local.bin' #if (!$has_local_bin) #{ webi_path_add ~/.local/bin #} #!/usr/bin/env pwsh IF ($null -eq $Env:WEBI_HOST -or "" -eq $Env:WEBI_HOST) { $Env:WEBI_HOST = "https://webinstall.dev" } ############################# # Install vim-zig (zig.vim) # ############################# # ~/.vim/plugins/.vim $my_vim_confname = "zig.vim" # ~/.vim/pack/plugins/start// $my_vim_plugin = "zig.vim" # Non-executable packages should define these variables $pkg_cmd_name = "${my_vim_plugin}" $pkg_no_exec = $true $pkg_src = "$HOME\Downloads\webi\$Env:WEBI_PKG_PATHNAME" $pkg_dst = "$HOME\.vim\pack\plugins\start\$my_vim_plugin" function fn_vim_init { if (-Not (Test-Path "$HOME\.vimrc")) { New-Item -ItemType File -Path "$HOME\.vimrc" } New-Item -ItemType Directory -Force ` -Path "$HOME\.vim\pack\plugins\start" | Out-Null New-Item -ItemType Directory -Force ` -Path "$HOME\.vim\plugins" | Out-Null } function fn_git_shallow_clone { IF (Test-Path -Path "$pkg_src") { Write-Host "Found $pkg_src" Return } Write-Output "Checking for Git..." IF (-Not (Get-Command -Name "git" -ErrorAction Silent)) { & "$HOME\.local\bin\webi-pwsh.ps1" git $null = Sync-EnvPath } Write-Output "Cloning $Env:PKG_NAME from $Env:WEBI_PKG_URL to $pkg_src" $my_rnd = (Get-Random -Maximum 4294967295 -Minimum 65535).toString("X") $my_tmp = "$pkg_src.$my_rnd.part" & git clone --config advice.detachedHead=false --quiet ` --depth=1 --single-branch --branch "$Env:WEBI_GIT_TAG" ` "$Env:WEBI_PKG_URL" ` "$my_tmp" Move-Item "$my_tmp" "$pkg_src" } function fn_remove_existing { Remove-Item -Recurse -Force -ErrorAction Ignore ` -Path "$pkg_dst" | Out-Null } function fn_install { Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse } function fn_vim_config_download { $my_vim_confpath = "$HOME\.vim\plugins\$my_vim_confname" IF (Test-Path -Path "$my_vim_confpath") { Write-Host "Found $my_vim_confpath" Return } & curl.exe -sS -o "$my_vim_confpath" ` "$Env:WEBI_HOST/packages/${Env:PKG_NAME}/${my_vim_confname}" } function fn_vim_config_update { $my_vim_confpath = "$HOME\.vim\plugin\$my_vim_confname" Write-Host '' Write-Host 'MANUAL SETUP REQUIRED' ` -ForegroundColor yellow -BackgroundColor black Write-Host '' Write-Host "Add the following to ~/.vimrc:" ` -ForegroundColor magenta -BackgroundColor white Write-Host " source $my_vim_confpath" ` -ForegroundColor magenta -BackgroundColor white Write-Host '' # TODO manually add #$my_note="$Env:PKG_NAME: installed via webinstall.dev/$Env:PKG_NAME" } function main { fn_vim_init fn_git_shallow_clone fn_remove_existing fn_install fn_vim_config_download fn_vim_config_update } main webi_path_add ~/.local/bin # Done Pop-Location