From 29d0b6075ede95931cae301d7050d60309e08ff7 Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Fri, 9 Apr 2021 11:22:50 +0530 Subject: [PATCH] Add zoxide --- zoxide/README.md | 105 +++++++++++++++++++++++++++++++++++++++++++++ zoxide/install.ps1 | 52 ++++++++++++++++++++++ zoxide/install.sh | 41 ++++++++++++++++++ zoxide/releases.js | 20 +++++++++ 4 files changed, 218 insertions(+) create mode 100644 zoxide/README.md create mode 100644 zoxide/install.ps1 create mode 100644 zoxide/install.sh create mode 100644 zoxide/releases.js diff --git a/zoxide/README.md b/zoxide/README.md new file mode 100644 index 0000000..9de855f --- /dev/null +++ b/zoxide/README.md @@ -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 index 0000000..01f93eb --- /dev/null +++ b/zoxide/install.ps1 @@ -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 index 0000000..33127b3 --- /dev/null +++ b/zoxide/install.sh @@ -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 index 0000000..27d0ad2 --- /dev/null +++ b/zoxide/releases.js @@ -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)); + }); +} -- 2.25.1