Show HN: Copy any code to clipboard in OS X, adding proper syntax highlighting
github.com
github.com
I use this to style code I then paste code into presentation slides in order to include pretty code samples on a slide without resorting to screenshots; it has infinite resolution, and someone can copy it from the presentation file or PDF later. I presume this tool would be great for similar uses.
“Be sure to create the ellipsis character using the key combination Option-; (Option-semicolon). This ensures that an assistive app can provide the correct interpretation of the character to a disabled user. If you use three period characters to simulate an ellipsis, many assistive apps will be unable to make sense of them. Also, three period characters and an ellipsis don't look the same because the periods are spaced differently than the points of an ellipsis.”
Of course, Apple’s advice for typing U+2026 HORIZONTAL ELLIPSIS (…) (typing ⌥;) is only accurate if you’re using a US keyboard layout. The key combination will be different in other keyboard layouts. For example, in the 'Canadian French - CSA' keyboard layout, typing ⌥; will give you U+00B0 DEGREE SIGN instead (which makes sense if you actually look at a French ISO layout keyboard, like this² one or this³ one). On that keyboard layout, to get U+2026 HORIZONTAL ELLIPSIS, you’d actually type ⌥⇧L (option-shift-L).
¹ — https://developer.apple.com/library/mac/documentation/UserEx...
――――――
¹ — https://macheist.com/bundle
² — http://f.cl.ly/items/0p330J1Y3K2v0N1t2M2p/popchar_shortcut.p...
I actually think I'll stick to the command-line/pipeable script you link to...for teaching purposes, I've wanted to make myself a utility that converts syntax-higlighted code into a PNG...so that I can show the code but make it much more difficult to just copy/paste.
edit: And of course, the thing that I want, someone has already made and yet I couldn't even bother to RTFM. From running `highlight --h` at the command line:
SVG output options:
--height set image height (units allowed)
--width set image width (see --height)Also, this kind of thing already exists:
I want people to see my code, but I want to remove as many of the conveniences that enable them to just copy-paste that I can -- while not severely hindering my own ability to write and maintain lessons (once code is in PNG...it's quite difficult to grep and/or re-edit), because I believe having to just physically type out code slows you enough that you actually think about the code.
Also, having to type out code pretty much forces you to get into the habit of using keyboard shortcuts, particularly auto-complete.
Too often, beginners (and frankly, experienced programmers such as myself) believe that they truly understand a snippet of code just because they read it. And being beginners, they lack the discipline and the wisdom to know that code is not just human-readable machine instructions, to be read as if it were a stilted essay, but something to be interactively tested and changed.
Also, those new to coding don't realize that copying/reusing code is just fine. But understanding what it does before you attempt to re-use it -- that's the challenge.
–———
Somewhat relatedly, it's sometimes annoying how OS X love preserving styles when copying text. I may be misremembering, but I think text copied from Terminal.app uses your terminal font.
What version of OS X are you using? Are you using an Mac-oriented keyboard (ctrl/option/command) or a Windows-oriented keyboard (ctrl/windows/alt)? Also keep in mind, if you haven’t already tested it out on multiple computers, it could be the keyboard itself that’s dying.
(I’ve never experienced the issue. I actually do use a Windows-based keyboard on my Mac, but I use it with ControllerMate¹ (swapped the Windows key and alt key and changed the functions of all the nonstandard keys (multimedia keys, zooming in and out keys, Windows Flip 3D key, etc.)).
――――――
I'm using a Mac keyboard layout. I know that Alt is in a different place on Windows layouts, but that's a different problem.
I’ve used many OS Xs over the years (Mac OS X v10.3 Panther, Mac OS X v10.4 Tiger, Mac OS X v10.5 Leopard, OS X v10.8 Mountain Lion, OS X v10.9 Mavericks, and OS X v10.11 El Capitan), and each time I’ve had to upgrade, I’ve always done a clean install (just in case, which I’d say probably spared me from a lot of potential issues). Assuming this is a software problem, when you end up needing to upgrade again, I’d recommend trying to do a clean install instead of just upgrading your previous installation (so that this issue doesn’t just carry over to the upgrade).
Also, though it probably won't matter for most people, Acorn's file format is pretty ingenious: http://shapeof.com/archives/2013/4/we_need_a_standard_layere...
Incidentally, there's also a bunch of extra Dropbox files that you probably don't want to be including. It looks like you developed this on a Mac, saved it to Dropbox and then created the Zip on a Windows box.
Sorry to say it, but the whole thing feels like an amateurish wrapper around:
pbpaste | /usr/local/bin/pygmentize -g -O style=... -f rtf -l ... | pbcopy
which appears to do all the work.The tool is essentially a wrapper. I do not deny that in the credits.
However, there's nothing wrong with that. It's simple, yes, but it does what it promises. (Additionally, it still took a couple hours in QA and README presentation)
There shouldn't be Dropbox metadata though. I'll double-check that.
I think you're conflating two separate things, source code and a packaged releases. The Github repository should have the source code, which in your case is the XML code for the workflow and plist. You then create a release [1] from that software. It's usually customary to include the script used to build it, which in this case is likely just a shell script wrapper around the zip command to create the archive.
The important point is that the source is always visible. Uploading zip files into the repo gives the impression that you're trying to hide something, even if that isn't the case. Also, one of the great things about open source is that people can be curious. It's likely that if you had checked in the unzipped files, people would have browsed through them in the Github UI to see how it worked. Fewer people will take the time to clone the repo or download/unzip/browse the zip file.
Could you please let me know how you created the second gif in the the README?
- Mike
I guess one advantage of using a single command is that you can select, right-click the selection and run the service, and then paste. OTOH, I would probably end up doing a normal copy with command-C, pasting with command-V, and then having to do it again because I forgot to do the special copy.
OTOH, if you're going to have a combination command, it seems that it's more common to have special behavior in the paste operation rather than in the copy one. See "Paste and Match Styles", "Paste Special" etc.
No big deal in any case, I was just wondering what the rationale was behind the UI choice.