## what - Run shell command conditionally (optional) - Update README docs ## how - the shell directive will check if the 'if' property is available. - If it is, it will run the command in 'if' property. - If the command results in a return 0 code or 'true', then the 'command' property will run. - If the condition to run the command is a non 0 code or 'false', the shell command won't run - dotbot config example: ```yaml - shell: - command: echo "this is running on a MacOS" if: uname -s | grep -i "Darwin" ``` - running shell command regardless ```yaml - shell: - command: echo "This should run regardless" ``` - dotbot config example: skipping command if false ```yaml - shell: - command: echo "This command should be skipped" if: false ``` ## why - can run the shell command conditionally - can use multiple dotbot configs to run different OS - Ex: incorporating it in https://github.com/ecarlson94/dotbot-template ## where - file changed in `./dotbot/plugins/shell.py` ## usage Create dotbot config ```yaml - shell: - command: echo "this is running on a MacOS" if: uname -s | grep -i "Darwin" ``` ```yaml - shell: - command: echo "This command should be skipped" if: false ``` ```yaml - shell: - command: apt update && apt upgrade -y if: lsb_release -i | grep -io 'debian' description: Update APT package repository - command: dnf update -y if: lsb_release -i | grep -io 'fedora' description: Update DNF package repository ``` # NOTE - The reason to wrap the if command in string, is to prevent Python from interpreting it. - `str(item["if"]),` - https://github.com/Clumsy-Coder/dotbot/blob/25ef5d5a5fed1e2f95e57115dfdbc8ba67cfc93f/dotbot/plugins/shell.py#L52 - Try it without wrapping it in strings - https://github.com/Clumsy-Coder/dotbot/blob/974156ccdecee05eb9544b0b21cc0351428ddd43/dotbot/plugins/shell.py#L51-L57 - ```python run_if_result = dotbot.util.shell_command( item["if"], cwd=self._context.base_directory(), enable_stdin=False, enable_stdout=False, enable_stderr=stderr, ) ``` - Fails to run because error was thrown ```yaml - shell: - command: echo "This command should be skipped" if: false ``` - Works if wrapping `false` in strings ```yaml - shell: - command: echo "This command should be skipped" if: "false" ```
This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by Clumsy-Coder and has received 3 comments.