strs

๐Ÿงต Easy string tools for the shell

https://github.com/alexdelorenzo/strs

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • โ—‹
    CITATION.cff file
  • โœ“
    codemeta.json file
    Found codemeta.json file
  • โ—‹
    .zenodo.json file
  • โ—‹
    DOI references
  • โ—‹
    Academic publication links
  • โ—‹
    Committers with academic emails
  • โ—‹
    Institutional organization owner
  • โ—‹
    JOSS paper metadata
  • โ—‹
    Scientific vocabulary similarity
    Low similarity (6.3%) to scientific vocabulary

Keywords

bash shell shell-script string string-algorithms string-manipulation strings strings-python
Last synced: 6 months ago · JSON representation

Repository

๐Ÿงต Easy string tools for the shell

Basic Info
  • Host: GitHub
  • Owner: alexdelorenzo
  • License: agpl-3.0
  • Language: Python
  • Default Branch: main
  • Homepage: https://alexdelorenzo.dev
  • Size: 178 KB
Statistics
  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • Open Issues: 1
  • Releases: 4
Topics
bash shell shell-script string string-algorithms string-manipulation strings strings-python
Created over 4 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Funding License

README.md

Easy string tools for the shell

strs has more than 50 tools that make working with strings in the shell easier.

strs brings common string convenience methods to shells like Bash, because string manipulation in shells can be hard.

```bash $ str capitalize "hey there! :fire:" | str to-emoji Hey there! ๐Ÿ”ฅ

$ str repeat 5 โญ | str join ๐ŸŒ™ โญ ๐ŸŒ™ โญ ๐ŸŒ™ โญ ๐ŸŒ™ โญ ๐ŸŒ™ โญ ```

Table of Contents

Commands

capitalize casefold center col count
contains endswith find has-emoji index
isalnum isalpha isascii isdecimal isdigit
isidentifier islower isnumeric isprintable isspace
istitle isupper join length lower
ljust lstrip nth partition replace
replace-first repeat rfind rindex rpartion
rsplit rstrip rjust upper split
strip sbob startswith substring slice
title to-ascii to-emoji from-emoji zerofill

Usage

Practical example

If you're on Debian, you can use strs to take your apt sources from Debian testing, point them to Debian stable on the fly, and then send them to a stable machine: bash $ str replace testing stable < sources.list | ssh host "cat > /etc/apt/sources.list"

To do the same with sed, you'd need to know sed's regex syntax, if your sed comes with the -i feature flag, and if it's GNU sed or BSD sed.

strs, on the other hand, has a uniform interface and set of features across platforms, shells and operating systems, including Windows.

String manipulation in the shell

strs has string tools that are similar to those that are built into Bash, and it has commands for features that Bash doesn't have syntactic sugar for, as well.

The following examples of Bash code only work with Bash, whereas strs commands will work if you're using Bash, zsh, PowerShell or something else.

String length

Bash

```bash string='This is an example.'

$ echo "${#string}" 19 ```

strs

bash $ str length "$string" 19

Or, using pipes: bash $ echo $string | str length 19

Strip

Bash

```bash front='This' end='example.'

$ echo "${string#$front}" # from front is an example.

$ echo "${string%$end}" # from end This is an ```

strs

```bash $ str lstrip $front "$string" is an example.

$ str rstrip $end "$string" This is an

$ str strip $front$end "$string" is an ```

Or, using pipes: ```bash $ echo $string | str lstrip $front is an example.

$ echo $string | str rstrip $end This is an

$ echo $string | str strip $front$end is an ```

Capitalization

Bash

```bash $ echo "${string^}" # capitalize first char This is an example.

$ echo "${string^^}" # capitalize all THIS IS AN EXAMPLE.

$ echo "${string,,}" # lower all this is an example. ```

strs

```bash $ str capitalize "$string" This is an example.

$ str upper "$string" THIS IS AN EXAMPLE.

$ str lower "$string" this is an example. ```

Or: ```bash $ echo $string | str capitalize This is an example.

$ echo $string | str upper THIS IS AN EXAMPLE.

$ echo $string | str lower this is an example. ```

Replace

Bash

```bash old='an' new='a'

$ echo "${string//$old/$new}" # replace all This is a example.

$ echo "${string/$old/$new}" # replace first This is a example. ```

strs

```bash $ str replace $old $new "$string" This is a example.

$ str replace $old $new "$string" --count 1 This is a example.

$ str replace-first $old $new "$string" This is a example. ```

Or: bash $ echo $string | str replace $old $new $ echo $string | str replace $old $new --count 1 $ echo $string | str replace-first $old $new

String manipulation tools

strs has string manipulation commands that don't have syntactic sugar in Bash.

Casefold

```bash string='This is an example.'

$ str casefold "$string" this is an example. ```

bash $ echo $string | str casefold this is an example.

Center

```bash width=40

$ str center $width "$string" This is an example.
```

bash $ echo $string | str center $width This is an example.

Count

```bash countChar='e'

$ str count $countChar "$string" 2 ```

bash $ echo $string | str count $countChar 2

Find

```bash find='e'

$ str find $find "$string" 11 ```

bash $ echo $string | str find $find 11

Index

bash $ str index $find "$string" 11

bash $ echo $string | str index $find 11

Join

```bash on='_'

$ str join $on $string Thisisan_example. ```

bash $ str split ' ' "$string" | str join $on This_is_an_example.

Partition

```bash part=' '

$ str partition "$part" "$string" This

is an example. ```

bash $ echo $string | str partition "$part" [...]

Split

```bash split=' '

$ str split "$split" "$string" This is an example. ```

bash $ echo $string | str split "$split" [...]

Strip

```bash strip='.'

$ str strip $strip "$string" This is an example ```

bash $ echo $string | str strip $strip This is an example

Swap case

bash $ str swapcase "$string" tHIS IS AN EXAMPLE.

bash $ echo $string | str swapcase tHIS IS AN EXAMPLE.

To title case

bash $ str title "$string" This Is An Example.

bash $ echo $string | str title This Is An Example.

Zero fill

bash $ str zfill $width "$string" 000000000000000000000This is an example.

bash $ echo $string | str zfill $width 000000000000000000000This is an example.

Repeat

bash $ str repeat 3 "$string" This is an example. This is an example. This is an example.

bash $ echo $string | str repeat 3 [...]

Left justify

bash $ str ljust $width "$string" --fillchar '*' This is an example.*********************

bash $ echo $string | str ljust $width --fillchar '*' This is an example.*********************

Left strip

bash $ str lstrip T "$string" his is an example.

bash $ echo $string | str lstrip T his is an example.

Right find

bash $ str rfind $find "$string" 17

bash $ echo $string | str rfind $find 17

Right index

bash $ str rindex $find "$string" 17

bash $ echo $string | str rindex $find 17

Right justify

bash $ str rjust $width "$string" This is an example.

bash $ echo $string | str rjust $width This is an example.

Right strip

```bash remove='.'

$ str rstrip $remove "$string" This is an example ```

bash $ echo $string | str rstrip $remove This is an example

Right partition

```bash $ str rpartition "$part" "$string" This is an

example. ```

bash $ echo $string | str rpartition "$part" [...]

Right split

bash $ str rsplit "$split" "$string" This is an example.

bash $ echo $string | str rsplit "$split" [...]

More string tools

strs has tools that deal with UTF-8, ASCII and emojis, and it has tools that aren't found in Python or common shells.

To ASCII

bash $ str to-ascii "It is 20ยฐ Celsius outside." It is 20deg Celsius outside.

bash $ str to-ascii "ว ฤš ว ว‘ ว“ ฤŒ ฤŽ วฆ ศž วฐ วจ ฤฝ ล‡ ล˜ ล  ลค ลฝ" A E I O U C D G H j K L N R S T Z

Substring

bash $ str substring 3 "Hey there! ๐Ÿ”ฅ" Hey

You can use negative indices like you can in Python: bash $ str substring -3 "Hey there! ๐Ÿ”ฅ" --start 4 there

Slice

You can use Python's slice syntax directly, too. bash $ str slice 4:-3 "Hey there! ๐Ÿ”ฅ" there

Contains

bash $ str contains ๐Ÿ”ฅ "Hey there! ๐Ÿ”ฅ"; echo $? 0

Emojis

bash $ str has-emoji "Hey there! ๐Ÿ”ฅ"; echo $? 0

bash $ str from-emoji "Hey there! ๐Ÿ”ฅ" Hey there! :fire:

Get columns

bash $ str col 2 'hello world' world

bash $ echo -e 'hello\tworld' | str col 2 world

Return nth lines

bash $ sudo dmesg | str nth 50 [73627.811739] Filesystems sync: 0.02 seconds

tYpE lIkE tHiS

bash $ str sbob "squidward likes krabby patties" sQuIdWaRd LiKeS kRaBbY pAtTiEs

String validation tools

strs also brings Python's string validation methods to the shell.

Here's an example of how you'd use them in a conditional statement, followed by examples of other validation tools: ```bash string='This is an example.'

if str startswith T "$string" && str endswith . "$string"; then printf "Starts with T and ends with .\n"

elif str contains example "$string"; then printf "Contains 'example'\n"

elif !str isalnum "$string"; then printf "Isn't alphanumeric\n"

fi ```

Starts with

bash $ str startswith T "$string"; echo $? 0

bash $ echo $string | str startswith T; echo $? 0

Ends with

bash $ str endswith . "$string"; echo $? 0

bash $ echo $string | str endswith .; echo $? 0

Is alphanumeric

bash $ str isalnum "$string"; echo $? 0

bash $ echo $string | str isalnum; echo $? 0

Is alphabetic

bash $ str isalpha "$string"; echo $? 1

bash $ echo $string | str isalpha; echo $? 1

Is ASCII

bash $ str isascii "$string"; echo $? 0

bash $ echo $string | str isascii; echo $? 0

Is decimal

bash $ str isdecimal "$string"; echo $? 1

bash $ echo $string | str isdecimal; echo $? 1

Is digit

bash $ str isdigit "$string"; echo $? 1

bash $ echo $string | str isdigit; echo $? 1

Is valid Python identifier

bash $ str isidentifier "$string"; echo $? 1

bash $ echo $string | str isidentifier; echo $? 1

Is lower case

bash $ str islower "$string"; echo $? 1

bash $ echo $string | str islower; echo $? 1

Is numeric

bash $ str isnumeric "$string"; echo $? 1

bash $ echo $string | str isnumeric; echo $? 1

Is printable

bash $ str isprintable "$string"; echo $? 0

bash $ echo $string | str isprintable; echo $? 0

Is space character

bash $ str isspace "$string"; echo $? 1

bash $ echo $string | str isspace; echo $? 1

Is title case

bash $ str istitle "$string"; echo $? 1

bash $ echo $string | str istitle; echo $? 1

Is upper case

bash $ str isupper "$string"; echo $? 1

bash $ echo $string | str isupper; echo $? 1

Installation

Prerequisites

  • A Unix shell like Bash, or PowerShell or Command Prompt on Windows
  • Python 3.10+
  • requirements.txt

PyPI

bash python3 -m pip install strs You can view the strs package on PyPI.

Owner

  • Name: Alex DeLorenzo
  • Login: alexdelorenzo
  • Kind: user
  • Location: NYC / NJ

GitHub Events

Total
  • Watch event: 3
Last Year
  • Watch event: 3

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 234
  • Total Committers: 2
  • Avg Commits per committer: 117.0
  • Development Distribution Score (DDS): 0.107
Top Committers
Name Email Commits
Alex DeLorenzo a****x@a****v 209
Alex DeLorenzo 3****o@u****m 25
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 1
  • Total pull request authors: 0
  • Average comments per issue: 1.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • alexdelorenzo (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 54 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 23
  • Total maintainers: 1
pypi.org: strs

Easy string tools for the shell

  • Versions: 23
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 54 Last month
Rankings
Dependent packages count: 10.0%
Average: 21.3%
Downloads: 21.7%
Dependent repos count: 21.7%
Stargazers count: 23.1%
Forks count: 29.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

requirements.txt pypi
  • Unidecode >=1.3.2,<1.4.0
  • emoji >=1.6.1,<1.7.0
  • fire >=0.4.0,<0.5.0
  • more-itertools >=8.12.0,<8.13.0
  • unpackable >=0.0.4,<0.1.0
setup.py pypi