2024-01-01 00:01:43 +00:00
|
|
|
$version="0.45.0"
|
2020-02-12 08:56:53 +00:00
|
|
|
|
|
|
|
$fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition
|
|
|
|
|
|
|
|
function check_binary () {
|
|
|
|
Write-Host " - Checking fzf executable ... " -NoNewline
|
|
|
|
$output=cmd /c $fzf_base\bin\fzf.exe --version 2>&1
|
|
|
|
if (-not $?) {
|
|
|
|
Write-Host "Error: $output"
|
|
|
|
$binary_error="Invalid binary"
|
|
|
|
} else {
|
|
|
|
$output=(-Split $output)[0]
|
|
|
|
if ($version -ne $output) {
|
|
|
|
Write-Host "$output != $version"
|
|
|
|
$binary_error="Invalid version"
|
|
|
|
} else {
|
|
|
|
Write-Host "$output"
|
|
|
|
$binary_error=""
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Remove-Item "$fzf_base\bin\fzf.exe"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function download {
|
|
|
|
param($file)
|
|
|
|
Write-Host "Downloading bin/fzf ..."
|
2020-10-26 16:46:43 +00:00
|
|
|
if (Test-Path "$fzf_base\bin\fzf.exe") {
|
|
|
|
Write-Host " - Already exists"
|
|
|
|
if (check_binary) {
|
|
|
|
return
|
2020-02-12 08:56:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (-not (Test-Path "$fzf_base\bin")) {
|
|
|
|
md "$fzf_base\bin"
|
|
|
|
}
|
|
|
|
if (-not $?) {
|
|
|
|
$binary_error="Failed to create bin directory"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
cd "$fzf_base\bin"
|
2020-10-26 16:46:43 +00:00
|
|
|
$url="https://github.com/junegunn/fzf/releases/download/$version/$file"
|
2020-02-12 08:56:53 +00:00
|
|
|
$temp=$env:TMP + "\fzf.zip"
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
2021-01-28 02:41:23 +00:00
|
|
|
if ($PSVersionTable.PSVersion.Major -ge 3) {
|
|
|
|
Invoke-WebRequest -Uri $url -OutFile $temp
|
|
|
|
} else {
|
|
|
|
(New-Object Net.WebClient).DownloadFile($url, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$temp"))
|
|
|
|
}
|
2020-02-12 08:56:53 +00:00
|
|
|
if ($?) {
|
2020-06-07 01:57:23 +00:00
|
|
|
(Microsoft.PowerShell.Archive\Expand-Archive -Path $temp -DestinationPath .); (Remove-Item $temp)
|
2020-02-12 08:56:53 +00:00
|
|
|
} else {
|
|
|
|
$binary_error="Failed to download with powershell"
|
|
|
|
}
|
|
|
|
if (-not (Test-Path fzf.exe)) {
|
|
|
|
$binary_error="Failed to download $file"
|
|
|
|
return
|
|
|
|
}
|
2021-01-28 02:41:23 +00:00
|
|
|
echo y | icacls $fzf_base\bin\fzf.exe /grant Administrator:F ; check_binary >$null
|
2020-02-12 08:56:53 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 16:01:58 +00:00
|
|
|
download "fzf-$version-windows_amd64.zip"
|
2020-02-12 08:56:53 +00:00
|
|
|
|
|
|
|
Write-Host 'For more information, see: https://github.com/junegunn/fzf'
|