sublime_merge
sublime_merge copied to clipboard
Open Project instead of Folder in Sublime Text
Problem description
Opening a Sublime Project from a repository that I have open is unnecessarily hard and currently requires opening the repository's folder, then finding and opening the sublime-project file in it.
Preferred solution
I would like the Open Repository In Sublime Text action to check if there is a file named <repo name>.sublime-project at the top level, and if so, tell Sublime Text to open that instead of the folder.
Alternatives
Sublime Text could instead do this search when asked to open a folder.
I think this is a duplicate of #1142
I wrote an AutoHotkey launcher on Windows that does that for any file I open. For Sublime Merge, just point the Editor Path to this launcher. For better opening of files in a shell, use sublime instead of subl. For better opening of files from explorer, associate your file types with the launcher.
Basically:
sublime.exe D:\path\to\file.txt will look traverse up the tree, looking for *.sublime-project files and open the file in that project if it finds one. Otherwise, it uses a default project. Added nice touch, If it finds a *.sublime-project-symlink file, it reads the first line and uses that as the project file (lets you have different folders side by side, some in one project, some in another).
If it's useful, I'll move a couple of vars into an ini file and build it for simple reuse.
Here's the code if you want to build/tweak it yourself or use the logic to implement similar in a bash script or something else:
#NoEnv
#NoTrayIcon
exe:=A_ScriptDir . "\SublimeText\App\subl.exe"
file_path=%1%
; Look for sublime-project files in the parent dirs of a file and open the file in that project
project_path:=file_path
Loop, 50{
; Walk up the dirs
SplitPath, project_path, , project_path
project_file:=""
Loop, Files, % project_path . "\*.sublime-project*", F
{
project_file:=A_LoopFilePath
break
}
If RegExMatch(project_file, "-symlink$")>0{
FileReadLine, project_file, % project_file, 1
break
}
If FileExist(project_file){
break
}
; we're at the root of the drive and didn't find a project file, so use the default
If(SubStr(project_path,0,1) == ":"){
project_file:="D:\default_project.sublime-project"
break
}
}
; subl.exe --project "D:\development\my_code\my_project.sublime-project" "D:\development\my_code\docs\notes.rst[:line[:col]]"
cmd:="""" . exe . """ --project """ . project_file . """ """ . file_path . """"
; MsgBox, 64, CMD, % cmd
; Clipboard:=cmd
RunWait, % cmd
ExitApp, % ErrorLevel