Last active
June 20, 2022 10:36
-
-
Save robertcoopercode/7b958290baa66bba5571487d2f7a1be8 to your computer and use it in GitHub Desktop.
Raycast script for lorem ipsum text. Related utils file found at https://gist.github.com/robertcoopercode/e9ed269fdbffe63a440e98cf8575779b
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
#!/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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment