Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 61a30ea7136aebc37e69bafabcf35332a5876000 @jnordberg committed Sep 20, 2011
Showing with 33 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +29 −0 ColorPick.py
  3. +3 −0 Default (OSX).sublime-keymap
  4. BIN bin/colorpick
1 .gitignore
@@ -0,0 +1 @@
+*.pyc
29 ColorPick.py
@@ -0,0 +1,29 @@
+import sublime, sublime_plugin
+import subprocess
+from os import path
+
+class ColorPickCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ view = self.view
+ sel = view.sel()
+ selected = None
+
+ # get the currently selected color - if any
+ if len(sel) > 0:
+ selected = view.substr(view.word(sel[0])).strip()
+ if selected.startswith('#'): selected = selected[1:]
+
+ # get new color from picker
+ args = [path.join(sublime.packages_path(), 'ColorPick', 'bin', 'colorpick')]
+ if selected != None and len(selected) == 6:
+ args.append('-startColor')
+ args.append(selected)
+ proc = subprocess.Popen(args, stdout=subprocess.PIPE)
+ color = proc.communicate()[0]
+
+ # replace all regions with color
+ for region in sel:
+ word = view.word(region)
+ if view.substr(word.a - 1) == '#':
+ word = sublime.Region(word.a - 1, word.b)
+ self.view.replace(edit, word, color)
3 Default (OSX).sublime-keymap
@@ -0,0 +1,3 @@
+[
+ { "keys": ["super+shift+c"], "command": "color_pick" }
+]
BIN bin/colorpick
Binary file not shown.

0 comments on commit 61a30ea

Please sign in to comment.