Skip to content
Myr

Add install.ps1 for downloading fzf.exe on Windows (#1845)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by jiangjianshan · committed by GitHub · parent 001d116 · Browse files · 1 file+73 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+73 added−0 removed

  • other:+73 added−0 removed

1 file+73 added−0 removed

added:install.ps1+73 added
1$version="0.20.0"23if ([Environment]::Is64BitProcess) {4 $binary_arch="amd64"5} else {6 $binary_arch="386"7}89$fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition1011function check_binary () {12 Write-Host " - Checking fzf executable ... " -NoNewline13 $output=cmd /c $fzf_base\bin\fzf.exe --version 2>&114 if (-not $?) {15 Write-Host "Error: $output"16 $binary_error="Invalid binary"17 } else {18 $output=(-Split $output)[0]19 if ($version -ne $output) {20 Write-Host "$output != $version"21 $binary_error="Invalid version"22 } else {23 Write-Host "$output"24 $binary_error=""25 return 126 }27 }28 Remove-Item "$fzf_base\bin\fzf.exe"29 return 030}3132function download {33 param($file)34 Write-Host "Downloading bin/fzf ..."35 if ("$version" -ne "alpha") {36 if (Test-Path "$fzf_base\bin\fzf.exe") {37 Write-Host " - Already exists"38 if (check_binary) {39 return40 }41 }42 }43 if (-not (Test-Path "$fzf_base\bin")) {44 md "$fzf_base\bin"45 }46 if (-not $?) {47 $binary_error="Failed to create bin directory"48 return49 }50 cd "$fzf_base\bin"51 if ("$version" -eq "alpha") {52 $url="https://github.com/junegunn/fzf-bin/releases/download/alpha/$file"53 } else {54 $url="https://github.com/junegunn/fzf-bin/releases/download/$version/$file"55 }56 $temp=$env:TMP + "\fzf.zip"57 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls1258 (New-Object Net.WebClient).DownloadFile($url, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$temp"))59 if ($?) {60 (Expand-Archive -Path $temp -DestinationPath .); (Remove-Item $temp)61 } else {62 $binary_error="Failed to download with powershell"63 }64 if (-not (Test-Path fzf.exe)) {65 $binary_error="Failed to download $file"66 return67 }68 check_binary >$null69}7071download "fzf-$version-windows_$binary_arch.zip"7273Write-Host 'For more information, see: https://github.com/junegunn/fzf'