Skip to content

Instantly share code, notes, and snippets.

@thachnuida
Created April 11, 2018 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thachnuida/b9f113f2ae67a58c16031f5ad434cf25 to your computer and use it in GitHub Desktop.
Save thachnuida/b9f113f2ae67a58c16031f5ad434cf25 to your computer and use it in GitHub Desktop.
Auto insert import other js files in current folder to current file
# Add to key binding { "keys": ["ctrl+1"], "command": "require_js_files"}
import sublime
import sublime_plugin
import os
class RequireJsFilesCommand(sublime_plugin.TextCommand):
def run(self, edit):
current_folder = os.path.dirname(self.view.file_name())
current_file_name = os.path.basename(self.view.file_name())
for file in os.listdir(current_folder):
if file.endswith('.js') and file != current_file_name:
self.view.insert(edit, 0, "import _name_ from './{0}';\n".format(os.path.splitext(file)[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment