1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 13:21:44 +00:00

adding a gencfg command

This commit is contained in:
deadc0de6
2024-10-23 14:06:39 +02:00
committed by deadc0de
parent d5d00ef9c0
commit d252756e46
8 changed files with 44 additions and 20 deletions

5
README.md vendored
View File

@@ -98,8 +98,9 @@ Dotdrop is available on:
# Getting started # Getting started
[Create a new repository](https://dotdrop.readthedocs.io/en/latest/getting-started/#repository-setup) [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 to store your dotfiles with dotdrop. *Init* or *clone* that new repository,
[install dotdrop](https://dotdrop.readthedocs.io/en/latest/installation/). [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. 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 You can either use the default profile (which resolves to the *hostname* of the host

14
bootstrap.sh vendored
View File

@@ -2,22 +2,14 @@
# author: deadc0de6 (https://github.com/deadc0de6) # author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2017, deadc0de6 # Copyright (c) 2017, deadc0de6
fold="dotfiles"
conf="config.yaml" conf="config.yaml"
# copy dotdrop entry point # copy dotdrop entry point
cp dotdrop/dotdrop.sh dotdrop.sh cp dotdrop/dotdrop.sh dotdrop.sh
chmod +x dotdrop.sh chmod +x dotdrop.sh
mkdir -p $fold mkdir -p dotfiles
if [ ! -e ${conf} ]; then if [ ! -e "${conf}" ]; then
# init config file # init config file
cat << EOF > ${conf} ./dotdrop.sh gencfg > "${conf}"
config:
backup: true
create: true
dotpath: $fold
dotfiles:
profiles:
EOF
fi fi

View File

@@ -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` `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`
<s>link_by_default</s> | When importing a dotfile, set `link` to this value by default | false <s>link_by_default</s> | When importing a dotfile, set `link` to this value by default | false
## import_variables entry ## import_variables entry
It is possible to load variables/dynvariables from external files by providing their It is possible to load variables/dynvariables from external files by providing their

View File

@@ -2,8 +2,8 @@
## Location ## Location
The default config file used by dotdrop is The default config file used by dotdrop is `config.yaml`.
[config.yaml](https://github.com/deadc0de6/dotdrop/blob/master/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 Unless specified otherwise, dotdrop will look in the following places for its config file
and use the first one found: and use the first one found:

View File

@@ -15,12 +15,11 @@ $ cd my-dotfiles
$ mkdir dotfiles $ mkdir dotfiles
``` ```
Then add a config file. You can get a Then generate a base config file:
[minimal config file](https://github.com/deadc0de6/dotdrop/blob/master/config.yaml)
from dotdrop's repository with:
```bash ```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 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; (*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. see [config location](config/config-file.md#location) for more.

7
docs/usage.md vendored
View File

@@ -250,6 +250,13 @@ the file will be restored.
For more options, see the usage with `dotdrop --help`. 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 ## Concurrency
The command line switch `-w`/`--workers`, if set to a value greater than one, enables the use The command line switch `-w`/`--workers`, if set to a value greater than one, enables the use

18
dotdrop/config.py Normal file
View File

@@ -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:"""

View File

@@ -21,6 +21,7 @@ from dotdrop.cfg_aggregator import CfgAggregator
from dotdrop.action import Action from dotdrop.action import Action
from dotdrop.utils import uniq_list, debug_list, debug_dict from dotdrop.utils import uniq_list, debug_list, debug_dict
from dotdrop.exceptions import YamlException, OptionsException from dotdrop.exceptions import YamlException, OptionsException
from dotdrop.config import default_config
ENV_PROFILE = 'DOTDROP_PROFILE' ENV_PROFILE = 'DOTDROP_PROFILE'
ENV_CONFIG = 'DOTDROP_CONFIG' ENV_CONFIG = 'DOTDROP_CONFIG'
@@ -72,6 +73,7 @@ Usage:
dotdrop files [-VbTG] [-c <path>] [-p <profile>] dotdrop files [-VbTG] [-c <path>] [-p <profile>]
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...] dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
dotdrop profiles [-VbG] [-c <path>] dotdrop profiles [-VbG] [-c <path>]
dotdrop gencfg
dotdrop --help dotdrop --help
dotdrop --version dotdrop --version
@@ -148,6 +150,12 @@ class Options(AttrMonitor):
self.args = {} self.args = {}
if not args: if not args:
self.args = docopt(USAGE, version=VERSION) self.args = docopt(USAGE, version=VERSION)
if self.args['gencfg']:
# print config and exit
print(default_config)
sys.exit(0)
if args: if args:
self.args = args.copy() self.args = args.copy()
self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ