def init_pearl(pearl_env: PearlEnvironment, _: Namespace): """ Initializes the Pearl environment by setting up the PEARL_HOME files and directories and the `pearl.conf` file. """ messenger.print( f'{Color.CYAN}* {Color.NORMAL}Setting up $PEARL_HOME directory as {pearl_env.home}' ) (pearl_env.home / 'bin').mkdir(parents=True, exist_ok=True) (pearl_env.home / 'packages').mkdir(parents=True, exist_ok=True) (pearl_env.home / 'repos').mkdir(parents=True, exist_ok=True) (pearl_env.home / 'var').mkdir(parents=True, exist_ok=True) static = Path(pkg_resources.resource_filename('pearllib', 'static/')) if (pearl_env.home / 'boot').exists(): (pearl_env.home / 'boot').unlink() (pearl_env.home / 'boot').symlink_to(static / 'boot') if not pearl_env.config_filename.exists(): messenger.print( f'{Color.CYAN}* {Color.NORMAL}Creating the Pearl configuration file {pearl_env.config_filename} from template $PEARL_HOME' ) pearl_env.config_filename.parent.mkdir(parents=True, exist_ok=True) pearl_conf_template = static / 'templates/pearl.conf.template' shutil.copyfile(str(pearl_conf_template), str(pearl_env.config_filename)) apply(f"source {pearl_env.home}/boot/sh/pearl.sh", f"{os.environ['HOME']}/.bashrc") messenger.print(f'{Color.CYAN}* {Color.NORMAL}Activated Pearl for Bash') apply(f"source {pearl_env.home}/boot/sh/pearl.sh", f"{os.environ['HOME']}/.zshrc") messenger.print(f'{Color.CYAN}* {Color.NORMAL}Activated Pearl for Zsh') apply(f"source {pearl_env.home}/boot/fish/pearl.fish", f"{os.environ['HOME']}/.config/fish/config.fish") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Activated Pearl for Fish shell') apply(f"source {pearl_env.home}/boot/vim/pearl.vim", f"{os.environ['HOME']}/.vimrc") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Activated Pearl for Vim editor') apply(f"(load-file \"{pearl_env.home}/boot/emacs/pearl.el\")", f"{os.environ['HOME']}/.emacs") messenger.print( f'{Color.CYAN}* {Color.NORMAL}Activated Pearl for Emacs editor') messenger.info('') messenger.info("Done! Open a new terminal and have fun!") messenger.info('') messenger.info("To get the list of Pearl packages available:") messenger.print(" >> pearl list")
def test_apply_dir_and_file_not_exist(tmp_path): line = 'Add this line' apply(line, str(tmp_path / 'mydir/file')) assert (tmp_path / 'mydir/file').read_text() == line + '\n'
def test_apply(line, file_content, expected_result, tmp_path): (tmp_path / 'file').write_text(file_content) apply(line, str(tmp_path / 'file')) assert (tmp_path / 'file').read_text() == expected_result