diff --git a/README.md b/README.md index 787a9d4..f75f389 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,9 @@ Dotdrop is available on: # Getting started [Create a new repository](https://dotdrop.readthedocs.io/en/latest/getting-started/#repository-setup) -to store your dotfiles with dotdrop. *Init* or *clone* that new repository and -[install dotdrop](https://dotdrop.readthedocs.io/en/latest/installation/). +to store your dotfiles with dotdrop. *Init* or *clone* that new repository, +[install dotdrop](https://dotdrop.readthedocs.io/en/latest/installation/) and +generate a default config file [generate config file](https://dotdrop.readthedocs.io/en/latest/usage/#generate-a-default-config) Then import any dotfiles (files or directories) you want to manage with dotdrop. You can either use the default profile (which resolves to the *hostname* of the host diff --git a/bootstrap.sh b/bootstrap.sh index 49acd16..e71a3ac 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -2,22 +2,14 @@ # author: deadc0de6 (https://github.com/deadc0de6) # Copyright (c) 2017, deadc0de6 -fold="dotfiles" conf="config.yaml" # copy dotdrop entry point cp dotdrop/dotdrop.sh dotdrop.sh chmod +x dotdrop.sh -mkdir -p $fold +mkdir -p dotfiles -if [ ! -e ${conf} ]; then +if [ ! -e "${conf}" ]; then # init config file - cat << EOF > ${conf} -config: - backup: true - create: true - dotpath: $fold -dotfiles: -profiles: -EOF + ./dotdrop.sh gencfg > "${conf}" fi diff --git a/docs/config/config-config.md b/docs/config/config-config.md index 761f174..350ec74 100644 --- a/docs/config/config-config.md +++ b/docs/config/config-config.md @@ -38,7 +38,6 @@ Entry | Description | Default `workdir` | Path to the directory where templates are installed before being symlinked when using `link:absolute|relative|link_children` (absolute path or relative to the config file location) | `~/.config/dotdrop` link_by_default | When importing a dotfile, set `link` to this value by default | false - ## import_variables entry It is possible to load variables/dynvariables from external files by providing their diff --git a/docs/config/config-file.md b/docs/config/config-file.md index 27f36f7..c3415bd 100644 --- a/docs/config/config-file.md +++ b/docs/config/config-file.md @@ -2,8 +2,8 @@ ## Location -The default config file used by dotdrop is -[config.yaml](https://github.com/deadc0de6/dotdrop/blob/master/config.yaml). +The default config file used by dotdrop is `config.yaml`. +A clean base config can be generated using `dotdrop gencfg`. Unless specified otherwise, dotdrop will look in the following places for its config file and use the first one found: diff --git a/docs/getting-started.md b/docs/getting-started.md index 091b488..3467e3e 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -15,12 +15,11 @@ $ cd my-dotfiles $ mkdir dotfiles ``` -Then add a config file. You can get a -[minimal config file](https://github.com/deadc0de6/dotdrop/blob/master/config.yaml) -from dotdrop's repository with: +Then generate a base config file: ```bash -$ wget https://raw.githubusercontent.com/deadc0de6/dotdrop/master/config.yaml +$ dotdrop gencfg > config.yaml ``` + It is recommended to store your config file directly within your repository (*my-dotfiles* in the example above), but you could save it in different places if you wish; see [config location](config/config-file.md#location) for more. diff --git a/docs/usage.md b/docs/usage.md index d28be09..a3b4e50 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -250,6 +250,13 @@ the file will be restored. For more options, see the usage with `dotdrop --help`. +## Generate a default config + +The `gencfg` command will generate a default config in yaml +```bash +$ dotdrop gencfg > config.yaml +``` + ## Concurrency The command line switch `-w`/`--workers`, if set to a value greater than one, enables the use diff --git a/dotdrop/config.py b/dotdrop/config.py new file mode 100644 index 0000000..4b6c60a --- /dev/null +++ b/dotdrop/config.py @@ -0,0 +1,18 @@ +""" +author: deadc0de6 (https://github.com/deadc0de6) +Copyright (c) 2024, deadc0de6 + +default config +""" + +default_config = """config: + backup: true + banner: true + create: true + dotpath: dotfiles + keepdot: false + link_dotfile_default: nolink + link_on_import: nolink + longkey: false +dotfiles: +profiles:""" \ No newline at end of file diff --git a/dotdrop/options.py b/dotdrop/options.py index 3ead971..8143572 100644 --- a/dotdrop/options.py +++ b/dotdrop/options.py @@ -21,6 +21,7 @@ from dotdrop.cfg_aggregator import CfgAggregator from dotdrop.action import Action from dotdrop.utils import uniq_list, debug_list, debug_dict from dotdrop.exceptions import YamlException, OptionsException +from dotdrop.config import default_config ENV_PROFILE = 'DOTDROP_PROFILE' ENV_CONFIG = 'DOTDROP_CONFIG' @@ -72,6 +73,7 @@ Usage: dotdrop files [-VbTG] [-c ] [-p ] dotdrop detail [-Vb] [-c ] [-p ] [...] dotdrop profiles [-VbG] [-c ] + dotdrop gencfg dotdrop --help dotdrop --version @@ -148,6 +150,12 @@ class Options(AttrMonitor): self.args = {} if not args: self.args = docopt(USAGE, version=VERSION) + + if self.args['gencfg']: + # print config and exit + print(default_config) + sys.exit(0) + if args: self.args = args.copy() self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ