flavorjones / calendar-assistant

Command-line tool to manage your Google Calendar
Apache License 2.0
19 stars 5 forks source link

"availability" command copies to clipboard #49

Open mikfreedman opened 5 years ago

mikfreedman commented 5 years ago

Maybe formatted for Gmail? maybe not?

https://github.com/envygeeks/clippy

Just putting this here for reference.

flavorjones commented 5 years ago

I think this gem is better maintained: https://github.com/janlelis/clipboard

flavorjones commented 5 years ago

This isn't going to work easily on Linux; not sure about macOS.

I've pushed a branch, 49-clipboard-availability, which pulls in the gems clipboard and ansi-to-html, and in it I convert the ANSIful text to HTML and then copy it to the clipboard.

The problem is (at least on Linux, and I think on macOS as well) that in order to paste properly into gmail in a browser, the mime type has to be set properly for the content.

On Linux, again, either using xsel or xclip (tried both (see https://github.com/janlelis/clipboard/blob/master/lib/clipboard/linux.rb)), it only has a text/plain mime type:

$ xclip -o -t TARGETS -selection clipboard
TIMESTAMP
TARGETS
MULTIPLE
SAVE_TARGETS
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/plain;charset=utf-8
text/plain

whereas when I copy-as-html the same text from my Gnome Terminal, I get:

$ xclip -o -t TARGETS -selection clipboard
TIMESTAMP
TARGETS
MULTIPLE
SAVE_TARGETS
UTF8_STRING
COMPOUND_TEXT
TEXT
STRING
text/plain;charset=utf-8
text/plain
text/html

Note text/html makes an appearance.

There doesn't appear to be a way to use xsel or xclip to set mime type, so I can't even hack the gem. Further, the man page for pbcopy (see https://github.com/janlelis/clipboard/blob/master/lib/clipboard/mac.rb for why that's relevant) reveals there are even fewer useful arguments than linux utilities, and so I'm assuming it will do the same thing and set only a text/plain mime type.

So I think we're stuck here unless we want to write our own library to set mime types natively.

flavorjones commented 5 years ago

Forgot to note: without the text/html mime type, I get this when I paste to gmail:

image

but with it, everything's fine:

image

flavorjones commented 5 years ago

Actually, resurrecting this because I can make it work on Linux

flavorjones commented 5 years ago

TODO: Consider figuring out how to make X and Pasteboard copy work from C and write extension code for Clipboard. See https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PasteboardGuide106/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008099

In the meantime, here's the version that works on Linux: branch 49-clipboard-availability