2017-03-12 1 views
0

동일한 이름과 확장명을 가진 여러 하위 파일과 폴더를 만드는 명령을 만들 수 있습니까? 나는 "바탕 화면 헤더"의 이름으로 명령 및 유형을 열 것입니다 예를 들어Sublime Text : 하나의 명령으로 여러 개의 하위 파일이있는 폴더 만들기

결과는 (폴더)

  • 다음 생성되는

    바탕 헤더 것 데스크탑 header.js

  • 데스크탑 header.php
  • _desktop-header.sass

나는 BEM을 따라 왔으며 결국 모든 블록을 수동으로 생성해야합니다.

답변이 있는지 검색하려면 무엇을해야할지 모르겠습니다.

감사합니다.

답변

2

예, 임의의 파이썬 코드를 a 명령에 쓸 수 있습니다. Tools> Developer> New Plugin ...을 선택하고 다음 코드를 붙여 넣으십시오. 이렇게하면 현재보기에 비해 상대적으로 3 개의 파일이 들어있는 폴더가 만들어집니다.

{ 
    "keys": ["alt+shift+b"], 
    "command": "create_bem_files", 
}, 
:

import os 

import sublime 
import sublime_plugin 


class CreateBemFilesCommand(sublime_plugin.WindowCommand): 
    def run(self): 
     window = self.window 
     view_path = window.active_view().file_name() 
     if not view_path: 
      sublime.error_message("Save your file first.") 
      return 
     base_folder_path, _ = os.path.split(view_path) 

     def on_done(name): 
      folder_path = os.path.join(base_folder_path, name) 
      # add your file names 
      file_names = [ 
       name + ".js", 
       name + ".php", 
       "_" + name + ".sass" 
      ] 
      file_paths = [ 
       os.path.join(folder_path, file_name) 
       for file_name in file_names 
      ] 
      # create the folder 
      os.makedirs(folder_path, exist_ok=True) 
      # create the files 
      for file_path in file_paths: 
       with open(file_path, "a"): 
        pass 
       # open the files in Sublime Text 
       window.open_file(file_path) 

     window.show_input_panel(
      "Input the folder name", "", on_done, None, None) 

나중에이 같은 키 바인딩을 만들

관련 문제