我的機器上經常有相同的Git倉庫的多個副本。我通常會打開多個Sublime Text窗口,每個窗口都有一個Git repo副本的打開項目。如何判斷我在Sublime Text中使用哪個項目?
是否有任何設置可以在狀態欄或標題欄上顯示項目文件的路徑,或者是否可以輕鬆區分其他類似項目?事實上,我沒有簡單的方法來區分哪個Sublime Text窗口正在使用哪個項目文件。
我的機器上經常有相同的Git倉庫的多個副本。我通常會打開多個Sublime Text窗口,每個窗口都有一個Git repo副本的打開項目。如何判斷我在Sublime Text中使用哪個項目?
是否有任何設置可以在狀態欄或標題欄上顯示項目文件的路徑,或者是否可以輕鬆區分其他類似項目?事實上,我沒有簡單的方法來區分哪個Sublime Text窗口正在使用哪個項目文件。
Sublime的標題欄會默認顯示當前與窗口關聯的項目的文件名部分;它是當前選定文件名稱右邊的文本,位於圓括號內。例如,在這裏我有OverrideAudit
項目當前打開的:
有沒有辦法,(目前)顯示在標題欄等信息,但使用一些插件代碼可以顯示在狀態欄中的文本,而不是。
[編輯]問題跟蹤器上有一個open feature request,用於添加配置標題欄的功能,您可能需要權衡該標題欄。 [/編輯]
下面是一個插件的示例,它複製將窗口標題中的項目名稱放入狀態欄。如果需要,您可以修改show_project
中的代碼,該代碼僅將項目名稱隔離爲如果需要,請包含路徑。
要使用此功能,您可以從菜單中選擇Tools > Developer > New Plugin...
,並使用此代碼替換默認存根,根據需要進行修改。
import sublime
import sublime_plugin
import os
# Related Reading:
# https://forum.sublimetext.com/t/displaying-project-name-on-the-rite-side-of-the-status-bar/24721
# This just displays the filename portion of the current project file in the
# status bar, which is the same text that appears by default in the window
# caption.
def plugin_loaded():
"""
Ensure that all views in all windows show the associated project at startup.
"""
# Show project in all views of all windows
for window in sublime.windows():
for view in window.views():
show_project (view)
def show_project(view):
"""
If a project file is in use, add the name of it to the start of the status
bar.
"""
if view.window() is None:
return
project_file = view.window().project_file_name()
if project_file is not None:
project_name = os.path.splitext (os.path.basename (project_file))[0]
view.set_status ("00ProjectName", "[" + project_name + "]")
class ProjectInStatusbar(sublime_plugin.EventListener):
"""
Display the name of the current project in the status bar.
"""
def on_new(self, view):
show_project (view)
def on_load(self, view):
show_project (view)
def on_clone(self, view):
show_project (view)