dotfiles
1

Configure Feed

Select the types of activity you want to include in your feed.

Add support for sudo-installed dotfiles

Juan Nunez-Iglesias (Jun 25, 2026, 6:48 PM +0200) 42ac77f9 4373af55

+32 -1
+32 -1
dots
··· 19 19 import argparse 20 20 import difflib 21 21 import filecmp 22 + import os 22 23 import shutil 23 24 import sys 24 25 from datetime import datetime ··· 39 40 "cosmic/custom-shortcuts": HOME / ".config" / "cosmic" / "com.system76.CosmicSettings.Shortcuts" / "v1" / "custom", 40 41 "cosmic/system-actions": HOME / ".config" / "cosmic" / "com.system76.CosmicSettings.Shortcuts" / "v1" / "system_actions", 41 42 "sway": HOME / ".config" / "sway", 42 - "starship/starship.toml": HOME / ".config" / "starship.toml" 43 + "starship/starship.toml": HOME / ".config" / "starship.toml", 44 + "keyd/default.conf": Path("/etc/keyd/default.conf"), 43 45 } 44 46 45 47 REPO_DIR = Path(__file__).resolve().parent ··· 50 52 """Yield (relative_name, repo_path, system_path) for each tracked item.""" 51 53 for rel, sys_path in DOTFILES_MAP.items(): 52 54 yield rel, REPO_DIR / rel, sys_path 55 + 56 + 57 + def requires_root(sys_path: Path) -> bool: 58 + """A target needs root if it lives outside $HOME (e.g. /etc/...).""" 59 + try: 60 + sys_path.resolve().relative_to(HOME.resolve()) 61 + return False 62 + except ValueError: 63 + return True 64 + 65 + 66 + def running_as_root() -> bool: 67 + return hasattr(os, "geteuid") and os.geteuid() == 0 53 68 54 69 55 70 # -------------------------------------------------------------------------- ··· 87 102 timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") 88 103 snapshot_dir = BACKUP_ROOT / timestamp 89 104 made_backup = False 105 + is_root = running_as_root() 106 + skipped_for_privileges: list[tuple[str, bool]] = [] 90 107 91 108 for rel, src_repo, sys_path in rel_abs_sys_paths(): 109 + needs_root = requires_root(sys_path) 110 + if needs_root != is_root: 111 + skipped_for_privileges.append((rel, needs_root)) 112 + continue 113 + 92 114 if not src_repo.exists(): 93 115 print(f" skip: {rel} (not present in repo)") 94 116 continue ··· 124 146 if made_backup: 125 147 print(f"\nBackups saved under .backups/{timestamp}/") 126 148 149 + if skipped_for_privileges: 150 + rerun_as = "without sudo" if is_root else "with sudo" 151 + print(f"\nSkipped (re-run {rerun_as} to link these):") 152 + for rel, needs_root in skipped_for_privileges: 153 + tag = "needs sudo" if needs_root else "user-level" 154 + print(f" {rel} ({tag})") 155 + 127 156 128 157 # -------------------------------------------------------------------------- 129 158 # check: report current status ··· 152 181 ) 153 182 else: 154 183 status = "not installed" 184 + if requires_root(sys_path): 185 + status += " [sudo]" 155 186 print(f" {rel:<{width}} {status}") 156 187 157 188