我如何知道我在 Sublime Text 中使用的是哪个项目?

How can I tell which project I'm using in Sublime Text?

我的机器上经常有同一个 Git 存储库的多个副本。我通常打开多个 Sublime Text windows,每个打开的项目都是 Git 回购副本之一。

是否有任何设置可以在状态栏或标题栏上显示项目文件的路径,或者可以通过其他方式轻松区分其他类似项目?事实上,我没有简单的方法来区分哪个 Sublime Text window 正在使用哪个项目文件。

Sublime 的标题栏默认会显示当前与window关联的项目的文件名部分;它是圆括号内当前 selected 文件名称右侧的文本。例如,这里我有当前打开的 OverrideAudit 项目:

(目前)无法在标题栏中显示其他信息,但使用一些插件代码,您可以在状态栏中显示文本。

[编辑] 问题跟踪器上有一个 open feature request 可以添加配置标题栏的功能,您可能想要权衡一下。 [/编辑]

这是一个插件示例,它复制了将 window 标题中的项目名称放入状态栏的过程。如果需要,您可以修改 show_project 中的代码,仅将项目名称隔离为例如如果需要,请包括路径。

要使用它,您可以从菜单中 select Tools > Developer > New Plugin... 并用此代码替换默认存根,并根据需要进行修改。

此代码为also available on GitHub

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)