Streamlining Tweet Creation from Markdown

As an experience engineer, I’m always looking for ways to streamline my workflow. Recently, I developed a nifty solution to transform my newsletter content, which is Markdown-formatted, into tweet-ready text quickly.

This solution combines a bash script with the text expansion tool Espanso, creating a seamless process for generating tweets from my existing content.

The Bash Script: tweet_from_markdown

Let’s start by examining the bash script I created:

#!/bin/bash
# Get the main content
main_content=$(pbpaste | sed -E 's/^[0-9]+. //; s/[MORE].*$//' | tr -d 'n' | cut -c 1-277 | sed -E 's/(.*)$/1.../')
# Get the link
link=$(pbpaste | sed -nE 's/.*[MORE]((.*))/1/p')
# Combine and print
echo "${main_content} ${link}"

This script does several things:

  1. It uses pbpaste to get the content from the clipboard.

  2. It removes any numbering at the start of the content.

  3. It trims the content to 277 characters (leaving room for the link) and adds an ellipsis.

  4. It extracts a link from the [MORE] section of the original content.

  5. Finally, it combines the trimmed content with the link and prints the result.

Integrating with Espanso

To make this script even more powerful, I integrated it with Espanso, a cross-platform text expander. Here’s the Espanso configuration:

  - trigger: ":tw"
    replace: "{{output}}"
    vars:
      - name: output
        type: shell
        params:
          cmd: "~/Documents/dev/hivefive-stack/tweet_from_markdown"

This configuration tells Espanso to:

  1. Watch for the “:tw” trigger.

  2. When triggered, run the tweet_from_markdown script.

  3. Replace the trigger with the output of the script.

How It Works in Practice

Now, whenever I’m writing content in Markdown format, I can easily create a tweet-ready version:

  1. I copy the relevant portion of my Markdown content to the clipboard. In my case, the Hive Five newsletter.

     4. Joel discusses strategies and tips for part-time bug bounty hunting. He covers things like finding (and enforcing) balance, picking programs and goals, and streamlining your process to optimize productivity. [MORE](https://www.youtube.com/watch?v=AlqmnkfckWg)

  2. Then, in any text field, I type “:tw”.

  3. Espanso detects the trigger, runs the script, and replaces “:tw” with the tweet-ready text.

  4. Output: Joel discusses strategies and tips for part-time bug bounty hunting. He covers things like finding (and enforcing) balance, picking programs and goals, and streamlining your process to optimize productivity. ... https://www.youtube.com/watch?v=AlqmnkfckWg

This process takes a matter of seconds and ensures that my tweets are consistently formatted and include the link.

Conclusion

By combining a simple bash script with the power of Espanso, I’ve created a workflow that significantly speeds up my content distribution process. This solution demonstrates how small, targeted scripts can be leveraged to create powerful automation tools.

Whether you’re a content creator, marketer, or just someone who tweets frequently, this kind of automation can save you time and ensure consistency in your social media posts.

Feel free to remix this script and Espanso configuration to your own needs.



Source link