c0b283c76b70a438759fb58935e2eeb3c5bb4fea

Author
Robby Russell <robby@planetargon.com>
Committer
Robby Russell <robby@planetargon.com>
Date

Message

Merge pull request #3833 from coopermaruyama/master

coffeescript aliases for easy compiling

Diff

 1diff --git a/plugins/coffee/README.md b/plugins/coffee/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..d0e7bbe74b59716d99bdd103c7f229d8b1119ebb
 4--- /dev/null
 5+++ b/plugins/coffee/README.md
 6@@ -0,0 +1,31 @@
 7+## Coffeescript Plugin
 8+
 9+This plugin provides aliases for quickly compiling and previewing your
10+cofeescript code.
11+
12+When writing Coffeescript it's very common to want to preview the output of a
13+certain snippet of code, either because you want to test the output or because
14+you'd like to execute it in a browser console which doesn't accept Coffeescript.
15+
16+Preview the compiled result of your coffeescript with `cf "code"` as per the
17+following:
18+
19+```zsh
20+$ cf 'if a then be else c'
21+if (a) {
22+  b;
23+} else {
24+  c;
25+}
26+```
27+
28+Also provides the following aliases:
29+
30+* **cfc:** Copies the compiled JS to your clipboard. Very useful when you want
31+           to run the code in a JS console.
32+
33+* **cfp:** Compiles from your currently copied clipboard. Useful when you want 
34+           to compile large/multi-line snippets
35+
36+* **cfpc:** Paste coffeescript from clipboard, compile to JS, then copy the
37+            the result back to clipboard.
38diff --git a/plugins/coffee/coffee.plugin.zsh b/plugins/coffee/coffee.plugin.zsh
39new file mode 100644
40index 0000000000000000000000000000000000000000..1a7bedd87fe9426f18c00e9f99bbc269a194406d
41--- /dev/null
42+++ b/plugins/coffee/coffee.plugin.zsh
43@@ -0,0 +1,16 @@
44+#!/bin/zsh
45+
46+# compile a string of coffeescript and print to output
47+cf () {
48+  coffee -peb $1
49+}
50+# compile & copy to clipboard
51+cfc () {
52+  cf $1 | pbcopy
53+}
54+
55+# compile from pasteboard & print
56+alias cfp='coffeeMe "$(pbpaste)"'
57+
58+# compile from pasteboard and copy to clipboard
59+alias cfpc='cfp | pbcopy'