Last active
January 5, 2024 23:59
-
-
Save mikeri/1e70a103b906163725cd025b68a84851 to your computer and use it in GitHub Desktop.
Ranger plugin for storing metadata in extended file attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ranger plugin for storing metadata in extended file attributes | |
# Requires Python 3.3 | |
# drop it in ~/.config/ranger/plugins | |
from ranger.ext.openstruct import DefaultOpenStruct as ostruct | |
import ranger.core.metadata | |
import os | |
def get_metadata(_, filename): | |
attributes = os.listxattr(filename) | |
metadata = {} | |
for attribute in attributes: | |
if attribute.startswith("user."): | |
key = attribute[5:] | |
value = os.getxattr(filename, attribute) | |
metadata[key] = value.decode() | |
return ostruct(metadata) | |
def set_metadata(_, filename, update_dict): | |
for key in update_dict.keys(): | |
os.setxattr(filename, "user." + key, update_dict[key].encode()) | |
ranger.core.metadata.MetadataManager.get_metadata = get_metadata | |
ranger.core.metadata.MetadataManager.set_metadata = set_metadata |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment