Skip to content

Commit d252756

Browse files
committed
adding a gencfg command
1 parent d5d00ef commit d252756

File tree

8 files changed

+44
-20
lines changed

8 files changed

+44
-20
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ Dotdrop is available on:
9898
# Getting started
9999

100100
[Create a new repository](https://dotdrop.readthedocs.io/en/latest/getting-started/#repository-setup)
101-
to store your dotfiles with dotdrop. *Init* or *clone* that new repository and
102-
[install dotdrop](https://dotdrop.readthedocs.io/en/latest/installation/).
101+
to store your dotfiles with dotdrop. *Init* or *clone* that new repository,
102+
[install dotdrop](https://dotdrop.readthedocs.io/en/latest/installation/) and
103+
generate a default config file [generate config file](https://dotdrop.readthedocs.io/en/latest/usage/#generate-a-default-config)
103104

104105
Then import any dotfiles (files or directories) you want to manage with dotdrop.
105106
You can either use the default profile (which resolves to the *hostname* of the host

bootstrap.sh

+3-11
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@
22
# author: deadc0de6 (https://github.com/deadc0de6)
33
# Copyright (c) 2017, deadc0de6
44

5-
fold="dotfiles"
65
conf="config.yaml"
76

87
# copy dotdrop entry point
98
cp dotdrop/dotdrop.sh dotdrop.sh
109
chmod +x dotdrop.sh
11-
mkdir -p $fold
10+
mkdir -p dotfiles
1211

13-
if [ ! -e ${conf} ]; then
12+
if [ ! -e "${conf}" ]; then
1413
# init config file
15-
cat << EOF > ${conf}
16-
config:
17-
backup: true
18-
create: true
19-
dotpath: $fold
20-
dotfiles:
21-
profiles:
22-
EOF
14+
./dotdrop.sh gencfg > "${conf}"
2315
fi

docs/config/config-config.md

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Entry | Description | Default
3838
`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`
3939
<s>link_by_default</s> | When importing a dotfile, set `link` to this value by default | false
4040

41-
4241
## import_variables entry
4342

4443
It is possible to load variables/dynvariables from external files by providing their

docs/config/config-file.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Location
44

5-
The default config file used by dotdrop is
6-
[config.yaml](https://github.com/deadc0de6/dotdrop/blob/master/config.yaml).
5+
The default config file used by dotdrop is `config.yaml`.
6+
A clean base config can be generated using `dotdrop gencfg`.
77

88
Unless specified otherwise, dotdrop will look in the following places for its config file
99
and use the first one found:

docs/getting-started.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ $ cd my-dotfiles
1515
$ mkdir dotfiles
1616
```
1717

18-
Then add a config file. You can get a
19-
[minimal config file](https://github.com/deadc0de6/dotdrop/blob/master/config.yaml)
20-
from dotdrop's repository with:
18+
Then generate a base config file:
2119
```bash
22-
$ wget https://raw.githubusercontent.com/deadc0de6/dotdrop/master/config.yaml
20+
$ dotdrop gencfg > config.yaml
2321
```
22+
2423
It is recommended to store your config file directly within your repository
2524
(*my-dotfiles* in the example above), but you could save it in different places if you wish;
2625
see [config location](config/config-file.md#location) for more.

docs/usage.md

+7
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ the file will be restored.
250250

251251
For more options, see the usage with `dotdrop --help`.
252252

253+
## Generate a default config
254+
255+
The `gencfg` command will generate a default config in yaml
256+
```bash
257+
$ dotdrop gencfg > config.yaml
258+
```
259+
253260
## Concurrency
254261

255262
The command line switch `-w`/`--workers`, if set to a value greater than one, enables the use

dotdrop/config.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
author: deadc0de6 (https://github.com/deadc0de6)
3+
Copyright (c) 2024, deadc0de6
4+
5+
default config
6+
"""
7+
8+
default_config = """config:
9+
backup: true
10+
banner: true
11+
create: true
12+
dotpath: dotfiles
13+
keepdot: false
14+
link_dotfile_default: nolink
15+
link_on_import: nolink
16+
longkey: false
17+
dotfiles:
18+
profiles:"""

dotdrop/options.py

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from dotdrop.action import Action
2222
from dotdrop.utils import uniq_list, debug_list, debug_dict
2323
from dotdrop.exceptions import YamlException, OptionsException
24+
from dotdrop.config import default_config
2425

2526
ENV_PROFILE = 'DOTDROP_PROFILE'
2627
ENV_CONFIG = 'DOTDROP_CONFIG'
@@ -72,6 +73,7 @@
7273
dotdrop files [-VbTG] [-c <path>] [-p <profile>]
7374
dotdrop detail [-Vb] [-c <path>] [-p <profile>] [<key>...]
7475
dotdrop profiles [-VbG] [-c <path>]
76+
dotdrop gencfg
7577
dotdrop --help
7678
dotdrop --version
7779
@@ -148,6 +150,12 @@ def __init__(self, args=None):
148150
self.args = {}
149151
if not args:
150152
self.args = docopt(USAGE, version=VERSION)
153+
154+
if self.args['gencfg']:
155+
# print config and exit
156+
print(default_config)
157+
sys.exit(0)
158+
151159
if args:
152160
self.args = args.copy()
153161
self.debug = self.args['--verbose'] or ENV_DEBUG in os.environ

0 commit comments

Comments
 (0)