feature(delta): add *nix and Windows installer + cheat sheet
authorJay Palacio <jaypalacio@gmail.com>
Sun, 21 Nov 2021 11:36:46 +0000 (06:36 -0500)
committerAJ ONeal <aj@therootcompany.com>
Tue, 23 Nov 2021 07:15:36 +0000 (07:15 +0000)
delta/README.md [new file with mode: 0644]
delta/install.ps1 [new file with mode: 0644]
delta/install.sh [new file with mode: 0644]
delta/releases.js [new file with mode: 0644]
test/install.sh

diff --git a/delta/README.md b/delta/README.md
new file mode 100644 (file)
index 0000000..461fc76
--- /dev/null
@@ -0,0 +1,27 @@
+---
+title: delta
+homepage: https://github.com/dandavison/delta
+tagline: |
+  delta: A syntax-highlighting pager for git and diff output
+---
+
+To update or switch versions, run `webi delta` (or `@0.9.1`, `@0.9.0`,
+etc).
+
+## Cheat Sheet
+
+Install delta and add this to your `~/.gitconfig`:
+
+```gitconfig
+[pager]
+    diff = delta
+    show = delta
+    log = delta
+    blame = delta
+    reflog = delta
+
+[interactive]
+    diffFilter = delta --color-only
+```
+
+Make sure to check out the helpful [ReadMe](https://github.com/dandavison/delta/blob/master/README.md)
diff --git a/delta/install.ps1 b/delta/install.ps1
new file mode 100644 (file)
index 0000000..8679d09
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/env pwsh
+
+##################
+# Install delta #
+##################
+
+# Every package should define these variables
+$pkg_cmd_name = "delta"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\delta.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\delta-v$Env:WEBI_VERSION\bin\delta.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\delta-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\delta-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | out-null
+$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    # useragent -A was causing download to fail at 1kb
+    echo "Downloading delta from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd"))
+{
+    echo "Installing delta"
+
+    # TODO: create package-specific temp directory
+    # Enter tmp
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft
+        Remove-Item -Path ".\delta-v*" -Recurse -ErrorAction Ignore
+        Remove-Item -Path ".\delta.exe" -Recurse -ErrorAction Ignore
+
+        # Unpack archive file into this temporary directory
+        # Windows BSD-tar handles zip. Imagine that.
+        echo "Unpacking $pkg_download"
+        & tar xf "$pkg_download"
+
+        # Settle unpacked archive into place
+        echo "Install Location: $pkg_src_cmd"
+        New-Item "$pkg_src_bin" -ItemType Directory -Force | out-null
+        Move-Item -Path ".\delta-*\delta.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | out-null
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/delta/install.sh b/delta/install.sh
new file mode 100644 (file)
index 0000000..748143a
--- /dev/null
@@ -0,0 +1,44 @@
+#!/bin/bash
+set -e
+set -u
+
+function __init_delta() {
+
+
+    #################
+    # Install delta #
+    #################
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="delta"
+
+    pkg_dst_cmd="$HOME/.local/bin/delta"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/delta-v$WEBI_VERSION/bin/delta"
+    pkg_src_dir="$HOME/.local/opt/delta-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    # pkg_install must be defined by every package
+    pkg_install() {
+        # ~/.local/opt/delta-v0.99.9/bin
+        mkdir -p "$(dirname $pkg_src_cmd)"
+
+        # mv ./delta-*/delta ~/.local/opt/delta-v0.99.9/bin/delta
+        mv ./delta-*/delta "$pkg_src_cmd"
+    }
+
+    # pkg_get_current_version is recommended, but not required
+    pkg_get_current_version() {
+        # 'delta --version' has output in this format:
+        #       delta 0.9.2
+        # This trims it down to just the version number:
+        #       0.9.2
+        delta --version 2> /dev/null |
+            head -n 1 |
+            cut -d ' ' -f 2
+    }
+
+}
+
+__init_delta
diff --git a/delta/releases.js b/delta/releases.js
new file mode 100644 (file)
index 0000000..47c16ac
--- /dev/null
@@ -0,0 +1,20 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'dandavison';
+var repo = 'delta';
+
+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);
+    // just select the first 15 for demonstration
+    all.releases = all.releases.slice(0, 15);
+    console.info(JSON.stringify(all, null, 2));
+  });
+}
index 43d37689eab1eeef6479f2f291605d4cd4d4ef6e..3d55469f7fb8faed14ffda1d3eb32922b96503a1 100644 (file)
@@ -14,6 +14,7 @@ function __rmrf_local() {
             chromedriver \
             comrak \
             curlie \
+            delta \
             deno \
             dotenv \
             dotenv-linter \
@@ -103,6 +104,7 @@ function __rmrf_local() {
             chromedriver \
             comrak \
             curlie \
+            delta \
             deno \
             dotenv \
             dotenv-linter \
@@ -196,6 +198,7 @@ function __test() {
         chromedriver \
         comrak \
         curlie \
+        delta \
         deno \
         dotenv \
         dotenv-linter \