Skip to content

Instantly share code, notes, and snippets.

@yields
Created June 14, 2013 16:36
Show Gist options
  • Save yields/5783382 to your computer and use it in GitHub Desktop.
Save yields/5783382 to your computer and use it in GitHub Desktop.
a tiny sublime plugin to create files and folders quickly
#
# a tiny sublime plugin to create files and folders quickly:
#
# copy and paste this to you're sublime packages/user folder
# and add a shortcut with the command `touch` to you're sublime keybindings.
#
# Example:
#
# ../baz/foo.js
# /baz/baz.foo.js
# test.js
#
# do what the fuck you want license.
#
#
# imports
import sublime_plugin
import sublime
import os
#
# error with <ms>
def error(ms):
sublime.error_message(ms)
#
# Get path for <name> with <path>
def pathize(view, name):
if '/' != name[0]:
abs = os.path.dirname(view.file_name())
else:
abs = view.window().folders()[0]
name = name[1:]
return os.path.join(abs, name)
#
# touch
class Touch(sublime_plugin.WindowCommand):
def run(self):
show = self.window.show_input_panel
show('touch', '', self.ondone, self.onchange, self.oncancel)
def ondone(self, name):
view = self.window.active_view()
path = pathize(view, name)
try:
os.makedirs(os.path.dirname(path))
except:
pass
self.window.open_file(path)
def onchange(self):
pass
def oncancel(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment