Skip to content

Instantly share code, notes, and snippets.

@namklabs
Last active October 31, 2018 19:22
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namklabs/273055ef9c060af6ddc34a78910585a6 to your computer and use it in GitHub Desktop.
Save namklabs/273055ef9c060af6ddc34a78910585a6 to your computer and use it in GitHub Desktop.
bash lorem ipsum osx terminal
function lorem(){
# Copy lorem ipsum to your clipboard in OS X
# usage:
# $ lorem <int> <htmlflag>
# where <int> is how many paragraphs of lorem ipsum you want, each separated by 2 newlines
# and <htmlflag> is anything, indicating you want each paragraph surrounded by <p></p>. Omit if you don't want this.
# Explanations
# This is our source lorem ipsum text.
lorem='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.'
# Here we are gathering the <int> argument.
count=$(( $1 ))
# The minimum is 1 lorem ipsum, so enforce that here.
if [[ "$count" -lt 1 ]];
then
count=$(( $count + 1 ))
fi
# This is the variable that will hold our output.
text=''
# Iterate until our count is zero. Decrement each iteration.
while [ "$count" -gt 0 ];
do
# Append the lorem ipsum again.
# Check if we should add a beginning <p> tag.
if [[ $2 != '' ]];
then
text=$text'<p>'$lorem'</p>'
else
text=$text$lorem
fi
# If this isn't the last iteration, add newlines or paragraph HTML tags.
if [[ "$count" -gt 1 ]];
then
text=$text'\n\n'
fi
# Decrement our counter variable.
count=$(( $count - 1 ))
done
# Copy to clipboard!
echo -e $text | pbcopy
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment