CLI string manipulation utility
bastr
takes stdin
content and provide functions to modify the content. It is
meant as an alternative to using sed
, tr
, awk
and other utilities for
simple string and array manipulation.
The unix utilities are probably more performant and more powerful - this utility only exists because it is easier and more semantic to use.
Scripts in bastr
are sequences of predefined actions. To create a new script,
use the bs script:add
command and follow along with the prompts
To list your scripts, use bs script:list
.
To apply a script, use (someprocess) | bs script [scriptname]
$ echo -n "capitalize all words" | bs split " " | bs capitalize | bs join " "
>>> Capitalize All Words
$ ps | bs lineArray | bs findItem bash | bs getItem 0 | bs split -r "\s+" | bs getItem 3
>>> /usr/local/bin/bash
$ npm install -g @cthru/bastr
$ (someProcess) | bs COMMAND
running command...
$ bs (-v|--version|version)
@cthru/bastr/0.3.3 darwin-x64 node-v10.10.0
$ bs --help [COMMAND]
USAGE
$ (someProcess) | bs COMMAND
...
(someProcess) | bs capitalize
(someProcess) | bs findItem TERM
(someProcess) | bs getItem [INDEX]
(someProcess) | bs help [COMMAND]
(someProcess) | bs join [GLUE]
(someProcess) | bs replace SEARCHTERM REPLACETERM
(someProcess) | bs script [SCRIPTNAME]
bs script:add
bs script:delete SCRIPTNAME
bs script:list
(someProcess) | bs select INDEXES
(someProcess) | bs split DELIMITER
(someProcess) | bs toArray
(someProcess) | bs trim TRIMCHAR
Capitalizes string or [string]
USAGE
$ (someProcess) | bs capitalize
OPTIONS
-a, --all Target all letters, not just first
-d, --decapitalize De-Capitalize instead
ALIASES
$ (someProcess) | bs cap
See code: src/commands/capitalize.js
Get an Item from an array, or a character from a string
USAGE
$ (someProcess) | bs findItem TERM
ARGUMENTS
TERM The term to search for
ALIASES
$ (someProcess) | bs search
$ (someProcess) | bs filter
$ (someProcess) | bs find
See code: src/commands/findItem.js
Get an Item from an array, or a character from a string
USAGE
$ (someProcess) | bs getItem [INDEX]
ARGUMENTS
INDEX Zero-based index for the array item to select
ALIASES
$ (someProcess) | bs get
See code: src/commands/getItem.js
display help for bs
USAGE
$ (someProcess) | bs help [COMMAND]
ARGUMENTS
COMMAND command to show help for
OPTIONS
--all see all commands in CLI
See code: @oclif/plugin-help
Join multiple array elements together
USAGE
$ (someProcess) | bs join [GLUE]
ARGUMENTS
GLUE [default: ] Glue to use for join
See code: src/commands/join.js
Replaces Values in strings or arrays
USAGE
$ (someProcess) | bs replace SEARCHTERM REPLACETERM
ARGUMENTS
SEARCHTERM The term to search for
REPLACETERM The term to replace searchTerm with
OPTIONS
-c, --case-sensitive match only case sensitive occurances
-f, --first only replace the first occurance
-r, --regex use regular expression in search term
See code: src/commands/replace.js
Apply a script to bash output
USAGE
$ (someProcess) | bs script [SCRIPTNAME]
ARGUMENTS
SCRIPTNAME The script you want to apply
OPTIONS
-s, --show-cli-equivalent Show what this script would look like on bash
See code: src/commands/script/index.js
Add a new Script
USAGE
$ bs script:add
See code: src/commands/script/add.js
Delete a named script
USAGE
$ bs script:delete SCRIPTNAME
ARGUMENTS
SCRIPTNAME delete the `scriptName` script
See code: src/commands/script/delete.js
List your Scripts
USAGE
$ bs script:list
See code: src/commands/script/list.js
Selects array items by index list
USAGE
$ (someProcess) | bs select INDEXES
ARGUMENTS
INDEXES A list of indexes delimited by comma. Eg. '1,2,3' and '-3,5,6-'
See code: src/commands/select.js
Split a string into an array based on a delimiter
USAGE
$ (someProcess) | bs split DELIMITER
ARGUMENTS
DELIMITER [default: ] Delimiter to use as split point
OPTIONS
-r, --regex Delimiter is regex
See code: src/commands/split.js
Split multiline string into array of lines
USAGE
$ (someProcess) | bs toArray
ALIASES
$ (someProcess) | bs lineSplit
$ (someProcess) | bs line2array
$ (someProcess) | bs lineArray
See code: src/commands/toArray.js
Trim a string or an array of strings
USAGE
$ (someProcess) | bs trim TRIMCHAR
ARGUMENTS
TRIMCHAR [default: ] The character to trim
OPTIONS
-s, --sides=left|right|both [default: both] Configure which side(s) to trim
See code: src/commands/trim.js