GithubHelp home page GithubHelp logo

abhimanyu003 / sttr Goto Github PK

View Code? Open in Web Editor NEW
896.0 8.0 31.0 7.24 MB

cross-platform, cli app to perform various operations on string

License: MIT License

Go 95.40% Shell 4.60%
string transform cli-app cli productivity tui go tui-app json encryption-decryption

sttr's Introduction

sttr

sttr

Website | Install | Getting Started | CLI Reference | Source Code

sttr is command line software that allows you to quickly run various transformation operations on the string.

// With input prompt
sttr

// Direct input
sttr md5 "Hello World"

// File input
sttr md5 file.text
sttr base64-encode image.jpg

// Reading from different processor like cat, curl, printf etc..
echo "Hello World" | sttr md5
cat file.txt | sttr md5

// Writing output to a file
sttr yaml-json file.yaml > file-output.json

🎥 Demo

sttr demo

🔋 Installation

Quick install

You can run the below curl to install it somewhere in your PATH for easy use. Ideally it will be installed at ./bin folder

curl -sfL https://raw.githubusercontent.com/abhimanyu003/sttr/main/install.sh | sh

Webi

macOS / Linux

curl -sS https://webi.sh/sttr | sh

Windows

curl.exe https://webi.ms/sttr | powershell

See here

Homebrew

If you are on macOS and using Homebrew, you can install sttr with the following:

brew tap abhimanyu003/sttr
brew install sttr

Snap

sudo snap install sttr

Arch Linux

yay -S sttr-bin

Scoop

scoop bucket add sttr https://github.com/abhimanyu003/scoop-bucket.git
scoop install sttr

Go

go install github.com/abhimanyu003/sttr@latest

Manually

Download the pre-compiled binaries from the Release! page and copy them to the desired location.

📚 Guide

  • After installation simply run sttr command.
// 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.
sttr -h

// Example
sttr zeropad -h
sttr md5 -h
  • Working with files input.
sttr {command-name} {filename}

sttr base64-encode image.jpg
sttr md5 file.txt
sttr md-html Readme.md
  • Writing output to file.
sttr yaml-json file.yaml > file-output.json
  • Taking input from other command.
curl https: //jsonplaceholder.typicode.com/users | sttr json-yaml
  • Chaining the different processor.
sttr md5 hello | sttr base64-encode

echo "Hello World" | sttr base64-encode | sttr md5

💥 Supported Operations

Encode/Decode

  • ascii85-encode - Encode your text to Ascii85
  • ascii85-decode - Decode your Ascii85 text
  • base32-decode - Decode your Base32 text
  • base32-encode - Encode your text to Base32
  • base64-decode - Decode your Base64 text
  • base64-encode - Encode your text to Base64
  • base85-encode - Encode your text to Base85
  • base85-decode - Decode your Base85 text
  • base64url-decode - Decode your Base64 URL
  • base64url-encode - Encode your text to URL
  • html-decode - Unescape your HTML
  • html-encode - Escape your HTML
  • rot13-encode - Encode your text to ROT13
  • url-decode - Decode URL entities
  • url-encode - Encode URL entities

Hash

  • bcrypt - Get the bcrypt hash of your text
  • md5 - Get the MD5 checksum of your text
  • sha1 - Get the SHA1 checksum of your text
  • sha256 - Get the SHA256 checksum of your text
  • sha512 - Get the SHA512 checksum of your text

String

  • camel - Transform your text to CamelCase
  • kebab - Transform your text to kebab-case
  • lower - Transform your text to lower case
  • reverse - Reverse Text ( txeT esreveR )
  • slug - Transform your text to slug-case
  • snake - Transform your text to snake_case
  • title - Transform your text to Title Case
  • upper - Transform your text to UPPER CASE

Lines

  • count-lines - Count the number of lines in your text
  • reverse-lines - Reverse lines
  • shuffle-lines - Shuffle lines randomly
  • sort-lines - Sort lines alphabetically
  • unique-lines - Get unique lines from list

Spaces

  • remove-spaces - Remove all spaces + new lines
  • remove-newlines - Remove all new lines

Count

  • count-chars - Find the length of your text (including spaces)
  • count-lines - Count the number of lines in your text
  • count-words - Count the number of words in your text

RGB/Hex

  • hex-rgb - Convert a #hex-color code to RGB
  • hex-encode - Encode your text Hex
  • hex-decode - Convert Hexadecimal to String

JSON

  • json - Format your text as JSON
  • json-escape - JSON Escape
  • json-unescape - JSON Unescape
  • json-yaml - Convert JSON to YAML text
  • json-msgpack - Convert JSON to MSGPACK
  • msgpack-json - Convert MSGPACK to JSON

YAML

  • yaml-json - Convert YAML to JSON text

Markdown

  • markdown-html - Convert Markdown to HTML

Extract

  • extract-emails - Extract emails from given text
  • extract-ip - Extract IPv4 and IPv6 from your text
  • extract-urls - Extract URLs your text ( we don't do ping check )

Other

  • escape-quotes - escape single and double quotes from your text
  • completion - generate the autocompletion script for the specified shell
  • interactive - Use sttr in interactive mode
  • version - Print the version of sttr
  • zeropad - Pad a number with zeros
  • and adding more...

Featured On

These are the few locations where sttr was highlighted, many thanks to all of you. Please feel free to add any blogs/videos you may have made that discuss sttr to the list.

Contribution

This project welcomes your PR and issues. For example, refactoring, adding features, correcting English, etc.

A quick development guide can be found on. Developer-Guides wiki page.

If you need any help, you can contact me on Twitter.

Thanks to all the people who already contributed!

License

MIT

sttr's People

Contributors

abhimanyu003 avatar caarlos0 avatar ccoveille avatar fieu avatar gebes avatar huangnauh avatar mattn avatar meowgorithm avatar rasa avatar rverst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sttr's Issues

enhancement: sub command usage hints - single arg or ctrl+d

single string arg

I can see why it should only accept a single string for many of these commands, but it would be nice to update the help message to show that.

sttr snake Hello World!
Error: accepts at most 1 arg(s), received 2
Usage:
  sttr snake [flags] [string] <===========

Flags:
  -h, --help   help for snake
sttr snake 'Hello World!'
hello_world!

ctrl+d

Likewise, it would be nice if either the same double-empty-newline rule applied for stdin input, or if a message about Ctrl ⌃ + d was printed.

sttr snake
Hello World!





<ctrl+d>
hello_world!
sttr snake
Press <ctrl+d> to end <=========
Hello World!
hello_world!

Problem with hex-encode/hex-decode with "bigger" streams

Hi there,

Maybe it's not a bug or just undocumented or it has to do with linux STDIN-buffering
I have following problem with hex-encode and hex-decode using pipes.

user@host:~/tests$ sttr version
0.2.21

## OK case
## 31 kByte File - everything is ok

user@host:~/tests$ dd if=/dev/random of=random_file.bin bs=1k count=31
31+0 records in
31+0 records out
31744 bytes (32 kB, 31 KiB) copied, 0.00068615 s, 46.3 MB/s


user@host:~/tests$ sttr hex-encode random_file.bin | sttr hex-decode > copy.bin

## Error case
## 32 kByte File - error occurs
                                          
user@host:~/tests$ dd if=/dev/random of=random_file.bin bs=1k count=32
32+0 records in
32+0 records out
32768 bytes (33 kB, 32 KiB) copied, 0.00306848 s, 10.7 MB/s


user@host:~/tests$ sttr hex-encode random_file.bin | sttr hex-decode > copy.bin
Error: encoding/hex: invalid byte: U+000A
Usage:
  sttr hex-decode [string] [flags]

Aliases:
  hex-decode, hex-dec, hexadecimal-decode

Flags:
  -h, --help   help for hex-decode

## same file decode using a temp-file - no error

user@host:~/tests$ sttr hex-encode random_file.bin > temp.hex                  
user@host:~/tests$ sttr hex-decode temp.hex > copy.bin

suggestion: random, uuid, and ulid

This may be outside the scope of this project but I'd love to have something for quick and dirty development that:

  • allows me to generate random data (and then encode it to base64 or whatever)
  • can encode as uuid (noting that 8+ bits are non-random a 4 for v4 and a high order bit or two later on)
  • and ULID (this encodes time data and random data for sortable, distributable unique ids)

parsing cli tables

Hello, Abhimanyu. Awesome tool.

I used eat before and I want to switch to sttr, because of more general use cases covered by it, and because it's a single binary cli. Checks all the boxes.

What I do a lot with eat is parsing standard CLI tables like ps or docker images:

$ ps | eat

[
  {
    "PID": "5424",
    "TTY": "pts/1",
    "TIME": "00:00:00",
    "CMD": "fish"
  },
  {
    "PID": "6183",
    "TTY": "pts/1",
    "TIME": "00:00:00",
    "CMD": "ps"
  },
  {
    "PID": "6184",
    "TTY": "pts/1",
    "TIME": "00:00:00",
    "CMD": "node"
  },
  {
    "PID": "6185",
    "TTY": "pts/1",
    "TIME": "00:00:00",
    "CMD": "xclipm"
  }
]

I use this as a preprocessing step before manipulating data with something like jq or fx

Actually, I implemented this in eat. Code is super easy, but it works.
antonmedv/eat@0c2bec8#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346R79-R81

Maybe you could look into it.

command bcrypt ignoring rounds-parameter

I'm using version 0.2.20

It seems the bcrypt subcommand ignores the "Number of rounds"-parameter and uses always it's default value (=10)


user@host:~$ bin/sttr version
0.2.20

user@host:~$ time echo foobar | bin/sttr bcrypt 
$2a$10$HPs11TyDOG9iXxghmQF/qeLbIkqlsl5FmHIqe7GhJzmEs9lsH2lHy
real	0m0,121s
user	0m0,110s
sys	0m0,019s
user@host:~$ time echo foobar | bin/sttr bcrypt -r 12
$2a$10$RpRFWm9NGNe2/usl.1LYZuVmDVK.0xuAI0kvCCHE0PN.IT8K3jRK.
real	0m0,130s
user	0m0,112s
sys	0m0,026s

user@host:~$ bin/sttr help bcrypt
Get the Bcrypt hash of your text

Usage:
  sttr bcrypt [string] [flags]

Aliases:
  bcrypt, bcrypt-hash

Flags:
  -h, --help                    help for bcrypt
  -r, --number-of-rounds uint   Number of rounds (default 10)


enhancement: show sub command hints in menu

Current:

   Ascii85 / Base85 Decoding
   Decode your text to Ascii85 ( Base85 ) text

   Ascii85 / Base85 Encoding
   Encode your text to Ascii85 ( Base85 )

   Base32 Decode
   Decode your base32 text

   Base32 Encoding
   Encode your text to Base32

   Base64 Decode
   Decode your base64 text

   Base64 Encoding
   Encode your text to Base64

Desired:

   Ascii85 / Base85 Decoding (ascii85-decode)
   Decode your text to Ascii85 ( Base85 ) text

   Ascii85 / Base85 Encoding (ascii85-encode)
   Encode your text to Ascii85 ( Base85 )

   Base32 Decode (base32-decode)
   Decode your base32 text

   ...

Or something like that.

Error when attempting to install the application through curl

Ran the command curl -sfL https://raw.githubusercontent.com/abhimanyu003/sttr/main/install.sh | sh from the bin directory,

install: cannot create regular file '/usr/local/bin/sttr': Permission denied

Tried with sudo too.

What's the cause of the error and how to rectify it?

support crockford base32, Base-X base58, base62

The use case for Base32 is to provide something that's easier to write down and re-enter correctly - otherwise you'd always use base64. Base-N Base32 does not accomplish this. Crockford Base32 does (and another one I'm forgetting at the moment).

For this reason, the Base-N version of Base32 is rarely used. Almost always (survey other base32 libraries) it's Crockford Base32, which ensures that there are no ambiguous combinations - such as 0 and O, etc.

A few other bases that are popular in certain niches:

  • Crockford Base32
  • Base-X Base58 is used for cryptocurrency addresses and follows the same principles as Crockford Base32 in regards to character selection, but is also generic to arbitrary bit-widths (due to Base-X implementation)
    • Base58Check (the standard for how this is used in practice: Base58(Magic Bytes (Version) + Data + Checksum)
  • Base62 is used for prefixed & checksummed access tokens (e.g. GitHub, npm, Digital Ocean, etc)
    • Base62Check an informal name for actual way tokens are generated: Prefix + Base62(Entropy + Checksum)

Support for macOS with M1 chips.

Currently unable to follow the installation guide for installation on macOS 12.1 with Apple M1 because of the following error:

Error: Invalid formula: /opt/homebrew/Library/Taps/abhimanyu003/homebrew-sttr/Formula/sttr.rb
formulae require at least a URL
Error: Cannot tap abhimanyu003/sttr: invalid syntax in tap!

I suppose the error stems from this part in the formulae which seems to support only Intel chips?:

on_macos do
    if Hardware::CPU.intel?
      url "https://github.com/abhimanyu003/sttr/releases/download/v0.2.11/sttr_0.2.11_darwin_amd64.tar.gz"
      sha256 "37f720259894838ccbebf2d2491305f05be47daf3f2a509b2f0b5b06a3f1811f"

      def install
        bin.install "sttr"
      end
    end
  end

[FEATURE-REQUEST] Add epoch-human | human-epoch (Unix TimeStamps)

Hi, thanks for this.

It would be nice to implement a unix/epoch TimeStamp to Human date encoder/decoder

An example:

# You can ofc choose better cli args than `epoch-human`echo "1710152465311" | sttr epoch-human
2024-03-11T10:21:05
#The format is %Y-%m-%dT%H:%M:%S but you could pick something more readable

Add support for regular expressions

I think it would be interesting to add support for regular expressions. It looks like it already supports email/ip parsing so it doesn't look like a complex feature.

Nice work by the way!

Broken due to processor sort line change

@abhimanyu003

go/pkg/mod/github.com/abhimanyu003/[email protected]/cmd/processor_sort-lines.go:40:25

This just happened in the last hour when I was repulling it into a new project.

This version works: go install github.com/abhimanyu003/sttr@e5600168e954fbe603cba134226874b1e81c297a, everything after this fails.

Suggest that might be a good github action for post-merge to flag an install failure

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.