Friday 15 July 2011

keyboard shortcuts - Sublime Text 3 Key Binding - Using variables -



keyboard shortcuts - Sublime Text 3 Key Binding - Using variables -

i'm trying create key binding open favorite git application current sublime text 3 $project_path folder, somehow sublime text 3 doesn't convert variables actual path.

below can find current keyboard bindings file.

[ { "keys": ["super+ctrl+alt+g"], "command": "exec", "args": { "shell_cmd": "open -a gitbox $project_path" } } ]

$project_path doesn't convert actual project path... doing wrong? should utilize "build system" instead? looked build systems problem there have select scope of files (for illustration *.rb) , want keyboard shortcut valid all projects/files.

in textmate2 same shortcut achieved creating new "command" in bundle editor , assigning shortcut it. command be:

#!/usr/bin/ruby exec "open -a gitbox '#{env['tm_project_directory']}'"

so i'm trying accomplish same thing in sublime text 3 going wrong.

thanks!

i have spend few hours searching on same problem. after decided create little plugin own place holders.

import sublime, sublime_plugin class runappcommand(sublime_plugin.windowcommand): def run(self, app_args): app_args = self.fill_placeholder(app_args) self.window.run_command("exec", {"cmd": app_args } ) def fill_placeholder(self, args): res = [] proj_folder = self.get_project_folder() arg in args: arg = arg.replace("$project_folder", proj_folder) res.append(arg) homecoming res def get_project_folder(self,default=none): proj_folder = "" if self.window.project_file_name(): proj = self.window.project_data() proj_folder_obj = self.get_first(proj["folders"]) if proj_folder_obj: proj_folder = proj_folder_obj["path"] elif self.window.folders(): proj_folder = self.get_first(self.window.folders()) if not proj_folder: sublime.status_message("no project folder located") homecoming default homecoming proj_folder def get_first(self, iterable, default=none): if iterable: item in iterable: homecoming item homecoming default

after have saved code above packages/user/runapp.py can create command work adding next default.sublime-keymap:

{ "keys": ["super+ctrl+alt+g"], "command": "run_app", "args": { "app_args": ["open", "-a", "gitbox", "$project_folder"]}}

this may not best solution works me.

keyboard-shortcuts sublimetext3 gitbox

No comments:

Post a Comment