add fzf for Mac, Windows 10, and Linux
authorAJ ONeal <aj@therootcompany.com>
Wed, 15 Jul 2020 00:00:13 +0000 (00:00 +0000)
committerAJ ONeal <aj@therootcompany.com>
Wed, 15 Jul 2020 00:00:13 +0000 (00:00 +0000)
fzf/README.md [new file with mode: 0644]
fzf/install.ps1 [new file with mode: 0644]
fzf/install.sh [new file with mode: 0644]
fzf/releases.js [new file with mode: 0644]

diff --git a/fzf/README.md b/fzf/README.md
new file mode 100644 (file)
index 0000000..3932d8f
--- /dev/null
@@ -0,0 +1,32 @@
+---
+title: fzf
+homepage: https://github.com/junegunn/fzf-bin
+tagline: |
+  fzf is a general-purpose command-line fuzzy finder.
+---
+
+### Updating
+
+```bash
+webi fzf@stable
+```
+
+Use the `@beta` tag for pre-releases.
+
+## Cheat Sheet
+
+> It's an interactive Unix filter for command-line that can be used with any
+> list; files, command history, processes, hostnames, bookmarks, git commits,
+> logs, etc.
+
+### Live filter search results
+
+```bash
+find . | fzf
+```
+
+### Live filter logs
+
+```bash
+sudo journalctl -u my-app-name  --since '2020-01-01' | fzf
+```
diff --git a/fzf/install.ps1 b/fzf/install.ps1
new file mode 100644 (file)
index 0000000..6360ede
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/env pwsh
+
+$VERNAME = "$Env:PKG_NAME-v$Env:WEBI_VERSION.exe"
+$EXENAME = "$Env:PKG_NAME.exe"
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    echo "Downloading $Env:PKG_NAME from $Env:WEBI_PKG_URL to $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part"
+    & move "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE.part" "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+}
+
+IF (!(Test-Path -Path "$Env:USERPROFILE\.local\xbin\$VERNAME"))
+{
+    echo "Installing $Env:PKG_NAME"
+    # TODO: temp directory
+
+    # Enter tmp
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft
+        Remove-Item -Path "$Env:PKG_NAME-v*" -Recurse -ErrorAction Ignore
+
+        # Unpack archive
+        # Windows BSD-tar handles zip. Imagine that.
+        echo "Unpacking $Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+        & tar xf "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+        # Move single binary into root of temporary folder
+        & move "$EXENAME" "$VERNAME"
+        & dir
+
+        # Settle unpacked archive into place
+        echo "New Name: $VERNAME"
+        echo "New Location: $Env:USERPROFILE\.local\xbin\$VERNAME"
+        Move-Item -Path "$VERNAME" -Destination "$Env:USERPROFILE\.local\xbin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$Env:USERPROFILE\.local\bin\$EXENAME' from '$Env:USERPROFILE\.local\xbin\$VERNAME'"
+Remove-Item -Path "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$Env:USERPROFILE\.local\xbin\$VERNAME" -Destination "$Env:USERPROFILE\.local\bin\$EXENAME" -Recurse
diff --git a/fzf/install.sh b/fzf/install.sh
new file mode 100644 (file)
index 0000000..392fe8c
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+{
+    set -e
+    set -u
+
+    ###############
+    # Install fzf #
+    ###############
+
+    WEBI_SINGLE=true
+
+    pkg_get_current_version() {
+      # 'fzf --version' has output in this format:
+      #       0.21.1 (334a4fa)
+      # This trims it down to just the version number:
+      #       0.21.1
+      echo $(fzf --version 2>/dev/null | head -n 1 | cut -d' ' -f 1)
+    }
+
+    pkg_install() {
+        # $HOME/.local/xbin
+        mkdir -p "$pkg_src_bin"
+
+        # mv ./fzf* "$HOME/.local/opt/fzf-v0.21.1/bin/fzf"
+        mv ./fzf* "$pkg_src_cmd"
+
+        # chmod a+x "$HOME/.local/opt/fzf-v0.21.1/bin/fzf"
+        chmod a+x "$pkg_src_cmd"
+    }
+}
diff --git a/fzf/releases.js b/fzf/releases.js
new file mode 100644 (file)
index 0000000..5865d4b
--- /dev/null
@@ -0,0 +1,20 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'junegunn';
+var repo = 'fzf-bin';
+
+module.exports = function (request) {
+  return github(request, owner, repo).then(function (all) {
+    return all;
+  });
+};
+
+if (module === require.main) {
+  module.exports(require('@root/request')).then(function (all) {
+    all = require('../_webi/normalize.js')(all);
+    all.releases = all.releases.slice(0, 10);
+    //console.info(JSON.stringify(all));
+    console.info(JSON.stringify(all, null, 2));
+  });
+}