def main(self, arguments, *, reload=False, message=False): tools_requirements("zsh", "vim", "git") create_zshrc_not_exists(f". $HOME/.{package.info['pkg_name']}/init", self.zsh_rc) snakypy_path_create(self.config_root) create_config(config_content, self.config_file) snakypy_file_create(set_zshpower_content, self.init_file, force=True) if arguments["--omz"]: omz_install(self.omz_root) omz_install_plugins(self.omz_root, self.plugins) create_zshrc(zshrc_content, self.zsh_rc) change_theme_in_zshrc(self.zsh_rc, f"{package.info['pkg_name']}") add_plugins_zshrc(self.zsh_rc) snakypy_file_create(set_zshpower_content, self.theme_file, force=True) install_fonts(self.HOME) change_shell() printer("Done!", foreground=FG.FINISH) if message else None if not arguments["--omz"] and not get_line_source(self.zsh_rc): printer(instruction_not_omz, foreground=FG.YELLOW) reload_zsh() if reload else None
def create_config(content, file_path, force=False): if not exists(file_path) or force: parsed_toml = toml_parse(content) write_toml = toml_dumps(parsed_toml) snakypy_file_create(write_toml, file_path, force=force) return True return
def add_plugins_zshrc(zshrc): plugins = ( "python", "django", "pip", "pep8", "autopep8", "zsh-syntax-highlighting", "zsh-autosuggestions", ) current = plugins_current_zshrc(zshrc) new_plugins = [] for plugin in plugins: if plugin not in current: new_plugins.append(plugin) if len(new_plugins) > 0: current_zshrc = read_zshrc(zshrc) plugins = f'plugins=({" ".join(current)} {" ".join(new_plugins)})' new_zsh_rc = re_sub(rf"^plugins=\(.*", plugins, current_zshrc, flags=re_m) snakypy_file_create(new_zsh_rc, zshrc, force=True) return new_zsh_rc return
def create_zshrc(content, zshrc): if exists(zshrc): if not read_zshrc_omz(zshrc): shutil_copyfile(zshrc, f"{zshrc}-{datetime.today().isoformat()}") snakypy_file_create(content, zshrc, force=True) return True elif not exists(zshrc): snakypy_file_create(content, zshrc) return True return
def change_theme_in_zshrc(zshrc, theme_name): if read_zshrc_omz(zshrc): current_zshrc = read_zshrc(zshrc) current_theme = read_zshrc_omz(zshrc)[1] new_theme = f'ZSH_THEME="{theme_name}"' new_zsh_rc = re_sub(rf"{current_theme}", new_theme, current_zshrc, flags=re_m) snakypy_file_create(new_zsh_rc, zshrc, force=True) return True return
def main(self): checking_init(self.HOME) if not read_zshrc_omz(self.zsh_rc): title = f"Do you want to uninstall {package.info['name']}?" options = ["Yes", "No"] reply = pick(title, options, colorful=True, index=True) if reply is None or reply[0] == 1: printer("Whew! Thanks! :)", foreground=FG.GREEN) exit(0) rm_init_file_package(self.init_file) rm_source_zshrc(self.zsh_rc) else: title = f"What did you want to uninstall?" options = [ f"{package.info['name']}", f"{package.info['name']} and Oh My ZSH", "Cancel", ] reply = pick(title, options, colorful=True, index=True) if reply is None or reply[0] == 2: printer("Whew! Thanks! :)", foreground=FG.GREEN) exit(0) with contextlib_suppress(Exception): os_remove(self.theme_file) rm_init_file_package(self.init_file) change_theme_in_zshrc(self.zsh_rc, "robbyrussell") if reply[0] == 1: shutil_rmtree(self.omz_root, ignore_errors=True) with contextlib_suppress(Exception): shutil_copyfile( self.zsh_rc, f"{self.zsh_rc}-D{datetime.today().isoformat()}") with contextlib_suppress(Exception): os_remove(self.zsh_rc) snakypy_file_create("", f"{self.HOME}/.zshrc", force=True) reload_zsh() printer("Uninstall process finished.", foreground=FG.FINISH)
def create_zshrc_not_exists(content, zshrc): if not exists(zshrc): snakypy_file_create(content, zshrc)
def rm_source_zshrc(zshrc): current_zshrc = read_zshrc(zshrc) line_rm = "source\\ \\$HOME/.zshpower" new_zshrc = re_sub(rf"{line_rm}", "", current_zshrc, flags=re_m) snakypy_file_create(new_zshrc, zshrc, force=True)