shell-string
Simple CLI to perform common string operations
Usage
shell-string 0.3.2
Cli for common string operations. Takes input from stdin.
USAGE:
string <SUBCOMMAND>
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
case Transform upper- or lowercase
distinct Output the set of input strings without repetitions, in order
help Prints this message or the help of the given subcommand(s)
length Returns the length the input string
line Pick a single line by linenumber
replace Replace all matching words
reverse Reverse order of lines
split Split up a string by a separator and print the parts on separate lines
substr Extract a part of a given string
template Useful for templating, replace sections of input with the output of a shell command or script
Why does this exists
I'm writing ci pipelines from time to time and manipulating strings, especially templating anything, always is a HUGE pain.
Every coworker has his own style solving a problem and when it comes down to string transformation any solution not written by yourself is sheer unmaintainable.
This is mostly because there are thousands of ways to do the tasks shell-string
does, but this cli makes them very obvious and easy to understand.
More than anything I hated finding some solution for file templating over and over again. I wrote shell-string
to never again have to think about what the best way of templating a file is.
It's always this, period.
Why is shell-string
good for templating files?
Because you practically have no restrictions.
You need to just drop in some environment variables? Easy, just write {{ echo $MY_VAR }}
into the template.
Is complex logic needed? You could write {{ console.log(crazyStuff()) }}
and you're golden. Just execute with --shell=node
You want to use haskell
in your template files? Use haskell!
The string template
command is so powerful, because it doesn't do the heavy lifting itself, like a lot of alternatives do.
Instead it relies on using EVRYTHING, you could use in the terminal. You can specify, how a command get's interpreted, be it by ghci
, python
or sh
(which is the default).
Using string template
you could even set up your very own workflow for templating files. This is especially useful in CI or when configuring a fresh system.
How does that look?
kind: Deployment
metadata:
name: -deployment
labels:
deployed: "{{date}}"
app:
spec:
replicas:
...
image:
...
Per default sh
is used to interpret the command inside {{
and }}
and, if these delimeters don't suite your style, that's okay. You can choose any delimiter you fancy. And you should.
How am using a document as a template?
give you have a document deployment.template.yaml
and you want to derive a file called deployment.yaml
, that's easy. Open a terminal and type
|
which means
cat deployment.template.yaml
: Print the filedeployment.template.yaml
| string template
: The|
means "don't print this in a terminal, pipe it to another programm" and that programm isstring
intemplate
mode.> deployment.yaml
: Write the output of this into a file calleddeployment.yaml
. If the file existed, empty it beforehand.
Installation
Given cargo is installed on your machine execute
To verify your installation worked type string --version
. Given your installation was successful you should see the appropriate version number.
if you want the very latest version, check out this repository locally using
and build and install the code using