-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·48 lines (32 loc) · 1.03 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/env python3
import os
import yaml
import ranger.api
from ranger.core.linemode import LinemodeBase
CHECKMARK = os.getenv("RANGER_DOTDROP_CHECKMARK", " ✔")
DOTDROP_CONFIG = os.getenv("DOTDROP_CONFIG", "")
if DOTDROP_CONFIG:
with open(DOTDROP_CONFIG) as config:
config = yaml.safe_load(config)
files = [
os.path.expanduser(config["dotfiles"][file]["dst"]) for file in config["dotfiles"]
]
def add_files(files_new):
for file in files_new:
files.append(file)
def remove_files(files_new):
for file in files_new:
if file in files:
files.remove(file)
@ranger.api.register_linemode
class LinemodeDotdrot(LinemodeBase):
name = "dotdrop"
uses_metadata = False
def filetitle(self, file, metadata):
return file.relative_path + file_included(file.path, CHECKMARK)
def file_included(file, checkmark):
if DOTDROP_CONFIG == "" or file == "/":
return ""
if file in files:
return checkmark
return file_included(os.path.dirname(file), checkmark)