summaryrefslogtreecommitdiffstats
path: root/install.ps1
diff options
context:
space:
mode:
authorjiangjianshan <jiangjianshan1103@gmail.com>2020-02-12 16:56:53 +0800
committerGitHub <noreply@github.com>2020-02-12 17:56:53 +0900
commitf39cf6d855ace3a38efb4fd0f11f792a53319992 (patch)
tree0696ec000aae0d26d1121174d8db2247485f1d7e /install.ps1
parent001d1168848c0d799e69f4172eaeb79cce9f36c0 (diff)
Add install.ps1 for downloading fzf.exe on Windows (#1845)
Diffstat (limited to 'install.ps1')
-rw-r--r--install.ps173
1 files changed, 73 insertions, 0 deletions
diff --git a/install.ps1 b/install.ps1
new file mode 100644
index 00000000..46bd9403
--- /dev/null
+++ b/install.ps1
@@ -0,0 +1,73 @@
+$version="0.20.0"
+
+if ([Environment]::Is64BitProcess) {
+ $binary_arch="amd64"
+} else {
+ $binary_arch="386"
+}
+
+$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 ..."
+ if ("$version" -ne "alpha") {
+ if (Test-Path "$fzf_base\bin\fzf.exe") {
+ Write-Host " - Already exists"
+ if (check_binary) {
+ return
+ }
+ }
+ }
+ 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"
+ if ("$version" -eq "alpha") {
+ $url="https://github.com/junegunn/fzf-bin/releases/download/alpha/$file"
+ } else {
+ $url="https://github.com/junegunn/fzf-bin/releases/download/$version/$file"
+ }
+ $temp=$env:TMP + "\fzf.zip"
+ [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
+ (New-Object Net.WebClient).DownloadFile($url, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$temp"))
+ if ($?) {
+ (Expand-Archive -Path $temp -DestinationPath .); (Remove-Item $temp)
+ } else {
+ $binary_error="Failed to download with powershell"
+ }
+ if (-not (Test-Path fzf.exe)) {
+ $binary_error="Failed to download $file"
+ return
+ }
+ check_binary >$null
+}
+
+download "fzf-$version-windows_$binary_arch.zip"
+
+Write-Host 'For more information, see: https://github.com/junegunn/fzf'