Table of Contents
ck
The Config Keeper
build it
requirements
- clang (llvm) or gcc (gnu)
- cmake
- sqlite3-dev
compiler
> export CC=clang # or > export CC=gcc
make
# 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
for devs
CMake options
cmake accepts the following options:
option(CK_ASAN "Build with asan") option(CK_DEBUG "Build with debug symbols") option(CK_TESTS "Make the tests") option(CK_SHARED "Build with shared lib")
To use any one of them append it after the cmake command like so:
cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck
Just build with address sanitizer enabled like so: llvm has better asan than gcc, so I use that.
# 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 -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck # run make > make # run ck > ./ck
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
First make sure you build ck with the -DCK_TESTS=1
option. Then
go to the build directory and type:
$ ./test-ck
test suite
$ ./test-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 if the tests crush unexpectedly -h, --help, * print this
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:
# 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
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:
$ 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 ...
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:
# initialize new ck $ ck init /path_to/where_you_want/your_configs/to_be \ /path_to/the_secret/directory
add
or a or -a
Adds a configuration to the ck database. 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
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:
# add config to ck $ ck add program_name config_path [-s] [-p]
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.
Passing the -a flag will enable the listing of config attributes (secret or primary). It is best used with tree or plain paths.
Usage:
# list tree structure, with attributes $ ck list tree -a # list paths in python $ ck l paths -t python # list programs in lisp $ ck ls programs -t lisp
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 quotes.
Usage:
# 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
If you want to use more advanced grep techniques or even a different pattern matching program you can do it like so:
# with xargs $ ck ls paths | xargs grep -E 'A|B' # or in bash $ for i in $(ck ls paths); do grep -E 'A|B' $i; done # or in zsh $ for i ($(ck ls paths)) grep -E 'A|B' $i
edit
or e or -e
Edit configurations with $EDITOR
.
Edit takes at least one and up to two arguments.
The first argument is the programName. If the program has a primary configuration edit will open this. If the program has only one configuration edit will open it. If the program has more than 1 configurations and no primary, it will print the avaliable configurations and exit.
The second argument is the configName. If it exists it will open, else it will print the avaliable configurations and exit.
Usage:
# suppose this is our ck instance $ ck list tree -a emacs: |- init.el |- accounts.el [s] |- orgconf.org [p] # edit the primary emacs config $ ck edit emacs # edit a specific emacs config, other than the primary $ ck edit emacs accounts.el