├── LICENSE ├── README.markdown └── coda /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 Justin Hileman 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | coda-cli -- Shell integration for Coda 2 | ====================================== 3 | 4 | http://justinhileman.info/coda-cli 5 | 6 | 7 | `coda` makes Panic's Coda a first-class *nix citizen 8 | ---------------------------------------------------- 9 | 10 | This tool provides shell integration for [Coda](http://panic.com/coda). You can 11 | now open files and directories from a terminal: 12 | 13 | coda foo.html 14 | coda foo.html bar.css 15 | coda ./ 16 | 17 | If `foo.html` or `bar.css` doesn't exist, `coda` will create it automatically 18 | for you. 19 | 20 | You can also edit a file and wait for it to close (`-w` or `--wait`). This is 21 | really important if you plan on making `coda` your default `$EDITOR`. Now you 22 | can use Coda for writing Git or SVN commit messages. Simply add this line to 23 | your `.bash_profile` or `.bashrc` or `.zshrc`: 24 | 25 | export EDITOR='coda -w' 26 | 27 | In addition to knowing how to wait, `coda` plays nice with pipes. You can use 28 | it just like any other POSIX utility... Invoke it from the command line and pass 29 | the output from any command to Coda, or from Coda to another command. Try a 30 | couple of these: 31 | 32 | echo 'foo' | coda 33 | echo 'bar' | coda >> out.txt 34 | coda >> somefile.html 35 | find . -name "*.css" | xargs coda 36 | coda < config.yaml > config_new.yaml 37 | 38 | Note that piping output from coda implies `--wait`. 39 | 40 | 41 | Installation 42 | ------------ 43 | 44 | Make sure `coda` is executable and somewhere in your `$PATH`. The easiest way to 45 | do that is with [Homebrew](http://mxcl.github.com/homebrew/) ... 46 | 47 | brew update 48 | brew install coda-cli 49 | 50 | Or you can strike out on your own: 51 | 52 | mkdir -p /usr/local/bin 53 | curl https://raw.github.com/bobthecow/coda-cli/master/coda > /usr/local/bin/coda 54 | chmod 777 /usr/local/bin/coda 55 | 56 | 57 | Usage 58 | ----- 59 | 60 | coda --help 61 | 62 | 63 | License 64 | ------- 65 | 66 | * Copyright 2011 [Justin Hileman](http://justinhileman.com) 67 | * Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) 68 | -------------------------------------------------------------------------------- /coda: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | coda-cli -- Shell integration for Coda 4 | 5 | http://justinhileman.info/coda-cli 6 | 7 | 8 | `coda` makes Panic's Coda a first-class *nix citizen. 9 | 10 | This tool provides shell integration for Coda. You can now open files and 11 | directories from a terminal: 12 | 13 | coda foo.html 14 | coda foo.html bar.css 15 | coda ./ 16 | 17 | If `foo.html` or `bar.css` doesn't exist, `coda` will create it automatically 18 | for you. 19 | 20 | You can also edit a file and wait for it to close (`-w` or `--wait`). This is 21 | really important if you plan on making `coda` your default `$EDITOR`. Now you 22 | can use Coda for writing Git or SVN commit messages. Simply add this line to 23 | your `.bash_profile` or `.bashrc` or `.zshrc`: 24 | 25 | export EDITOR='coda -w' 26 | 27 | In addition to knowing how to wait, `coda` plays nice with pipes. You can use 28 | it just like any other POSIX utility... Invoke it from the command line and pass 29 | the output from any command to Coda, or from Coda to another command. Try a 30 | couple of these: 31 | 32 | echo 'foo' | coda 33 | echo 'bar' | coda >> out.txt 34 | coda >> somefile.html 35 | find . -name "*.css" | xargs coda 36 | coda < config.yaml > config_new.yaml 37 | 38 | Note that piping output from coda implies `--wait`. 39 | 40 | 41 | Usage: 42 | 43 | coda --help 44 | 45 | 46 | License: 47 | 48 | Copyright 2011 Justin Hileman - http://justinhileman.com 49 | Distributed under the MIT License - http://creativecommons.org/licenses/MIT/ 50 | 51 | """ 52 | import sys, os, time, commands, optparse, signal 53 | from tempfile import mkstemp 54 | from pipes import quote 55 | 56 | version = '1.0.5' 57 | 58 | if commands.getoutput("mdfind \"kMDItemCFBundleIdentifier == 'com.panic.Coda2'\"") != "": 59 | bundle_id = 'com.panic.Coda2' 60 | else: 61 | bundle_id = 'com.panic.Coda' 62 | 63 | parser = optparse.OptionParser( 64 | usage='Usage: %prog [options] [file ...]', 65 | epilog="To read input from stdin, use a pipe or pass `-` for [file] Piping output from coda implies `-w`." 66 | ) 67 | opts = ( 68 | ('-w', '--wait', {'action': 'store_true', 'default': False, 'help': 'wait for file to be closed'}), 69 | ('-d', '--change-dir', {'action': 'store_true', 'dest': 'chdir', 'default': False, 'help': "change Coda's working directory"}), 70 | ('-n', '--new-window', {'action': 'store_true', 'dest': 'new_window', 'default': False, 'help': "open in a new window"}), 71 | ('--ls-tabs', {'action': 'store_true', 'dest': 'lstabs', 'default': False, 'help': 'show all open tabs'}), 72 | ('--version', {'action': 'store_true', 'default': False, 'help': 'print version information and quit'}), 73 | ) 74 | for opt in opts: 75 | parser.add_option(*opt[:-1], **opt[-1]) 76 | parser.version = "%%prog: %s" % version 77 | 78 | (options, files) = parser.parse_args() 79 | 80 | # handle Ctrl+C gracefully 81 | signal.signal(signal.SIGINT, lambda *x: sys.exit(1)) 82 | 83 | def osascript(scpt): 84 | return commands.getoutput("osascript 2>/dev/null <