This is mostly possible; Text can be added to the status bar although you can’t specify an exact position, and (as far as I am aware) it is not possible to change the color of the text or add an image (e.g. a colored dot).
A simplistic example of this is the following plugin code, which you can save in your Packages\User
folder as something like project_in_statusbar.py
(use Preferences > Browse Packages
if you don’t know where that location is):
[edit]
The code below is modified from the original version I posted so that it includes plugin_loaded
method that applies the project name to all views in all windows when Sublime initially starts, since event handlers do not trigger at this time.
It’s also modified to put the project name at the left of the status bar instead of the right, and the project name is slightly different (I find it easier to distinguish with it wrapped in square brackets).
[/edit]
import sublime
import sublime_plugin
import os
def plugin_loaded ():
# 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):
# Is there a project file defined?
project_file = view.window ().project_file_name ()
if project_file is not None:
# Get the project filename without path or extension
project_name = os.path.splitext (os.path.basename (project_file))[0]
view.set_status ("00ProjectName", "[" + project_name + "]")
# Display the current project name in the status bar
class ProjectInStatusbar(sublime_plugin.EventListener):
# When you create a new empty file
def on_new(self, view):
show_project (view)
# When you load an existing file
def on_load(self, view):
show_project (view)
# When you use File > New view into file on an existing file
def on_clone(self, view):
show_project (view)
The key to this is the call to view.set_status()
. This adds text to the status bar, where we add the text Project:
and the name of the current project file without any path or extension. This could be modified to make the text stand out more, such as forcing the name to upper case or wrapping it in [
and ]
.
The text can’t be positioned at the far right of the bar, though. Sublime sets aside a single part of the status bar for plugins to add text to, and it orders the text added alphabetically by the key
that is provided, which here is zzProjectName
to try and push it alphabetically to the end of the list.
This puts the text as far right as you can get it, although it still appears to the left of the text that shows you what line and column you are currently at in the file.