Add zoxide
authorAjeet D'Souza <98ajeet@gmail.com>
Fri, 9 Apr 2021 05:52:50 +0000 (11:22 +0530)
committerAJ ONeal <aj@therootcompany.com>
Tue, 15 Jun 2021 05:27:16 +0000 (05:27 +0000)
zoxide/README.md [new file with mode: 0644]
zoxide/install.ps1 [new file with mode: 0644]
zoxide/install.sh [new file with mode: 0644]
zoxide/releases.js [new file with mode: 0644]

diff --git a/zoxide/README.md b/zoxide/README.md
new file mode 100644 (file)
index 0000000..9de855f
--- /dev/null
@@ -0,0 +1,105 @@
+---
+title: zoxide
+homepage: https://github.com/ajeetdsouza/zoxide
+tagline: |
+  zoxide: A smarter cd command.
+---
+
+## Cheat Sheet
+
+`zoxide` is a smarter `cd` command for your terminal. It keeps track of the
+directories you visit, so that you can switch to them using just a few
+keystrokes.
+
+![tutorial](https://github.com/ajeetdsouza/zoxide/raw/main/contrib/tutorial.webp)
+
+## Usage
+
+```sh
+z foo       # cd to highest ranked directory matching foo
+z foo bar   # cd to highest ranked directory matching foo and bar
+
+z foo/      # can also cd into actual directories
+z ..        # cd into parent directory
+z -         # cd into previous directory
+
+zi foo      # cd with interactive selection (requires fzf)
+```
+
+## Add zoxide to your shell
+
+To use zoxide, it needs to be first initialized on your shell:
+
+### bash
+
+Add the following line to your configuration file (usually `~/.bashrc`):
+
+```sh
+eval "$(zoxide init bash)"
+```
+
+### elvish
+
+Add the following line to your configuration file (usually `~/.elvish/rc.elv`):
+
+```sh
+eval $(zoxide init elvish | slurp)
+```
+
+### fish
+
+Add the following line to your configuration file (usually `~/.config/fish/config.fish`):
+
+```fish
+zoxide init fish | source
+```
+
+### nushell
+
+Initialize zoxide's Nushell script:
+
+```sh
+zoxide init nushell --hook prompt | save ~/.zoxide.nu
+```
+
+Then, in your Nushell configuration file:
+
+- Prepend `__zoxide_hook;` to the `prompt` variable.
+- Add the following lines to the `startup` variable:
+  - `zoxide init nushell --hook prompt | save ~/.zoxide.nu`
+  - `source ~/.zoxide.nu`
+
+### powershell
+
+Add the following line to your profile:
+
+```powershell
+Invoke-Expression (& {
+    $hook = if ($PSVersionTable.PSVersion.Major -lt 6) { 'prompt' } else { 'pwd' }
+    (zoxide init --hook $hook powershell) -join "`n"
+})
+```
+
+### xonsh
+
+Add the following line to your configuration file (usually `~/.xonshrc`):
+
+```python
+execx($(zoxide init xonsh), 'exec', __xonsh__.ctx, filename='zoxide')
+```
+
+### zsh
+
+Add the following line to your configuration file (usually `~/.zshrc`):
+
+```sh
+eval "$(zoxide init zsh)"
+```
+
+### Any POSIX shell
+
+Add the following line to your configuration file:
+
+```sh
+eval "$(zoxide init posix --hook prompt)"
+```
diff --git a/zoxide/install.ps1 b/zoxide/install.ps1
new file mode 100644 (file)
index 0000000..01f93eb
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env pwsh
+
+##################
+# Install zoxide #
+##################
+
+# Every package should define these variables
+$pkg_cmd_name = "zoxide"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\zoxide.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\zoxide-v$Env:WEBI_VERSION\bin\zoxide.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\zoxide-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\zoxide-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) {
+    # TODO: arch detection
+    Write-Output "Downloading zoxide from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & Move-Item "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd")) {
+    Write-Output "Installing zoxide"
+
+    # Enter tmp
+    Push-Location ".local\tmp"
+
+    # Remove any leftover tmp cruft
+    Remove-Item -Path ".\zoxide*" -Recurse -ErrorAction Ignore
+
+    # Unpack archive
+    Write-Output "Unpacking $pkg_download"
+    & tar xf "$pkg_download"
+
+    # Settle unpacked archive into place
+    Write-Output "Install Location: $pkg_src_cmd"
+    New-Item "$pkg_src_bin" -ItemType Directory -Force
+    Move-Item -Path "zoxide.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    Pop-Location
+}
+
+Write-Output "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/zoxide/install.sh b/zoxide/install.sh
new file mode 100644 (file)
index 0000000..33127b3
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+function __init_zoxide() {
+    set -e
+    set -u
+
+    ##################
+    # Install zoxide #
+    ##################
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="zoxide"
+
+    pkg_dst_cmd="$HOME/.local/bin/zoxide"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/zoxide-v$WEBI_VERSION/bin/zoxide"
+    pkg_src_dir="$HOME/.local/opt/zoxide-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    # pkg_install must be defined by every package
+    pkg_install() {
+        # mkdir -p "~/.local/opt/zoxide-v0.99.9/bin"
+        mkdir -p "$(dirname "$pkg_src_cmd")"
+
+        # mv ./zoxide-*/zoxide "~/.local/opt/zoxide-v0.99.9/bin/zoxide"
+        mv ./zoxide-*/zoxide "$pkg_src_cmd"
+    }
+
+    # pkg_get_current_version is recommended, but (soon) not required
+    pkg_get_current_version() {
+        # 'zoxide --version' has output in this format:
+        #       zoxide v0.5.0-31-g8452961
+        # This trims it down to just the version number:
+        #       0.5.0
+        zoxide --version 2>/dev/null | head -n 1 | cut -d '-' -f 1 | cut -b '9-'
+    }
+
+}
+
+__init_zoxide
diff --git a/zoxide/releases.js b/zoxide/releases.js
new file mode 100644 (file)
index 0000000..27d0ad2
--- /dev/null
@@ -0,0 +1,20 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'ajeetdsouza';
+var repo = 'zoxide';
+
+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 5 for demonstration
+    all.releases = all.releases.slice(0, 5);
+    console.info(JSON.stringify(all, null, 2));
+  });
+}