diff --git a/README.md b/README.md index bceb9bc7..7e5f7a7d 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ Editing the file in a text editor will give you more control and be faster. #### Conditional Backup and Reinstallation -Every dotfile has two subkeys: `backup_condition` and `reinstall_condition`. Both of these accept expressions that will be evaluated in `bash`. An empty string (`""`) is the default value, and is considered to be `True`. If the return value of the expression is `0`, this is considered `True`. Otherwise, it is `False`. This lets you do simple things like preventing backup with: +Every dotfile has two (optional) subkeys: `backup_condition` and `reinstall_condition`. Both of these accept expressions that will be evaluated in `bash`. An empty string (`""`) is the default value, and is considered to be `True`. If the return value of the expression is `0`, this is considered `True`. Otherwise, it is `False`. This lets you do simple things like preventing backup with: ```javascript // Because `$ false` returns 1 @@ -167,7 +167,7 @@ And also more complicated things like only backing up certain files if an enviro "backup_condition": "[[ -n \"$ENV_VAR\" ]]" ``` -My config (as of `v5.0.0a`) looks like this, and is used to back up my [dotfiles](https://www.github.com/alichtman/dotfiles): +Here's an example config based on my [dotfiles](https://www.github.com/alichtman/dotfiles): ```json { @@ -175,101 +175,16 @@ My config (as of `v5.0.0a`) looks like this, and is used to back up my [dotfiles "lowest_supported_version": "5.0.0a", "dotfiles": { ".config/agignore": { - "reinstall_condition": "", - "backup_condition": "" + "backup_condition": "uname -a | grep Darwin", + "reinstall_conditon": "uname -a | grep Darwin" }, - ".config/crontab": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/fzf-notes": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/git/config": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/git/gitignore_global": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/jrnl/jrnl.yaml": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/kitty": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/nvim": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/pycodestyle": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/pylintrc": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/python": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/radare2/radare2rc": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/ranger": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/shallow-backup.conf": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/starship.toml": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/tmux": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/tuir/tuir.cfg": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/zathura/zathurarc": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".config/zsh": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".ctags": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".ghc/ghci.conf": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".pypirc": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".ssh": { - "reinstall_condition": "", - "backup_condition": "" - }, - ".zshenv": { - "reinstall_condition": "", - "backup_condition": "" - } + ".config/git/gitignore_global": { }, + ".config/jrnl/jrnl.yaml": { }, + ".config/kitty": { }, + ".config/nvim": { }, + ".config/pycodestyle": { }, + ... + ".zshenv": { } }, "root-gitignore": [ ".DS_Store", diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index e968c6f7..e1682f8b 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -31,7 +31,7 @@ def backup_dotfiles(backup_dest_path, dry_run=False, home_path=os.path.expanduse dot_path_pairs = [] for dotfile_path_from_config, options in config.items(): # Evaluate condition, if specified. Skip if the command doesn't return true. - condition_success = evaluate_condition(condition=options["backup_condition"], + condition_success = evaluate_condition(condition=options.get("backup_condition", ""), backup_or_reinstall="backup", dotfile_path=dotfile_path_from_config) if not condition_success: diff --git a/shallow_backup/config.py b/shallow_backup/config.py index dbf570c0..543f1793 100644 --- a/shallow_backup/config.py +++ b/shallow_backup/config.py @@ -56,46 +56,16 @@ def get_default_config() -> dict: "backup_condition": "", "reinstall_condition": "", }, - ".bashrc": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".config/git": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".config/nvim/init.vim": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".config/tmux": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".config/zsh": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".profile": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".pypirc": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".ssh": { - "backup_condition": "", - "reinstall_condition": "", - }, - ".zshenv": { - "backup_condition": "", - "reinstall_condition": "", - }, - f"{strip_home(get_config_path())}": { - "backup_condition": "", - "reinstall_condition": "", - }, + ".bashrc": {}, + ".config/git": {}, + ".config/nvim/init.vim": {}, + ".config/tmux": {}, + ".config/zsh": {}, + ".profile": {}, + ".pypirc": {}, + ".ssh": {}, + ".zshenv": {}, + f"{strip_home(get_config_path())}": {}, }, "root-gitignore": [ "dotfiles/.ssh", @@ -151,10 +121,7 @@ def add_dot_path_to_config(backup_config: dict, file_path: str) -> dict: else: stripped_home_path = strip_home(abs_path) print_path_blue("Added:", stripped_home_path) - backup_config["dotfiles"][stripped_home_path] = { - "reinstall_condition": "", - "backup_condition": "" - } + backup_config["dotfiles"][stripped_home_path] = {} return backup_config @@ -169,15 +136,15 @@ def show_config(): print_path_red("Backup Path:", contents) elif section == "config_mapping": print_red_bold("\nConfigs:") - for path, dest in contents.items(): - print(f" {path} -> {dest}") + for config_path, dest in contents.items(): + print(f" {config_path} -> {dest}") # Print section header and contents. (Dotfiles) elif section == "dotfiles": print_path_red("\nDotfiles:", "(Backup and Reinstall conditions will be shown if they exist)") for dotfile, options in contents.items(): - backup_condition = options['backup_condition'] - reinstall_condition = options['reinstall_condition'] + backup_condition = options.get('backup_condition', "") + reinstall_condition = options.get('reinstall_condition', "") if backup_condition or reinstall_condition: print(f" {dotfile} ->") print(f"\t\tbackup_condition: \"{backup_condition}\"") diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index e0fb9f26..a7f8a6b9 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -25,7 +25,7 @@ def reinstall_dots_sb(dots_path: str, home_path: str = os.path.expanduser("~"), dotfiles_to_reinstall = [] for dotfile_path_from_config, options in config.items(): # Evaluate condition, if specified. Skip if the command doesn't return true. - condition_success = evaluate_condition(condition=options["reinstall_condition"], + condition_success = evaluate_condition(condition=options.get("reinstall_condition", ""), backup_or_reinstall="reinstall", dotfile_path=dotfile_path_from_config) if not condition_success: diff --git a/shallow_backup/upgrade.py b/shallow_backup/upgrade.py index 46cd4fd9..4cca9fde 100644 --- a/shallow_backup/upgrade.py +++ b/shallow_backup/upgrade.py @@ -17,4 +17,3 @@ def check_if_config_upgrade_needed(): print_red("2. Manually upgrade the config.") print_red_bold("Please downgrade to a version of shallow-backup before v5.0.0a if you do not want to upgrade your config.") sys.exit() -