Skip to content

Instantly share code, notes, and snippets.

@robertcoopercode
Last active June 20, 2022 10:36
Show Gist options
  • Save robertcoopercode/7b958290baa66bba5571487d2f7a1be8 to your computer and use it in GitHub Desktop.
Save robertcoopercode/7b958290baa66bba5571487d2f7a1be8 to your computer and use it in GitHub Desktop.

Revisions

  1. robertcoopercode revised this gist Jul 22, 2021. No changes.
  2. robertcoopercode revised this gist Jul 22, 2021. No changes.
  3. robertcoopercode revised this gist Jul 22, 2021. No changes.
  4. robertcoopercode created this gist Jul 22, 2021.
    68 changes: 68 additions & 0 deletions loremipsum.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    #!/usr/bin/env php

    # Dependency: This script requires PHP
    # Install PHP: https://www.php.net/manual/en/install.php
    #
    # Required parameters:
    # @raycast.schemaVersion 1
    # @raycast.title Lorem Ipsum
    # @raycast.mode compact
    # @raycast.packageName Lorem Ipsum
    #
    # Optional parameters:
    # @raycast.icon 📝
    # @raycast.argument1 { "type": "text", "placeholder": "amount", "optional": true }
    # @raycast.argument2 { "type": "text", "placeholder": "words,sentences,paragraphs", "optional": true }
    #
    # Documentation:
    # @raycast.description Generate lorem ipsum text. Choose between words, sentences, or paragraphs (defaults to words). If amount not specified, defaults to 7 for words, 3 for sentences, and 3 for paragraphs.
    # @raycast.author Robert Cooper
    # @raycast.authorURL https://github.com/robertcoopercode

    <?php
    use utils\LoremIpsum;

    require_once('utils.php');

    $lipsum = new LoremIpsum;

    $count = $argv[1];
    $type = $argv[2];

    // Default to words if type not specified
    if (! in_array($type, array('words', 'word', 'w', 'sentences', 'sentence', 's', 'paragraphs', 'paragraph', 'p'))) {
    $type = "words";
    }

    if ($count === '') {
    switch ($type) {
    case 'words': $count = 7; break;
    case 'word': $count = 7; break;
    case 'sentences': $count = 3; break;
    case 'sentence': $count = 3; break;
    case 'paragraphs': $count = 3; break;
    case 'paragraph': $count = 3; break;
    }
    }

    switch ($type) {
    case 'word': $type = 'words'; break;
    case 'w': $type = 'words'; break;
    case 'sentence': $type = 'sentences'; break;
    case 's': $type = 'sentences'; break;
    case 'paragraph': $type = 'paragraphs'; break;
    case 'p': $type = 'paragraphs'; break;
    }


    if (! ctype_digit(strval($count))) {
    echo 'Not a valid number $count';
    exit(1);
    }

    $arg = ucfirst($lipsum->{$type}($count));

    shell_exec("echo '$arg' | pbcopy");
    $noun = $count > 1 ? $type : substr($type, 0, -1);

    echo "Copied ${count} ${noun} to clipboard";