diff --git a/info.plist b/info.plist index 6d22633..9d23451 100644 --- a/info.plist +++ b/info.plist @@ -131,7 +131,7 @@ escaping 127 script - python3 lipsum.py characters {query} + ./lipsum.sh -t characters -c {query} scriptargtype 0 scriptfile @@ -215,7 +215,7 @@ escaping 127 script - python3 lipsum.py words {query} + ./lipsum.sh -t words -c {query} scriptargtype 0 scriptfile @@ -230,6 +230,27 @@ version 2 + + config + + argumenttype + 1 + keyword + lipsum + subtext + Generate {query} sentences + text + Sentences + withspace + + + type + alfred.workflow.input.keyword + uid + 1029C7B6-DB95-4448-B3C5-C33F3DA0F894 + version + 1 + config @@ -238,7 +259,7 @@ escaping 127 script - python3 lipsum.py sentences {query} + ./lipsum.sh -t sentences -c {query} scriptargtype 0 scriptfile @@ -253,27 +274,6 @@ version 2 - - config - - argumenttype - 1 - keyword - lipsum - subtext - Generate {query} sentences - text - Sentences - withspace - - - type - alfred.workflow.input.keyword - uid - 1029C7B6-DB95-4448-B3C5-C33F3DA0F894 - version - 1 - config @@ -303,7 +303,7 @@ escaping 127 script - python3 lipsum.py paragraphs {query} + ./lipsum.sh -t paragraphs -c {query} scriptargtype 0 scriptfile @@ -390,7 +390,7 @@ variablesdontexport version - 3.2.0 + 4.0.0 webaddress https://github.com/alexchantastic/alfred-lipsum-workflow diff --git a/lib/__init__.py b/lib/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/lib/lorem/LICENSE b/lib/lorem/LICENSE deleted file mode 100755 index be383ed..0000000 --- a/lib/lorem/LICENSE +++ /dev/null @@ -1,29 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2019, Jarry Shaw -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/lorem/__init__.py b/lib/lorem/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/lib/lorem/lorem.py b/lib/lorem/lorem.py deleted file mode 100755 index 0ae18c6..0000000 --- a/lib/lorem/lorem.py +++ /dev/null @@ -1,436 +0,0 @@ -# -*- coding: utf-8 -*- -"""lorem ipsum generator - -In publishing and graphic design, lorem ipsum is a placeholder text commonly -used to demonstrate the visual form of a document or a typeface without -relying on meaningful content. - -The :mod:`lorem` module provides a generic access to generating the lorem ipsum -text from its very original text:: - - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod - tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim - veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea - commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit - esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat - cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id - est laborum. - -Usage of the :mod:`lorem` module is rather simple. Depending on your needs, the -:mod:`lorem` module provides generation of *words*, *sentences*, and -*paragraphs*. - -Get Random Words ----------------- - -The :mod:`lorem` module provides two different ways for getting random words. - -1. :func:`word` -- generate a list of random words - - .. code:: python - - word(count=1, func=None, args=(), kwargs={}) -> Iterator[str] - -2. :func:`get_word` -- return random words - - .. code:: python - - get_word(count=1, sep=' ', func=None, args=(), kwargs={}) -> str - -Get Random Sentences --------------------- - -The :mod:`lorem` module provides two different ways for getting random sentences. - -1. :func:`sentence` -- generate a list of random sentences - - .. code:: python - - sentence(count=1, comma=(0, 2), word_range=(4, 8)) -> Iterator[str] - -2. :func:`get_sentence` -- return random sentences - - .. code :: python - - get_sentence(count=1, sep=' ', comma=(0, 2), word_range=(4, 8)) -> Union[str] - -Get Random Paragraphs ---------------------- - -The :mod:`lorem` module provides two different ways for getting random paragraphs. - -1. :func:`paragraph` -- generate a list of random paragraphs - - .. code:: python - - paragraph(count=1, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Iterator[str] - -2. :func:`get_paragraph` -- return random paragraphs - - .. code:: python - - get_paragraph(count=1, sep=os.linesep, comma=(0, 2), word_range=(4, 8), sentence_range=(5, 10)) -> Union[str] - -Customise Word Pool -------------------- - -If wanted, the :mod:`lorem` module also provides an interface to customise the word -pool as you wish. - -1. :func:`set_pool` -- customise random word pool - - .. code:: python - - set_pool(pool) - -""" -import itertools -import os -import random -import typing - -__all__ = [ - 'set_pool', - 'word', 'sentence', 'paragraph', - 'get_word', 'get_sentence', 'get_paragraph', -] - -#: The original lorem ipsum text pool. -_TEXT = ('ad', 'adipiscing', 'aliqua', 'aliquip', 'amet', 'anim', 'aute', 'cillum', 'commodo', - 'consectetur', 'consequat', 'culpa', 'cupidatat', 'deserunt', 'do', 'dolor', 'dolore', - 'duis', 'ea', 'eiusmod', 'elit', 'enim', 'esse', 'est', 'et', 'eu', 'ex', 'excepteur', - 'exercitation', 'fugiat', 'id', 'in', 'incididunt', 'ipsum', 'irure', 'labore', 'laboris', - 'laborum', 'lorem', 'magna', 'minim', 'mollit', 'nisi', 'non', 'nostrud', 'nulla', - 'occaecat', 'officia', 'pariatur', 'proident', 'qui', 'quis', 'reprehenderit', 'sed', - 'sint', 'sit', 'sunt', 'tempor', 'ullamco', 'ut', 'velit', 'veniam', 'voluptate') - - -def _gen_pool(dupe: int = 1) -> typing.Iterator[str]: - """Generate word pool. - - Args: - dupe (int): Duplication to generate the word pool. - - Returns: - :obj:`Iterator[str]`: An infinite loop word pool. - - """ - pool = list() - for _ in range(dupe): - pool.extend(_TEXT) - random.shuffle(pool) - - while pool: # pragma: no cover - for text in pool: - yield text - random.shuffle(pool) - - -def _gen_word(pool: typing.Iterator[str], # pylint: disable=dangerous-default-value - func: typing.Optional[typing.Union[str, typing.Callable[[str], str]]] = None, - args: typing.Tuple[str] = (), kwargs: typing.Dict[str, str] = {}) -> str: - """Generate random word. - - Args: - pool (:obj:`Iterator[str]`): Word pool, returned by :func:`_gen_pool`. - func (:obj:`Optional[Union[str, Callable[[str], str]]]`): Filter function. It can be an - attribute name of :obj:`str`, or a customised function that takes the original :obj:`str` - and returns the modified :obj:`str`. - args (:obj:`Tuple[str]`): Additional positional arguments for ``func``. - kwargs (:obj:`Dict[str, Any]`): Additional keyword arguments for ``func``. - - Returns: - :obj:`str`: Random word. - - """ - text = next(pool) - if func is not None: - if isinstance(func, str): - text = getattr(text, func)(*args, **kwargs) - else: - text = func(text, *args, **kwargs) - return text - - -def _gen_sentence(pool: typing.Iterator[str], - comma: typing.Tuple[int], - word_range: typing.Tuple[int]) -> str: - """Generate random sentence. - - Args: - pool (:obj:`Iterator[str]`): Word pool, returned by :func:`_gen_pool`. - comma (:obj:`Tuple[int]`): Random range for number of commas. The function will use - :func:`random.randint` to choose a random integer as the number of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - - Returns: - :obj:`str`: Random sentence. - - """ - text = _gen_word(pool=pool, func='capitalize') - for _ in range(random.randint(*word_range) - 1): - text += ' ' + _gen_word(pool=pool) - - for _ in range(random.randint(*comma)): - include_comma = random.choice([True, False]) - if include_comma: - text += ',' - for _ in range(random.randint(*word_range)): - text += ' ' + _gen_word(pool=pool) - continue - break - return text + '.' - - -def _gen_paragraph(pool: typing.Iterator[str], - comma: typing.Tuple[int], - word_range: typing.Tuple[int], - sentence_range: typing.Tuple[int]) -> str: - """Generate random paragraph. - - Args: - pool (:obj:`Iterator[str]`): Word pool, returned by :func:`_gen_pool`. - comma (:obj:`Tuple[int]`): Random range for number of commas. The function will use - :func:`random.randint` to choose a random integer as the number of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - sentence_range (:obj:`Tuple[int]`): Random range for number of sentences in each - paragraph. The function will use :func:`random.randint` to choose a random integer - as the number of sentences. - - Returns: - :obj:`str`: Random paragraph. - - """ - text = _gen_sentence(pool=pool, comma=comma, word_range=word_range) - for _ in range(random.randint(*sentence_range) - 1): - text += ' ' + _gen_sentence(pool=pool, comma=comma, word_range=word_range) - return text - - -def word(count: int = 1, # pylint: disable=dangerous-default-value - func: typing.Optional[typing.Union[str, typing.Callable[[str], str]]] = None, - args: typing.Tuple[str] = (), kwargs: typing.Dict[str, str] = {}) -> typing.Iterator[str]: - """Generate a list of random words. - - .. code:: python - - >>> list(itertools.cycle(word(count=3), 3)) - ['labore', 'tempor', 'commodo'] - >>> list(itertools.cycle(word(count=3, func='capitalize'), 3)) - ['Ea', 'Lorem', 'Do'] - >>> list(itertools.cycle(word(count=3, func=lambda s: s.upper()), 3)) - ['UT', 'AMET', 'EXCEPTEUR'] - - Args: - count (int): Number of non-repeated random words. - func (:obj:`Optional[Union[str, Callable[[str], str]]]`): Filter function. - It can be an attribute name of :obj:`str`, or a customised function that - takes the original :obj:`str` and returns the modified :obj:`str`. - args (:obj:`Tuple[str]`): Additional positional arguments for ``func``. - kwargs (:obj:`Dict[str, Any]`): Additional keyword arguments for ``func``. - - Returns: - :obj:`Iterator[str]`: Indefinite random words generator. - - """ - pool = _gen_pool(count) - yield from itertools.cycle(_gen_word(pool=pool, - func=func, - args=args, - kwargs=kwargs) for _ in range(count)) - - -def sentence(count: int = 1, - comma: typing.Tuple[int] = (0, 2), - word_range: typing.Tuple[int] = (4, 8)) -> typing.Iterator[str]: - """Generate a list of random sentences. - - .. code:: python - - >>> list(itertools.islice(sentence(), 1)) - ['Aute irure et commodo sunt do duis dolor.'] - - Args: - count (int): Number of non-repeated random sentences. - comma (:obj:`Tuple[int]`): Random range for number of commas. The function will - use :func:`random.randint` to choose a random integer as the number of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - - Returns: - :obj:`Iterator[str]`: Indefinite random sentence generator. - - """ - pool = _gen_pool(count * random.randint(*word_range)) - yield from itertools.cycle(_gen_sentence(pool=pool, - comma=comma, - word_range=word_range) for _ in range(count)) - - -def paragraph(count: int = 1, - comma: typing.Tuple[int] = (0, 2), - word_range: typing.Tuple[int] = (4, 8), - sentence_range: typing.Tuple[int] = (5, 10)) -> typing.Iterator[str]: - """Generate a list of random paragraphs. - - .. code:: python - - >>> list(itertools.islice(paragraph(), 1)) - ['Aute sint et cupidatat aliquip. Non exercitation est aliquip voluptate ' - 'fugiat, reprehenderit ad occaecat laboris velit consequat. Magna enim ' - 'deserunt aute laborum fugiat exercitation. Aliqua ex sunt fugiat in ' - 'magna voluptate. Elit nisi exercitation nostrud. Magna proident et ' - 'fugiat eiusmod cupidatat fugiat, sit culpa fugiat non ea eu ' - 'reprehenderit elit. Proident mollit mollit ut cillum. Nostrud voluptate ' - 'aliquip cupidatat anim.'] - - Args: - count (int): Number of non-repeated random paragraphs. - comma (:obj:`Tuple[int]`): Random range for number of commas. The function - will use :func:`random.randint` to choose a random integer as the number - of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - sentence_range (:obj:`Tuple[int]`): Random range for number of sentences in each - paragraph. The function will use :func:`random.randint` to choose a random - integer as the number of sentences. - - Returns: - :obj:`Iterator[str]`: Random paragraph generator. - - """ - pool = _gen_pool(count * random.randint(*word_range) * random.randint(*sentence_range)) - yield from itertools.cycle(_gen_paragraph(pool=pool, - comma=comma, - word_range=word_range, - sentence_range=sentence_range) for _ in range(count)) - - -def get_word(count: typing.Union[int, typing.Tuple[int]] = 1, # pylint: disable=dangerous-default-value - sep: str = ' ', - func: typing.Optional[typing.Union[str, typing.Callable[[str], str]]] = None, - args: typing.Tuple[str] = (), kwargs: typing.Dict[str, str] = {}) -> str: - """Return random words. - - .. code:: python - - >>> get_word(count=3) - 'anim voluptate non' - >>> get_word(count=3, func='capitalize') - 'Non Labore Ut' - >>> get_word(count=3, func=lambda s: s.upper()) - 'NISI TEMPOR CILLUM' - - Args: - count (:obj:`Union[int, Tuple[int]]`): Number of random words. To generate random - number of words, supply a 2-element tuple of :obj:`int`, the function will use - :func:`random.randint` to choose a random integer as the number of random words. - sep (str): Seperator between each word. - func (:obj:`Optional[Union[str, Callable[[str], str]]]`): Filter function. It can be - a function name of :obj:`str`, or a customised function that takes the original - :obj:`str` and returns the modified :obj:`str`. - args (:obj:`Tuple[str]`): Additional positional arguments for ``func``. - kwargs (:obj:`Dict[str, Any]`): Additional keyword arguments for ``func``. - - Returns: - :obj:`str`: Random words. - - """ - if isinstance(count, tuple): - count = random.randint(*count) - return sep.join(itertools.islice(word(count, func, args, kwargs), count)) - - -def get_sentence(count: typing.Union[int, typing.Tuple[int]] = 1, - sep: str = ' ', - comma: typing.Tuple[int] = (0, 2), - word_range: typing.Tuple[int] = (4, 8)) -> str: - """Return random sentences. - - .. code:: python - - >>> get_sentence() - 'Nostrud laboris lorem minim sit culpa, aliqua nostrud in amet, sint pariatur eiusmod esse.' - - Args: - - count (:obj:`Union[int, Tuple[int]]`): Number of random sentences. To generate - random number of sentences, supply a 2-element tuple of :obj:`int`, the - function will use :func:`random.randint` to choose a random integer as the number - of random sentences. - sep (str): Seperator between each sentence. - comma (:obj:`Tuple[int]`): Random range for number of commas. The function will use - :func:`random.randint` to choose a random integer as the number of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - - Returns: - :obj:`str`: Random sentences. - - """ - if isinstance(count, tuple): - count = random.randint(*count) - return sep.join(itertools.islice(sentence(count, comma, word_range), count)) - - -def get_paragraph(count: typing.Union[int, typing.Tuple[int]] = 1, - sep: str = os.linesep, - comma: typing.Tuple[int] = (0, 2), - word_range: typing.Tuple[int] = (4, 8), - sentence_range: typing.Tuple[int] = (5, 10)) -> str: - """Return random paragraphs. - - .. code:: python - - >>> get_paragraph() - 'Exercitation magna sunt excepteur irure adipiscing commodo duis. Est ' - 'ipsum qui deserunt, deserunt nostrud reprehenderit esse. Do velit ' - 'est in velit sed. Sunt officia officia lorem. Commodo lorem ' - 'exercitation veniam officia pariatur velit. Deserunt deserunt sed ' - 'consequat laborum consequat dolor. Et consectetur irure sint elit tempor,' - ' est minim nisi eiusmod id excepteur. Minim cillum veniam sed aliquip ' - 'anim sit, pariatur nostrud ex cillum laboris laborum. Laborum ullamco ' - 'mollit elit. Amet id incididunt ipsum sed.' - - Args: - count (:obj:`Union[int, Tuple[int]]`): Number of random paragraphs. To generate - random number of paragraphs, supply a 2-element tuple of :obj:`int`, the function - will use :func:`random.randint` to choose a random integer as the number of random - paragraphs. - sep (str): Seperator between each paragraph. The default value is OS-dependent as - :data:`os.linsep` (``\\r\\n`` on Windows, ``\\n`` on POSIX). - comma (:obj:`Tuple[int]`): Random range for number of commas. The function will use - :func:`random.randint` to choose a random integer as the number of commas. - word_range (:obj:`Tuple[int]`): Random range for number of words in each sentence. - The function will use :func:`random.randint` to choose a random integer as the - number of words. - sentence_range (:obj:`Tuple[int]`): Random range for number of sentences in each - paragraph. The function will use :func:`random.randint` to choose a random integer - as the number of sentences. - - Returns: - :obj:`str`: Random paragraphs. - - """ - if isinstance(count, tuple): - count = random.randint(*count) - return sep.join(itertools.islice(paragraph(count, comma, word_range, sentence_range), count)) - - -def set_pool(pool: typing.Iterable[str]): - """Customise random word pool. - - Args: - - pool (:obj:`Iterable[str]`): List of words to be used as random word pool. - - """ - global _TEXT - _TEXT = pool \ No newline at end of file diff --git a/lipsum.py b/lipsum.py deleted file mode 100644 index fa3275e..0000000 --- a/lipsum.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys -from lib.lorem import lorem - -args = sys.argv -type = args[1] -count = int(args[2]) if len(args) >= 3 else 1 - -def get_character(count): - pool = lorem.get_word(1) - - while len(pool) <= count: - pool += ' ' + lorem.get_word(1) - - return pool[0:count] - -def lipsum(type): - if type == 'characters': - return get_character(count).capitalize() - - elif type == 'words': - return lorem.get_word(count).capitalize() - - elif type == 'sentences': - return lorem.get_sentence(count) - - elif type == 'paragraphs': - return lorem.get_paragraph(count, '\n\n') - - else: - return lorem.get_sentence(count) - -sys.stdout.write(lipsum(type)) -sys.stdout.flush() diff --git a/lipsum.sh b/lipsum.sh new file mode 100755 index 0000000..7b64122 --- /dev/null +++ b/lipsum.sh @@ -0,0 +1,190 @@ +#!/bin/sh +version="1.0.0" +word_pool=("ad" "adipiscing" "aliqua" "aliquip" "amet" "anim" "aute" "cillum" "commodo" + "consectetur" "consequat" "culpa" "cupidatat" "deserunt" "do" "dolor" "dolore" + "duis" "ea" "eiusmod" "elit" "enim" "esse" "est" "et" "eu" "ex" "excepteur" + "exercitation" "fugiat" "id" "in" "incididunt" "ipsum" "irure" "labore" "laboris" + "laborum" "lorem" "magna" "minim" "mollit" "nisi" "non" "nostrud" "nulla" + "occaecat" "officia" "pariatur" "proident" "qui" "quis" "reprehenderit" "sed" + "sint" "sit" "sunt" "tempor" "ullamco" "ut" "velit" "veniam" "voluptate") +default_min_words=4 +default_max_words=8 + +# Generate a series of characters +# +# @param int $count Number of characters to generate +# @return string +generate_characters() { + local count word words characters + + count=$1 + + while [ ${#characters} -lt $count ] + do + word=$(generate_words 1) + words+=($word) + characters=${words[@]} + done + + echo ${characters:0:$count} +} + +# Generate a series of words +# +# @param int $count Number of words to generate +# @return string +generate_words() { + local i count rand word words + + count=$1 + + for ((i=0; i<$count; i++)) + do + rand=$(( RANDOM % ${#word_pool[*]} )) + word=${word_pool[$rand]} + words+=($word) + done + + echo ${words[@]} +} + +# Generate a series of sentences +# +# @param int $count Number of sentences to generate +# @param int $min Minimum number of words per sentence (default: 4) +# @param int $max Maximum number of words per sentence (default: 8) +# @return string +generate_sentences() { + local i count min max len placement sentence sentences + + count=$1 + min=${2:-$default_min_words} + max=${3:-$default_max_words} + + for ((i=0; i<$count; i++)) + do + len=$(( RANDOM % (${max} - ${min} + 1 ) + ${min} )) + sentence=$(generate_words $len) + sentence=$(capitalize "$sentence") + + # Randomly distribute commas throughout the sentences + if [ $len -gt 1 -a $(( RANDOM % 2 )) = 1 ]; then + placement=$(( RANDOM % ($len - 1) + 1 )) + sentence=$(sed "s/ /, /"$placement <<<$sentence) + fi + + sentences+=($sentence.) + done + + echo ${sentences[@]} +} + +# Generate a series of paragraphs +# +# @param int $count Number of paragraphs to generate +# @param int $min Minimum number of sentences per paragraph (default: 5) +# @param int $max Maximum number of sentences per paragraph (default: 10) +# @param int $min_words Minimum number of words per sentence (default: 4) +# @param int $max_words Maximum number of words per sentence (default: 8) +# @return string +generate_paragraphs() { + local i count min max len min_words max_words paragraph paragraphs + + count=$1 + min=${2:-5} + max=${3:-10} + min_words=${4:-$default_min_words} + max_words=${5:-$default_max_words} + + for ((i=0; i<$count; i++)) + do + len=$(( RANDOM % (${max} - ${min} + 1 ) + ${min} )) + paragraph=$(generate_sentences $len $min_words $max_words) + paragraphs+=$paragraph + + # Add linebreaks + if [ ! $i = $(( $count - 1 )) ]; then + paragraphs+="\n\n" + fi + done + + echo ${paragraphs[@]} +} + +# Capitalize the first letter in a string +# +# @param string $string String to capitalize +# @return string +capitalize() { + local string first_letter ord + + string=$1 + + first_letter=${string:0:1} + + if [[ ${first_letter} == [a-z] ]]; then + ord=$(printf '%o' "'${first_letter}") + ord=$(( ord - 40 )) + first_letter=$(printf '%b' '\'${ord}) + fi + + echo "${first_letter}${string:1}" +} + +# Show help information +# +# @return string +show_help() { + echo "Generates lorem ipsum dummy text" + echo + echo "Usage: lipsum [-t] [-c] [-m|M|w|W|h|v]" + echo "options:" + echo " t Type of text structure to generate (characters|words|sentences|paragraphs)" + echo " c Number of structures to generate" + echo " m Minimum number of structures to generate (applies to sentence and paragraph only)" + echo " M Maximum number of structures to generate (applies sentence and paragraph only)" + echo " w Minimum number of sentence words to generate (applies to paragraph only)" + echo " W Maximum number of sentences words to generate (applies to paragraph only)" + echo " v Print the software version" + echo " h Print help" +} + +# Show version information +# +# @return string +show_version() { + echo "lipsum $version" +} + +while getopts t:c:m:M:w:W:hv option +do + case $option in + t) type=${OPTARG};; + c) count=${OPTARG};; + m) min=${OPTARG};; + M) max=${OPTARG};; + w) min_words=${OPTARG};; + W) max_words=${OPTARG};; + h) show_help;; + v) show_version;; + *) + echo "Incorrect options provided" + exit 1 + ;; + esac +done + +case $type in + characters|character|char|c) + printf "$(capitalize "$(generate_characters $count)")" + ;; + words|word|w) + printf "$(capitalize "$(generate_words $count)")" + ;; + sentences|sentence|sent|s) + printf "$(generate_sentences $count $min $max)" + ;; + paragraphs|paragraph|para|p) + printf "$(generate_paragraphs $count $min $max $min_words $max_words)" + ;; +esac