str : An interactive string manipulation environment Copyright (C) 2025 Garrett Mills ---------------------------------------- Input / Output ---------------------------------------- copy Copy the current string to the clipboard. (Requires wl-clipboard.) paste Paste the contents of the clipboard to replace the current string. (Requires wl-clipboard.) infile Replace the current string with the contents of . outfile Write the current string as the contents of . edit Open the current string in EDITOR. history Print the undo/redo history runfile Parse a file as a set of str commands and execute them. from Replace the current string with the contents of the variable. to Store the current string contents into the variable. ---------------------------------------- String Manipulation ---------------------------------------- indent [] Indent the string with the specified number of spaces or tabs. Default is a single standard indentation level. trim [] [] Remove instances of the given character from either the start/end or both sides of the string. Default is to trim whitespace from both ends. quote [] Surround the current string in the given quote character. Default is to use the current "quote" setting, which defaults to a single-quote. unquote [] Try to strip surrounding quotes of the given character from the string. Will only proceed if the string has the quote mark on both ends. Default is to try common quote schemes (single/double quotes, backtick). enclose [] Wrap the string in the given character. Tries to match pairs when possible. Example: Using `(` will wrap with a closing `)` Default is to wrap with parentheses. prefix Prepend to the current string. suffix Append to the current string. split [] Split the current string using the given separator, and rejoin it using the given separator. Default is to rejoin on newlines. lines [] [] Like `split`, but defaults to splitting on chunks of whitespace. join [] Join separate lines in the string using the given separator. replace Replace all instances of with . lsub [] Replace the current string with a substring from the left, starting at . Optionally, limit to characters. rsub [] Like `lsub`, but works on the string from right-to-left. reparse Assuming the string is a valid expression, parse it and convert it to encoding. Example: reparse json php ---------------------------------------- Advanced Manipulation ---------------------------------------- line Runs the given command for every line in the string (separated by \n). word Runs the given command for every word in the string (separated by whitespace). contains Check if the current string contains . If not, replace it with an empty string. on Run the given command on the nth line or word. Example: on line 2 prefix + map [to ] [by ] Map the subject line-wise or word-wise for the given range. Default is to map until the end of the string if `to` is not provided, and to apply to every single line/word. Example: map line 1 to 5 by 2 prefix + over Apply a command to the given and save it back in . Example: over $a line prefix + ---------------------------------------- State Management ---------------------------------------- show Print out the current string. clear Replace the current string with an empty string. undo [] Undo the past operations on the string. Defaults to a single operation. redo Redo the past operations that were undone. Defaults to a single operation. save [] Store the current state of the interpreter to the given file path. Defaults to ~/.str.json load [] Restore a saved state from the given file path to the interpreter. Defaults to ~/.str.json exit Exit the interpreter. set [] Change the given interpreter to the given . If no value is given, will reset it back to the default. Supported settings: quote (default: ') - What character is used to parse quoted strings. Also sets the default for the `quote` command. escape (default: \) - What character is used to parse escape sequences. session (default: ~/.str.json) - Default file used by `save`/`load` commands. debug (default: 0) - Set to 1 to enable debug mode terminator (default: \n) - What character is used to parse sequential commands. Example: `set terminator ;` will begin parsing commands separated by a ; instead of when enter is pressed. ---------------------------------------- Variables ---------------------------------------- Define/set a variable $varname = Example: $foo = example $baz = 'another example' Use variables as arguments to commands Example: line prefix $foo Use quotes to escape variable names Example: line prefix '$foo' vars Print the value of all defined variables varUnset Unset a variable. Example: varUnset $foo ---------------------------------------- Functions ---------------------------------------- function Start a function definition. Subsequent commands will be parsed as part of the function body until `end function` is encountered. Functions may not be nested. end End a block of the given type. Only supports `function` currently. call Execute the given function. Example: ``` function format_sql_in_clause line lines line trim trim line quote " join , enclose ( end function ```