Skip to content

mholtzhausen/bastr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bastr

CLI string manipulation utility

oclif Version Downloads/week License

Description

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.

Advanced Use: Scripts

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]

Examples

$ 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

Usage

$ 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
...

Commands

(someProcess) | bs capitalize

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

(someProcess) | bs findItem TERM

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

(someProcess) | bs getItem [INDEX]

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

(someProcess) | bs help [COMMAND]

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

(someProcess) | bs join [GLUE]

Join multiple array elements together

USAGE
  $ (someProcess) | bs join [GLUE]

ARGUMENTS
  GLUE  [default:  ] Glue to use for join

See code: src/commands/join.js

(someProcess) | bs replace SEARCHTERM REPLACETERM

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

(someProcess) | bs script [SCRIPTNAME]

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

bs script:add

Add a new Script

USAGE
  $ bs script:add

See code: src/commands/script/add.js

bs script:delete SCRIPTNAME

Delete a named script

USAGE
  $ bs script:delete SCRIPTNAME

ARGUMENTS
  SCRIPTNAME  delete the `scriptName` script

See code: src/commands/script/delete.js

bs script:list

List your Scripts

USAGE
  $ bs script:list

See code: src/commands/script/list.js

(someProcess) | bs select INDEXES

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

(someProcess) | bs split DELIMITER

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

(someProcess) | bs toArray

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

(someProcess) | bs trim TRIMCHAR

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