2222import sys
2323from dataclasses import dataclass , field
2424from pathlib import Path
25- from typing import Any , Optional , Union
25+ from typing import Any , Optional , Tuple , Union
2626
2727try :
2828 import tomllib
@@ -970,22 +970,34 @@ def render(self, template_text: str) -> str:
970970
971971 return result
972972
973- def render_file (self , input_path : Path , output_path : Path ) -> bool :
973+ def render_file (self , input_path : Path , output_path : Path ) -> Tuple [ bool , bool ] :
974974 """Render a template file to an output path.
975975
976- Returns True if successful, False if skipped due to errors.
976+ Returns (success, wrote) where wrote is False if the file was skipped because
977+ content was already identical (avoids mtime bumps and app reloads).
977978 """
978979 self ._current_file = str (input_path )
979980 success = False
981+ wrote = False
980982 try :
981983 template_text = input_path .read_text ()
982984 rendered_text = self .render (template_text )
983985
984986 if self ._error_count > 0 :
985987 print (f"Skipping { output_path } : template has { self ._error_count } error(s)" , file = sys .stderr )
986988 else :
987- output_path .parent .mkdir (parents = True , exist_ok = True )
988- output_path .write_text (rendered_text )
989+ out = Path (output_path ).expanduser ()
990+ out .parent .mkdir (parents = True , exist_ok = True )
991+ skip_write = False
992+ if out .is_file ():
993+ try :
994+ if out .read_text () == rendered_text :
995+ skip_write = True
996+ except OSError :
997+ pass
998+ if not skip_write :
999+ out .write_text (rendered_text )
1000+ wrote = True
9891001 success = True
9901002 except FileNotFoundError :
9911003 self ._log_error (f"Template file not found: { input_path } " )
@@ -995,7 +1007,7 @@ def render_file(self, input_path: Path, output_path: Path) -> bool:
9951007 self ._log_error (f"Unexpected error: { e } " )
9961008 finally :
9971009 self ._current_file = None
998- return success
1010+ return success , wrote
9991011
10001012 # --- Custom Colors ---
10011013
@@ -1151,7 +1163,13 @@ def process_config_file(self, config_path: Path):
11511163 rendered_compare_to = self .render (compare_to )
11521164 self .closest_color = find_closest_color (rendered_compare_to , colors_to_compare )
11531165
1154- self .render_file (Path (input_path ).expanduser (), Path (output_path ).expanduser ())
1166+ ok , wrote = self .render_file (Path (input_path ).expanduser (), Path (output_path ).expanduser ())
1167+ if not ok :
1168+ continue
1169+
1170+ # Hooks reload external apps (e.g. Discord); skip when output unchanged
1171+ if not wrote :
1172+ continue
11551173
11561174 # Execute pre_hook if specified
11571175 pre_hook = template .get ("pre_hook" )
0 commit comments