2012-08-29 4 views
4

내 홈 폴더에서 특정 (점 구성) 파일을 열려면 간단한 sublime-command를 원합니다. $ {packages}와 같이 사용할 수있는 변수 나 다른 마법이 사용자의 홈 폴더에 있습니까?숭고한 텍스트 2에서 홈 경로에 액세스 명령

은 현재 내가 (Default.sublime-명령)

{ 
    "caption": "Edit my config", 
    "command": "open_file", 
    "args": { 
     "file": "/Users/MyName/.myconfig" 
    } 
} 

을 가지고 있지만 하드 코드 된 사용자 이름을 제거하고 싶습니다.

불행히도 나는 API의 "문서"에서 숭고한 것을 찾을 수 없습니다.

은 다음과 같이 정의 명령을 사용하여 수행 할 수 있습니다
+0

작동 여부는 모르겠지만 "file": sublime.packages_path() + "Users/MyName /. myconfig "를 args 섹션에서 사용합니다 –

+0

$ {packages}로 가능하지만 $ {home} (사용자의 집에서는 작동하지 않음)과 같은 패키지 경로를 갖고 싶지 않습니다. 국장님. –

+0

아마 하드 코드입니까? –

답변

1

:

import sublime_plugin, getpass 

class OpenCustomFileCommand(sublime_plugin.WindowCommand): 
    def run(self, file_name): 
    if("{username}" in file_name): 
     file_name = file_name.replace("{username}", getpass.getuser()) 
    self.window.open_file(file_name) 

을 다음과 같은 (Default.sublime-명령) :

{ 
    "caption": "Edit my config", 
    "command": "open_custom_file", 
    "args": { "file_name": "/Users/{username}/.myconfig" } 
} 

물론 당신은 OpenCustomFileCommand을 확장 할 수 있습니다 자신의 대체품.

P. 명령은 ST2의 Packages 디렉토리에 저장해야합니다. 즉, 파일 open_custom_file.py

관련 문제