https://github.com/daniel-beard/psst-hs
https://github.com/daniel-beard/psst-hs
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/daniel-beard/psst-hs
- Owner: daniel-beard
- License: bsd-3-clause
- Created: 2021-11-18T02:03:09.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-01-22T22:47:25.000Z (over 2 years ago)
- Last Synced: 2025-03-29T23:41:32.961Z (about 1 year ago)
- Language: Haskell
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# psst-hs
PaSteboard String Tranform tool - Haskell edition.
There are two ways to get data into this tool, `cat` something to it, or just run it and it will take the value in your pasteboard.
There are a lot of tools for transforming strings on the CLI, but the most useful tool is the one you remember how to use.
This tool aims to be useful, but unsurprising in behavior.
## Concepts
- This utility transforms strings with a typed dsl.
- The syntax is inspired by Julialang's pipeline operator `|>`
- This utility was born as a reimplentation of [daniel-beard/psst](https://github.com/daniel-beard/psst) with the following:
- Less syntax (for now), 'command' based
- Better documentation
- A typed representation
- Fast start time (Julia takes a while to warm up)
- Easy to add new commands
- Better error messages
- Interpreted, with ability to output partial results in case of errors
## Examples
```shell
echo 'hello world' | psst-hs 'words |> uppercase |> take(2) |> base64 |> unbase64'
["HE","WO"]
```
## Types and Examples
There are currently only a few types in `psst-hs`:
```
- VString
- VStringList
- VInt
- VBool
- VError
```
Many commands work the same across `VString` and `VStringList` types. The function used in the `VString` type is just mapped across the list.
## Commands
Commands are chained by the pipeline operator `|>`. Each command opts in to a particular input type.
### VString
base64 -> VString
- Description: Base64 encoding of a VString
- Example:
```
echo 'hello world' | psst-hs 'base64'
> aGVsbG8gd29ybGQK
```
head -> VString
- Description: Take the first value
- Example:
```
echo 'hello world' | psst-hs 'head'
> h
```
length -> VInt
- Description: Return a `VInt` representing the length of a `VString`
- Example:
```
echo 'hi' | psst-hs 'length'
> 2
```
lowercase -> VString
- Description: Return a `VString` with all characters set to lowercase
- Example:
```
echo 'HELLO WORLD' | psst-hs 'lowercase'
> "hello world"
```
match -> VStringList
- Description: Return all matches for a given regex
- Example:
```
echo 'hello world' | psst-hs 'match("[a-z]+")'
["hello", "world"]
```
matches -> VBool
- Description: Return a `VBool` indicating if input matches a regex
- Example:
```
echo "hello world" | psst-hs 'matches("\\w+")'
True
```
reverse -> VStringList
- Description: Return a `VString` with the characters reversed from their original order
- Example:
```
echo 'hello world' | psst-hs 'reverse'
> dlrow olleh
```
tail -> VString
- Description: All characters except the first one. Returns a `VString`
- Example:
```
echo 'hello world' | psst-hs 'tail'
> ello world
```
take(Int) -> VString
- Description: Output only the prefix number of characters. Returns a `VString`
- Example:
```
echo 'hello world' | psst-hs 'take(4)'
> hell
```
unbase64 -> VString
- Description: Decode a base64 representation. Returns a `VString`.
- Example:
```
echo 'aGVsbG8gd29ybGQK' | psst-hs 'unbase64'
> hello world
```
uppercase -> VString
- Description: Uppercase the string. Returns a `VString`
- Example:
```
echo 'hello world' | psst-hs 'uppercase'
> HELLO WORLD
```
words -> VStringList
- Description: Split a `VString` into components separated by whitespace. Returns a `VStringList`
- Example:
```
echo 'hello world' | psst-hs 'words'
> ["hello", "world"]
```
-------
### VStringList
base64 -> VStringList
- Description: Maps the `VString` method across a `VStringList`
- Example:
```
echo 'hello world' | psst-hs 'words |> base64'
> ["aGVsbG8=","d29ybGQ="]
```
length -> VInt
- Description: Returns the length of the `VStringList` as `VInt`
- Example:
```
echo 'hello world' | psst-hs 'words |> length'
> 2
```
lowercase -> VStringList
- Description: Maps the `VString` method across a `VStringList`
- Example:
```
echo 'HELLO WORLD' | psst-hs 'words |> lowercase'
> ["hello", "world"]
```
reverse -> VStringList
- Description: Reverse the order of elements within the `VStringList`
- Example:
```
echo 'hello world' | psst-hs 'words |> reverse'
> ["world", "hello"]
```
unbase64 -> VStringList
- Description: Maps the `VString` method across a `VStringList`
- Example:
```
echo 'aGVsbG8= d29ybGQ=' | psst-hs 'words |> unbase64'
> ["hello", "world"]
```
uppercase -> VStringList
- Description: Maps the `VString` method across a `VStringList`
- Example:
```
echo 'hello world' | psst-hs 'words |> uppercase'
> ["HELLO", "WORLD"]
```
tail -> VString
- Description: Returns the last `VString` from a `VStringList`
- Example:
```
echo 'hello world' | psst-hs 'words |> tail'
> ["WORLD"]
```
take(VInt) -> VStringList
- Description: Returns the first n `VString` values from a `VStringList`
- Example:
```
echo '1 2 3 4 5' | psst-hs 'words |> take(4)'
> ["1", "2", "3", "4"]
```
-------
## Building on macOS
```shell
brew install pcre
# For M1s
brew list pcre | grep 'pcre\.h$'
/opt/homebrew/include
ln -s /usr/local/pcre-8.45 /usr/sbin/pcre
ln -s /usr/local/pcre-8.45/include/pcre.h /usr/include/pcre.h
```