Copy output to clipboard as rich text for Slack
Take the most recent assistant output (or the content the user specifies: $ARGUMENTS) and copy it to the clipboard as rich text suitable for pasting into Slack, email, or other rich text editors.
Identify the content to copy. Use the most recent assistant output unless the user specifies something else via $ARGUMENTS.
Convert the markdown to simple HTML:
<b> tags)<ul>/<li> tags)<a href="..."> tags)<code style="background:#f0f0f0;padding:2px 4px;border-radius:3px;font-family:monospace;">)<pre style="background:#f0f0f0;padding:8px;border-radius:4px;font-family:monospace;">)<br> tagsEscape single quotes in the HTML by replacing ' with '.
Detect the OS and copy to clipboard as rich text:
First detect the platform:
uname -s
echo '<html content here>' | hexdump -ve '1/1 "%.2x"' \
| xargs printf 'set the clipboard to {text:" ", «class HTML»:«data HTML%s»}' | osascript -
This sets the «class HTML» pasteboard type so it pastes as formatted rich text.
Requires xclip. If not installed, tell the user to run sudo dnf install xclip (Fedora) or sudo apt install xclip (Debian/Ubuntu).
echo '<html content here>' | xclip -selection clipboard -t text/html
This sets the text/html MIME type on the X11 clipboard so it pastes as rich text in Slack, browsers, and email clients.
Requires wl-copy from wl-clipboard. If not installed, tell the user to run sudo dnf install wl-clipboard (Fedora) or sudo apt install wl-clipboard (Debian/Ubuntu).
echo '<html content here>' | wl-copy --type text/html
How to choose between X11 and Wayland: Check echo $XDG_SESSION_TYPE. If it says wayland, use wl-copy. If it says x11, use xclip.
Replace <html content here> with the actual HTML generated from the markdown.
Confirm to the user that the content has been copied to the clipboard as rich text, and mention which clipboard method was used.