I created a POSIX shell script alternative to randomize.py#2
Open
mutageneral wants to merge 1 commit intony64:masterfrom
Open
I created a POSIX shell script alternative to randomize.py#2mutageneral wants to merge 1 commit intony64:masterfrom
mutageneral wants to merge 1 commit intony64:masterfrom
Conversation
POSIX shell script alternative to randomize.py that should work on all Linux, BSD and MacOS systems out of the box
mutageneral
commented
Sep 1, 2024
| # clean up each word: remove leading and trailing punctuation and quotes | ||
| val=$(printf "%s" "$val" | sed -e 's/^[({'"'"'"]*//' -e 's/[.,!?;:)]}'"'"'"]*$//') | ||
| words="$words | ||
| $val" # one word per line in $words var |
Author
There was a problem hiding this comment.
Would this be better?
words="${words}${words:+$'\n'}$val"It seems to work the same way and fits on a single line, but it's less understandable.
mutageneral
commented
Sep 1, 2024
| set -- $line | ||
| for val; do | ||
| # clean up each word: remove leading and trailing punctuation and quotes | ||
| val=$(printf "%s" "$val" | sed -e 's/^[({'"'"'"]*//' -e 's/[.,!?;:)]}'"'"'"]*$//') |
Author
There was a problem hiding this comment.
I think this would do the same thing as this cryptic sed command and better, but I will be honest, I haven't tried the punctuation cleaning feature with eider commands.
# delete leading and trailing punctuation and whitespace from each line
sed -e 's/^[[:punct:][:space:]]*//' -e 's/[[:punct:][:space:]]*$//'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I created a POSIX shell script alternative to randomize.py that should work on all Linux, BSD and macOS systems out of the box, no Python required.
I think this fits well with the "only use the standard c libraries" goal of the project by providing a portable alternative to the Python script.
Usage example:
Oh, and another thing. I can't help with this until I learn C, but on POSIX systems we have pipes, so I would like if typist could read the words from stdin so you could do something like this:
$ randomize.sh most_used_words.txt | typist -(I would modify randomize.sh to output out of stdout by default.)
This is better because we don't have to write to the disk.
Another benefit: randomize.sh wouldn't overwrite the file, so you could pass it paths of text files without having to make a copy first.
It also gives us more extensibility and power.
For example, if you want a shorter test:
$ randomize.sh most_used_words.txt | head -1 | typist -It keeps only the first line of the randomized text.
Or you could type a fortune cookie/quote:
$ fortune | typist -Or a manual page:
$ man 1p sed | typist -