diff --git a/install.py b/install.py index d542682..aef7bed 100755 --- a/install.py +++ b/install.py @@ -258,24 +258,31 @@ class Installer: src_full.symlink(p_dest) - def do_append(self, dest: str, content: str) -> None: + def do_append(self, dest: str, content: str, condition: str = "true") -> None: """Append to a file.""" - self._do_write(dest, content, append=True) + self._do_write(dest, content, condition=condition, append=True) - def do_write(self, dest: str, content: str) -> None: + def do_write(self, dest: str, content: str, condition: str = "true") -> None: """Write into a file.""" - self._do_write(dest, content, append=False) + self._do_write(dest, content, condition=condition, append=False) - def _do_write(self, dest: str, content: str, *, append: bool) -> None: + def _do_write( + self, dest: str, content: str, *, condition: str, append: bool + ) -> None: p_dest = Path(dest).expanduser() pretty_dest = self.pretty_path(p_dest) - if p_dest.exists() and not self.force and not append: + if not self.evaluate_condition(condition): ui.info_2("Skipping", pretty_dest) return + if p_dest.exists() and not self.force and not append: + if not ui.ask_yes_no(f"{pretty_dest} already exists. Overwrite?"): + ui.info_2("Skipping", pretty_dest) + return + ui.info_2("Creating", pretty_dest) p_dest.parent.makedirs_p() content = content.format(base_dir=self.base_dir, home=self.home)