Files
nemo-repo-columns/nemoRepoColumns.py
T
dualfroz 9b312fab91 refactor: rebuild as a column plugin on nemo-repo-core
Keeps only the ColumnProvider from the single file extension; the config, git and cache layers come from nemo-repo-core, so the columns share one git query with the other plugins in the family.

The status string moves to the shared RepoInfo.summary and is now plain ASCII: 2 ahead, 1 behind instead of arrow glyphs. Both columns can be turned off in the config.
2026-08-05 20:07:00 +02:00

99 lines
3.3 KiB
Python

#!/usr/bin/python3
"""nemo-repo-columns: "Git Branch" and "Git Status" columns for Nemo.
Enable them per folder through Nemo's own "Visible Columns" dialog, or
globally under Edit > Preferences > List View. Values are filled in for
repository roots and left blank everywhere else.
Requires nemo-repo-core: https://github.com/dualfroz/nemo-repo-core
"""
import importlib.util
import os
import sys
def _ensureCoreOnPath():
if importlib.util.find_spec("nemoRepoCore") is not None:
return
dataHome = os.environ.get("XDG_DATA_HOME") or os.path.expanduser("~/.local/share")
dataDirs = (os.environ.get("XDG_DATA_DIRS") or "/usr/local/share:/usr/share").split(":")
for base in [dataHome] + dataDirs:
candidate = os.path.join(base, "nemo-repo-core")
if os.path.isdir(os.path.join(candidate, "nemoRepoCore")):
sys.path.insert(0, candidate)
return
_ensureCoreOnPath()
import gi
gi.require_version("Nemo", "3.0")
from gi.repository import GObject, Nemo
from nemoRepoCore import (coreConfig, findRepoRoot, localDirectoryPath,
repoCache, requireCore)
requireCore("1.0.0")
branchAttribute = "repo_branch"
statusAttribute = "repo_status"
pluginDefaults = {
"columns": {
"branch": True,
"status": True,
},
}
coreConfig.registerDefaults(pluginDefaults)
class RepoColumnProvider(GObject.GObject, Nemo.ColumnProvider,
Nemo.InfoProvider, Nemo.NameAndDescProvider):
def get_columns(self):
"""Columns are read once, when Nemo loads the extension.
Turning one off in the config therefore needs a Nemo restart, unlike
every other setting in this family.
"""
columns = []
if coreConfig.sectionFlag("columns", "branch", True):
columns.append(Nemo.Column(name="NemoRepoColumns::branch",
attribute=branchAttribute,
label="Git Branch",
description="Checked out branch of the repository"))
if coreConfig.sectionFlag("columns", "status", True):
columns.append(Nemo.Column(name="NemoRepoColumns::status",
attribute=statusAttribute,
label="Git Status",
description="Sync state with the upstream plus working tree state"))
return columns
def update_file_info(self, file):
path = localDirectoryPath(file)
if path is None:
return
repoRoot = findRepoRoot(path)
if repoRoot is None:
file.add_string_attribute(branchAttribute, "")
file.add_string_attribute(statusAttribute, "")
return
repoCache.registerFileObject(repoRoot, file)
info = repoCache.get(repoRoot)
if info.error:
file.add_string_attribute(branchAttribute, "?")
file.add_string_attribute(statusAttribute, info.error)
return
file.add_string_attribute(branchAttribute, info.branchLabel)
file.add_string_attribute(statusAttribute, info.summary)
def get_name_and_desc(self):
return ["nemo-repo-columns:::Git Branch and Git Status columns for the list view"]