Reputation: 329
How can I automatically close files/tabs in sublime text 2 or 3 from the previous branch on git checkout of new branch? I couldn't find any plugins for this. I have tried sublimegit, git,savvygit plugins. But whenever I change branch or checkout a new branch, the files (tabs) that don't exist in the new branch remain open and marked unsaved. I find this a little confusing. Any solutions?
Upvotes: 1
Views: 775
Reputation: 4847
The solution could be to write a plugin, which closes the views for which the corresponding file does not exists. This does not interact with svn or gut, but should have your desired behavior in the most cases. However be careful, that you don't have text only in ST without saving it in a file. Press Tools >> Developer >> New Plugin...
and paste:
import os
import sublime_plugin
class CloseUnsavedFilesCommand(sublime_plugin.WindowCommand):
def run(self):
window = self.window
for v in window.views():
file_name = v.file_name()
if file_name and not os.path.exists(file_name):
print("Close: '{0}'".format(file_name))
v.set_scratch(True)
window.focus_view(v)
window.run_command("close")
Now open the console ctrl+`
and write window.run_command("close_unsaved_files")
or create a keybinding for close_unsaved_files
.
Upvotes: 4