feat: add sttr

This commit is contained in:
Abhimanyu Sharma
2023-03-07 11:17:41 +00:00
committed by AJ ONeal
parent 6025fb3b8e
commit 51c7c20c59
4 changed files with 184 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
---
title: sttr
homepage: https://github.com/abhimanyu003/sttr
tagline: |
sttr: A cross-platform, cli app to perform various operations on string
---
To update or switch versions, run `webi sttr@stable` (or `@v0.2.16` etc).
## Cheat Sheet
> `sttr` makes it easy to perform various operations on string.
## Basic Usage
* After installation simply run `sttr` command.
```sh
// For interactive menu
sttr
// Provide your input
// Press two enter to open operation menu
// Press `/` to filter various operations.
// Can also press UP-Down arrows select various operations.
```
* Working with help.
```sh
sttr -h
// Example
sttr zeropad -h
sttr md5 -h
```
* Working with files input.
```sh
sttr {command-name} {filename}
sttr base64-encode image.jpg
sttr md5 file.txt
sttr md-html Readme.md
```
* Writing output to file.
```sh
sttr yaml-json file.yaml > file-output.json
```
* Taking input from other command.
```sh
curl https: //jsonplaceholder.typicode.com/users | sttr json-yaml
```
* Chaining the different processor.
```sh
sttr md5 hello | sttr base64-encode
echo "Hello World" | sttr base64-encode | sttr md5
```
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env pwsh
######################
# Install sttr #
######################
# Every package should define these variables
$pkg_cmd_name = "sttr"
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\sttr.exe"
$pkg_dst = "$pkg_dst_cmd"
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\sttr-v$Env:WEBI_VERSION\bin\sttr.exe"
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\sttr-v$Env:WEBI_VERSION\bin"
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\sttr-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"))
{
echo "Downloading sttr 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 sttr"
# TODO: create package-specific temp directory
# Enter tmp
pushd .local\tmp
# Remove any leftover tmp cruft
Remove-Item -Path ".\sttr-v*" -Recurse -ErrorAction Ignore
Remove-Item -Path ".\sttr.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 ".\sttr.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
+41
View File
@@ -0,0 +1,41 @@
#!/bin/sh
set -e
set -u
__init_sttr() {
######################
# Install sttr #
######################
# Every package should define these 6 variables
pkg_cmd_name="sttr"
pkg_dst_cmd="$HOME/.local/bin/sttr"
pkg_dst="$pkg_dst_cmd"
pkg_src_cmd="$HOME/.local/opt/sttr-v$WEBI_VERSION/bin/sttr"
pkg_src_dir="$HOME/.local/opt/sttr-v$WEBI_VERSION"
pkg_src="$pkg_src_cmd"
# pkg_install must be defined by every package
pkg_install() {
# ~/.local/opt/sttr-v0.99.9/bin
mkdir -p "$(dirname "$pkg_src_cmd")"
# mv ./sttr-*/sttr ~/.local/opt/sttr-v0.99.9/bin/sttr
mv ./sttr "$pkg_src_cmd"
}
# pkg_get_current_version is recommended, but (soon) not required
pkg_get_current_version() {
# 'sttr --version' has output in this format:
# sttr 0.99.9 (rev abcdef0123)
# This trims it down to just the version number:
# 0.99.9
sttr version 2> /dev/null | head -n 1 | cut -d ' ' -f 2
}
}
__init_sttr
+20
View File
@@ -0,0 +1,20 @@
'use strict';
var github = require('../_common/github.js');
var owner = 'abhimanyu003';
var repo = 'sttr';
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));
});
}