aboutsummaryrefslogtreecommitdiffstats
path: root/README.org
blob: 13becc6e0617bb6b6a7d6738f5c1dc3e155665e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#+html: <p align="center"><img src="res/logo.png" width="30%" height="30%" /></p>
* ck
*The Config Keeper*

* build it
** requirements
- clang (llvm) or gcc (gnu)
- cmake
- sqlite3-dev

** compiler
By default I use clang, if you want to use gcc just
edit the =CMakeLists.txt= file and change =clang= to =gcc=

** make
#+BEGIN_SRC sh
# clone the repo
> cd ~/code; git clone https://gitlab.com/grm-grm/ck
# make a build directory and enter it
> mkdir ~/ck_build; cd ~/ck_build;
# run cmake
> cmake ~/code/ck
# run make
> make
# run ck
> ./ck
#+END_SRC

* for devs
** make
Just build with address sanitizer enabled like so:
llvm has better asan than gcc, so I use that.
#+BEGIN_SRC sh
# clone the repo
> cd ~/code; git clone https://gitlab.com/grm-grm/ck
# make a build directory and enter it
> mkdir ~/ck_build; cd ~/ck_build;
# run cmake
> cmake ~/code/ck -DCK_ASAN=ON
# run make
> make
# run ck
> ./ck
#+END_SRC

** tests
The testing "suite" is a bash script that runs regression
and unit tests. Regression tests are under the =tests/= directory
and are bash scripts that test =ck= functionality. Unit tests reside
under =unit/= directory and test the code.

*** run tests
Simply go to the build dir and type.
#+BEGIN_SRC sh
$ ./check_ck
#+END_SRC

*** test suite
#+BEGIN_SRC sh
$ ./check_ck -h
ck test suite
use without flags to run all tests

flags:
  -u, --unit            run only the unit tests
  -r, --regression      run only the regression tests
  -c, --clear           remove test files
                         use it if the tests fail
  -h, --help, *         print this
#+END_SRC
* manual
ck's goal is to assist with the configuration file management.
To that end it tries to provides a cli interface that is pretty straight-forward
and intuitive.

Example usage:
#+BEGIN_SRC sh
  # initialize new ck
  $ ck init /path_to/where_you_want/your_configs/to_be \
    /path_to/the_secret/directory

  # add emacs configs
  ## primary config
  $ ck add emacs ~/.emacs.d/orgconf.org -p
  ## secret config, with passwords and naughty words
  $ ck add emacs ~/.emacs.d/accounts.org -s
  ## and another one for emacs
  $ ck add emacs ~/.emacs.d/init.el

  # add tmux config
  $ ck add tmux ~/.tmux.conf -p

  # list the configs
  $ ck list tree
  $ ck list paths -t lisp
  $ ck list programs -t python

  # search the configs
  $ ck search search-term
  $ ck search "\"search term with spaces\""
  $ ck search "\(" #escape symbols
#+END_SRC

The first command after typing *ck* is the action you wish to perform. Actions are 
a very important concept of ck. With an action you can initialize *ck*, add/move/delete
configuration files to it, edit them, list them in various ways and search in their content.

Actions expect their arguments in the order specified below. This is done to reduce the amount
of flags one has to pass to ck.

** ck configuration
ck uses sqlite to index the configuration files. The init
action creates a *.ck* directory (under $HOME)
in witch the *ckrc* and the *ckdb* reside. The first one contains
the two directories described above while the other one is the
sqlite db.

One can have multiple config directories with different configurations
each.

Using the special keyword *config* (or *conf* or *c* or *-c*) you can set the path
in which ck will search for the *.ck* directory.

You can prefix every action with this and ck will use the configuration
directory of your choice.

Usage:
#+BEGIN_SRC sh
  $ ck config ~/ ... # the default behaviour

  # /someplace/else must exist or
  # the action following it must be init
  $ ck conf /someplace/else ... 

  # same thing
  $ ck c /someplace/else ... 
  $ ck -c /someplace/else ... 
#+END_SRC

** Actions
*** init 
or i or -i

init takes exactly 2 arguments.

- *config_dir*: where all the configs will live
- *secret_dir*: where all the secret configs will live

Use init to initialize a new ck database.

Usage:
#+BEGIN_SRC sh
  # initialize new ck
  $ ck init /path_to/where_you_want/your_configs/to_be \
    /path_to/the_secret/directory
#+END_SRC

*** add 
or a or -a

Add takes 2 to 4 arguments.

- *program_name*: the name of the program you add a config to
- *config_path*: the path to the config
- Optional: (order doesn't matter)
  + *-p*: the config will be the primary (relevant on edit below)
  + *-s*: the config will be stored in the secret_dir

Use add to add a new config for ck to keep track of.

Keep in mind:
- The config has to exist
- If you are adding a config to a program already existing in ckdb make
 sure to use the same name
- Each program can have only one primary config

Usage:
#+BEGIN_SRC sh
  # add config to ck
  $ ck add program_name config_path [-s] [-p]
#+END_SRC

*** list
or ls or l or -l

List can show the *paths* or the *programs* that ck keeps track of.
With the flag *-t* and then one of the follwing types one can change
the way the list is printed:
- *plain*: simple listing (default)
- *python*: print like a python list
- *lisp*: print like a lisp list

Using the keyword *tree* ck can list the configurations under their
corresponding program.

#+BEGIN_SRC C
  /* TODO: show primary and secret atributes */
#+END_SRC
Usage:
#+BEGIN_SRC sh
  # list tree structure
  $ ck list tree
  # list paths in python
  $ ck l paths -t python
  # list programs in lisp
  $ ck ls programs -t lisp
#+END_SRC

*** search
or s or -s

Perform infile grep in all the configurations ck keeps track of.

Takes one argument, the *search-term*.

To search for terms with spaces you have to put them in escaped quotes.
To search for special symbols you have to enclose them in quotes and escape them.

Usage:
#+BEGIN_SRC sh
  # search for parenthesis
  $ ck search "\("
  # search term with spaces
  $ ck search "\"This is a space\""
  # both
  $ ck search "\"(add 2 4)\""
  # and a normal one
  $ ck search alias
#+END_SRC

*** edit 
or e or -e
~~--WIP--~~
Currently edit can only edit the primary config of a program.

To do it use:
#+BEGIN_SRC sh
$ ck edit program_name
#+END_SRC