stringhorse
Stringhorse is a text manipulation tool that works programmatically but stops short of being a full blown scripting language or regexp handler. You get three text panes. Paste the source text into the left and write your command recipe into the middle. The output will appear on the right.
Commands mostly don't have cutesy or UNIX-y names like sed or grep. You can work out what some commands do from the characters in their name …
- A plus will add something
- A minus will take something away
- An equals will match something
- A pipe (the | symbol) will split the text into pieces
- j commands join things together
- k commands keep something and remove the rest
- s commands swap things
- A < means something will happen to the left of the line or the match
- A > means something will happen to the right of the line or the match
Characters are combined to achieve things …
- k= will keep all the lines that match the text following the command.
- +> will add the text following the command to the right of each line.
Officially on the web at stringhorse.mcglashan.net
All the source code on github at github.com/davidmcglashan/stringhorse (CC0 1.0 Universal)
Commands dealing with string manipulation can support variables: reusable strings that are defined once and used often.
Variables are entered in the variables pane in the form key = value. Keys must not contain spaces or the variable will not work. Values can be any entered text. Definitions must include an equals sign. Everything before the equals sign is the key, and everything after is the value. Both the key and value have any leading and trailing whitespace removed.
To use a variable with a command simply type its name as a parameter, preceded with a $.
Example
If the variables pane contains the following …
find = red replace = green
… then the following command in the recipe pane will replace all instances of red in the input text with green in the output …
ss $find $replace
Patterns are variables that produce different outputs each time they are inserted into a text. Patterns only work with commands that add text to a line.
Patterns are entered in the variables pane in the form key = value under the same constraints as variables. To use a variable as a pattern it should be invoked with a %.
+> %code
Consider the following pattern definition ...
code = {AA}-{1111*}
When %code is encountered in a text-writing recipe command such as s or +> it will be replaced with a string generated from the pattern. Patterns are inserted verbatim except for characters within { and } where A will become a random uppercase letter and 1 will become a random digit. * is replaced by either a letter or a digit at a 50% chance. The pattern above therefore might become GT-8264P or AH-11318
There are a small number of built-in functions that can generate additional useful output.
+> @rng(1,10)
@rng can generate random numbers. The above will generate a random number between 1 and 10 (inclusive) and append it to the end of each line via the +> recipe command.
+> @lorem(5)
@lorem can generate passages of Lorem Ipsum text, according to the number of words required. The above will generate a five word sequence and append it to the end of each line via the +> recipe command. Lower case sequences are produced unless a 'c' character is included in the function paramters e.g. @lorem(5c).
Random Lorem Ipsum words can be produced by including an 'r', e.g. @lorem(3rc) produces a three-word sentence of random words, the first of which is capitalised.
folk = Alice,Bob,Charles,David,Eddie +> @list(folk)
Where a variable is declared as a comma-separated list (see folk above) a random entry from the list can be chosen by the @list command for use in a recipe. The example above appends a random entry from the folk list to the end of each line using the +> command.