Browse Source

Merge pull request #3833 from coopermaruyama/master

coffeescript aliases for easy compiling
Robby Russell 9 years ago
parent
commit
c0b283c76b
2 changed files with 47 additions and 0 deletions
  1. 31 0
      plugins/coffee/README.md
  2. 16 0
      plugins/coffee/coffee.plugin.zsh

+ 31 - 0
plugins/coffee/README.md

@@ -0,0 +1,31 @@
+## Coffeescript Plugin
+
+This plugin provides aliases for quickly compiling and previewing your
+cofeescript code.
+
+When writing Coffeescript it's very common to want to preview the output of a
+certain snippet of code, either because you want to test the output or because
+you'd like to execute it in a browser console which doesn't accept Coffeescript.
+
+Preview the compiled result of your coffeescript with `cf "code"` as per the
+following:
+
+```zsh
+$ cf 'if a then be else c'
+if (a) {
+  b;
+} else {
+  c;
+}
+```
+
+Also provides the following aliases:
+
+* **cfc:** Copies the compiled JS to your clipboard. Very useful when you want
+           to run the code in a JS console.
+
+* **cfp:** Compiles from your currently copied clipboard. Useful when you want 
+           to compile large/multi-line snippets
+
+* **cfpc:** Paste coffeescript from clipboard, compile to JS, then copy the
+            the result back to clipboard.

+ 16 - 0
plugins/coffee/coffee.plugin.zsh

@@ -0,0 +1,16 @@
+#!/bin/zsh
+
+# compile a string of coffeescript and print to output
+cf () {
+  coffee -peb $1
+}
+# compile & copy to clipboard
+cfc () {
+  cf $1 | pbcopy
+}
+
+# compile from pasteboard & print
+alias cfp='coffeeMe "$(pbpaste)"'
+
+# compile from pasteboard and copy to clipboard
+alias cfpc='cfp | pbcopy'