Skip to content

Instantly share code, notes, and snippets.

@sheepmaster
Created June 26, 2015 11:01
Show Gist options
  • Select an option

  • Save sheepmaster/d87c6a673ea04c4e9d98 to your computer and use it in GitHub Desktop.

Select an option

Save sheepmaster/d87c6a673ea04c4e9d98 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import subprocess
import sys
import tempfile
def usage():
sys.stderr.write('Usage: %s [-s]\n' % os.path.basename(sys.argv[0]))
def main(args):
if len(args) > 1:
usage()
return 1
silent = False
if len(args) == 1:
if args[0] != '-s':
usage()
return 1
silent = True
(fd, name) = tempfile.mkstemp()
os.write(fd, sys.stdin.read())
if silent:
return subprocess.call(['subl', name])
returncode = subprocess.call(['subl', '-w', name])
if returncode != 0:
return returncode
with open(name) as handle:
sys.stdout.write(handle.read())
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment