Debian Codegraph @

install.ps1

raw
1 $version="0.74.4"
2
3 $fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition
4
5 function check_binary () {
6 Write-Host " - Checking fzf executable ... " -NoNewline
7 $output=cmd /c $fzf_base\bin\fzf.exe --version 2>&1
8 if (-not $?) {
9 Write-Host "Error: $output"
10 $binary_error="Invalid binary"
11 } else {
12 $output=(-Split $output)[0]
13 if ($version -ne $output) {
14 Write-Host "$output != $version"
15 $binary_error="Invalid version"
16 } else {
17 Write-Host "$output"
18 $binary_error=""
19 return 1
20 }
21 }
22 Remove-Item "$fzf_base\bin\fzf.exe"
23 return 0
24 }
25
26 function download {
27 param($file)
28 Write-Host "Downloading bin/fzf ..."
29 if (Test-Path "$fzf_base\bin\fzf.exe") {
30 Write-Host " - Already exists"
31 if (check_binary) {
32 return
33 }
34 }
35 if (-not (Test-Path "$fzf_base\bin")) {
36 md "$fzf_base\bin"
37 }
38 if (-not $?) {
39 $binary_error="Failed to create bin directory"
40 return
41 }
42 cd "$fzf_base\bin"
43 $url="https://github.com/junegunn/fzf/releases/download/v$version/$file"
44 $temp=$env:TMP + "\fzf.zip"
45 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
46 if ($PSVersionTable.PSVersion.Major -ge 3) {
47 Invoke-WebRequest -Uri $url -OutFile $temp
48 } else {
49 (New-Object Net.WebClient).DownloadFile($url, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$temp"))
50 }
51 if ($?) {
52 (Microsoft.PowerShell.Archive\Expand-Archive -Path $temp -DestinationPath .); (Remove-Item $temp)
53 } else {
54 $binary_error="Failed to download with powershell"
55 }
56 if (-not (Test-Path fzf.exe)) {
57 $binary_error="Failed to download $file"
58 return
59 }
60 echo y | icacls $fzf_base\bin\fzf.exe /grant Administrator:F ; check_binary >$null
61 }
62
63 download "fzf-$version-windows_amd64.zip"
64
65 Write-Host 'For more information, see: https://github.com/junegunn/fzf'