-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_new_file.py
33 lines (25 loc) · 1.12 KB
/
create_new_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import sublime
import sublime_plugin
import os
class CreateNewFileCommand(sublime_plugin.TextCommand):
def run(self, edit):
assert self.view.file_name() is not None, sublime.error_message(
'expected at least a base view/file opened')
filename_selections = [self.view.substr(region)
for region in self.view.sel()
if self.view.substr(region)]
if filename_selections:
for filename in filename_selections:
self.create_new_file(filename)
else:
self.view.window().show_input_panel('Create New File', '.py',
self.on_done,
None,
None)
def on_done(self, filename):
self.create_new_file(filename)
def create_new_file(self, filename):
filepath = os.path.join(os.path.dirname(self.view.file_name()),
filename)
filepath = filepath.replace(' ', '\\ ')
os.system('subl {}'.format(filepath))