def add_history(self, x: str) -> None: hl = history_list() with suppress(ValueError): hl.remove(x) hl.append(x) del hl[:-50] atomic_save('\n'.join(hl).encode('utf-8'), history_path())
def update_theme_file(path: str) -> bool: with open(path) as f: raw = f.read() td = parse_theme(os.path.basename(path), raw, exc_class=ValueError) if 'upstream' not in td: return False nraw = urlopen(td['upstream']).read().decode('utf-8') if raw == nraw: return False atomic_save(nraw.encode('utf-8'), path) return True
def save_in_conf(self, confdir: str, reload_in: str) -> None: atomic_save(self.raw.encode('utf-8'), os.path.join(confdir, 'current-theme.conf')) confpath = os.path.realpath(os.path.join(confdir, 'kitty.conf')) try: with open(confpath) as f: raw = f.read() except FileNotFoundError: raw = '' nraw = patch_conf(raw, self.name) if raw: with open(confpath + '.bak', 'w') as f: f.write(raw) atomic_save(nraw.encode('utf-8'), confpath) if reload_in == 'parent': if 'KITTY_PID' in os.environ: os.kill(int(os.environ['KITTY_PID']), signal.SIGUSR1) elif reload_in == 'all': reload_conf_in_all_kitties()
def save_in_dir(self, dirpath: str) -> None: atomic_save(self.raw.encode('utf-8'), os.path.join(dirpath, f'{self.name}.conf'))