From fe73f8758a4079cbd764d616afeb261f9c7f8117 Mon Sep 17 00:00:00 2001 From: ayusHman Date: Fri, 11 Sep 2020 09:15:44 +0530 Subject: [PATCH] add sd --- sd/README.md | 47 +++++++++++++++++++++++++++++++++++++++++ sd/install.ps1 | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ sd/install.sh | 39 ++++++++++++++++++++++++++++++++++ sd/releases.js | 20 ++++++++++++++++++ 4 files changed, 163 insertions(+) create mode 100644 sd/README.md create mode 100644 sd/install.ps1 create mode 100644 sd/install.sh create mode 100644 sd/releases.js diff --git a/sd/README.md b/sd/README.md new file mode 100644 index 0000000..cbbff5b --- /dev/null +++ b/sd/README.md @@ -0,0 +1,47 @@ +--- +title: sd +homepage: https://github.com/chmln/sd +tagline: | + sd is an intuitive find & replace CLI. +--- + + + +### Updating `sd` + +`webi sd@stable` + +Use the `@beta` tag for pre-releases. + + +## Cheat Sheet +> sd is a productive and faster replacement of sed and awk command used for editing files in command line interface,it uses regex syntax +> similar to those used in JavaScript and Python + +## Usage of sd: + +### Replacing Text in a File + +```bash + sd 'original word' 'final word' ./file_to_be_changed +``` + +### Taking out word inside slashes from a given string + +```bash + echo "string output shown /word inside slashes/" | sd '.*(/.*/)' '$1' + /word inside slashes/ +``` + +### Using the string mode (-s) + +```bash + cat exm.txt + here is an @example + + cat exm.txt| sd -s '@' '' + here is an example +``` + + diff --git a/sd/install.ps1 b/sd/install.ps1 new file mode 100644 index 0000000..f68d580 --- /dev/null +++ b/sd/install.ps1 @@ -0,0 +1,57 @@ +#!/usr/bin/env pwsh + +################## +# Install sd # +################## + +# Every package should define these variables +$pkg_cmd_name = "sd" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\sd.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\sd-v$Env:WEBI_VERSION\bin\sd.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\sd-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\sd-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 + echo "Downloading sd from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing sd" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\sd-*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\sd.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" + & dir + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path "b\*\release\sd.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 +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/sd/install.sh b/sd/install.sh new file mode 100644 index 0000000..af2bba1 --- /dev/null +++ b/sd/install.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +{ + set -e + set -u + + ################## + # Install sd # + ################## + + # Every package should define these 6 variables + pkg_cmd_name="sd" + + pkg_dst_cmd="$HOME/.local/bin/sd" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/sd-v$WEBI_VERSION/bin/sd" + pkg_src_dir="$HOME/.local/opt/sd-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # ~/.local/opt/sd-v0.99.9/bin + mkdir -p "$(dirname $pkg_src_cmd)" + # mv ./sd-*/sd "$pkg_src_cmd" + mv sd-* "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'sd --version' has output in this format: + # sd 0.99.9 (rev abcdef0123) + # This trims it down to just the version number: + # 0.99.9 + echo $(sd --version 2>/dev/null | head -n 1 | cut -d ' ' -f 2) + } + + +} diff --git a/sd/releases.js b/sd/releases.js new file mode 100644 index 0000000..3c69083 --- /dev/null +++ b/sd/releases.js @@ -0,0 +1,20 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'chmln'; +var repo = 'sd'; + +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