diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.html | 657 | ||||
-rw-r--r-- | README.org | 281 | ||||
-rw-r--r-- | ck.1 | 80 | ||||
-rw-r--r-- | src/actionhelper.c | 8 | ||||
-rw-r--r-- | src/actionparser.c | 6 | ||||
-rw-r--r-- | src/actions.c | 8 | ||||
-rw-r--r-- | src/actions.h | 1 | ||||
-rw-r--r-- | src/dblayer.c | 36 | ||||
-rw-r--r-- | src/dblayer.h | 6 |
10 files changed, 407 insertions, 678 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e9d9e9..b0b3fbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ project(ck C) # version set(ck_MAJOR_VERSION 0) set(ck_MINOR_VERSION 8) -set(ck_PATCH_VERSION 2) +set(ck_PATCH_VERSION 3) # Feature test macros set(FEATURE_TEST_MACROS "-D_DEFAULT_SOURCE") diff --git a/README.html b/README.html index f6bd550..655204c 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2018-10-28 Sun 13:22 --> +<!-- 2018-10-29 Mon 17:20 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>‎</title> @@ -232,53 +232,46 @@ for the JavaScript code in this tag. <h2>Table of Contents</h2> <div id="text-table-of-contents"> <ul> -<li><a href="#orgf8d00be">ck</a> +<li><a href="#org00fe9a3">ck</a> <ul> -<li><a href="#orgf43f116">Technicalities</a></li> -<li><a href="#orge578423">Download</a></li> +<li><a href="#orgddefd39">Technicalities</a></li> +<li><a href="#org52a8ede">Download</a></li> </ul> </li> <li><a href="#build-instructions">build it</a> <ul> -<li><a href="#org6787614">requirements</a></li> -<li><a href="#org5689497">make && install</a></li> +<li><a href="#orge924f4c">requirements</a></li> +<li><a href="#orga1d810a">make && install</a></li> </ul> </li> -<li><a href="#org8db7ac9">for devs</a> +<li><a href="#org421fdfb">for devs</a> <ul> -<li><a href="#org42a6614">CMake options</a></li> -<li><a href="#org5501d31">compiler</a></li> -<li><a href="#org3720cae">tests</a> +<li><a href="#org98bcc06">CMake options</a></li> +<li><a href="#org945fa72">compiler</a></li> +<li><a href="#orge94d2b6">tests</a> <ul> -<li><a href="#org7b06e14">run tests</a></li> -<li><a href="#org7ad16bc">test suite</a></li> +<li><a href="#org6d98a70">run tests</a></li> +<li><a href="#orgdf6a992">test suite</a></li> </ul> </li> </ul> </li> -<li><a href="#manual">manual</a> +<li><a href="#org5444b91">ck configuration</a></li> +<li><a href="#usage">Usage</a> <ul> -<li><a href="#orgb40149d">ck configuration</a></li> -<li><a href="#org52aba1d">Actions</a> -<ul> -<li><a href="#org7ba72be">init</a></li> -<li><a href="#org9ae26ce">add</a></li> -<li><a href="#orgb4adc9b">list</a></li> -<li><a href="#org442a05c">search</a></li> -<li><a href="#org6320932">edit</a></li> -<li><a href="#orgae8e7fb">restore</a></li> -</ul> -</li> +<li><a href="#orgd2e5354">Initialize</a></li> +<li><a href="#orgfc9d01c">Add configs</a></li> +<li><a href="#orga6dee7d">Using the ck actions</a></li> </ul> </li> -<li><a href="#orgf44bdc3">manpage</a></li> +<li><a href="#manpage">manpage</a></li> </ul> </div> </div> <p align="center"><img src="res/logo.png"></p> -<div id="outline-container-orgf8d00be" class="outline-2"> -<h2 id="orgf8d00be">ck</h2> -<div class="outline-text-2" id="text-orgf8d00be"> +<div id="outline-container-org00fe9a3" class="outline-2"> +<h2 id="org00fe9a3">ck</h2> +<div class="outline-text-2" id="text-org00fe9a3"> <p> <b>The Config Keeper</b> </p> @@ -334,9 +327,9 @@ with the rest of us). </p> </div> -<div id="outline-container-orgf43f116" class="outline-3"> -<h3 id="orgf43f116">Technicalities</h3> -<div class="outline-text-3" id="text-orgf43f116"> +<div id="outline-container-orgddefd39" class="outline-3"> +<h3 id="orgddefd39">Technicalities</h3> +<div class="outline-text-3" id="text-orgddefd39"> <p> Upon adding a config to <b>ck</b>, it moves it to the specified folder and adds a symbolic link back where it came from (<code>ln -s</code>). @@ -349,9 +342,9 @@ majority should). </div> </div> -<div id="outline-container-orge578423" class="outline-3"> -<h3 id="orge578423">Download</h3> -<div class="outline-text-3" id="text-orge578423"> +<div id="outline-container-org52a8ede" class="outline-3"> +<h3 id="org52a8ede">Download</h3> +<div class="outline-text-3" id="text-org52a8ede"> <p> Go ahead and download <b>ck</b> and give it a try. It comes with a help sub-command that explains any inquires you might have. @@ -363,19 +356,19 @@ the <a href="#build-instructions">build</a> section. </p> <p> -You can also read the manual <a href="#manual">down below</a>. +You can also read the manpage <a href="#manpage">down below</a>. </p> </div> </div> </div> -<div id="outline-container-orgeb48bed" class="outline-2"> -<h2 id="build-instructions"><a id="orgeb48bed"></a>build it</h2> +<div id="outline-container-orgde5aa18" class="outline-2"> +<h2 id="build-instructions"><a id="orgde5aa18"></a>build it</h2> <div class="outline-text-2" id="text-build-instructions"> </div> -<div id="outline-container-org6787614" class="outline-3"> -<h3 id="org6787614">requirements</h3> -<div class="outline-text-3" id="text-org6787614"> +<div id="outline-container-orge924f4c" class="outline-3"> +<h3 id="orge924f4c">requirements</h3> +<div class="outline-text-3" id="text-orge924f4c"> <ul class="org-ul"> <li>cmake</li> <li>sqlite3-dev</li> @@ -384,24 +377,24 @@ You can also read the manual <a href="#manual">down below</a>. </div> </div> -<div id="outline-container-org5689497" class="outline-3"> -<h3 id="org5689497">make && install</h3> -<div class="outline-text-3" id="text-org5689497"> +<div id="outline-container-orga1d810a" class="outline-3"> +<h3 id="orga1d810a">make && install</h3> +<div class="outline-text-3" id="text-orga1d810a"> <p> Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install path. </p> <div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">clone the repo</span> +<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">clone the repo</span> > cd ~/code; git clone https://gitlab.com/grm-grm/ck -<span style="color: #656565;"># </span><span style="color: #757575;">make a build directory and enter it</span> -> mkdir ~/ck_build; <span style="color: #528fd1;">cd</span> ~/ck_build; -<span style="color: #656565;"># </span><span style="color: #757575;">run cmake</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">make a build directory and enter it</span> +> mkdir ~/ck_build; <span class="org-builtin">cd</span> ~/ck_build; +<span class="org-comment-delimiter"># </span><span class="org-comment">run cmake</span> > cmake ~/code/ck -<span style="color: #656565;"># </span><span style="color: #757575;">run make</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">run make</span> > make -<span style="color: #656565;"># </span><span style="color: #757575;">install it</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">install it</span> > make install -<span style="color: #656565;"># </span><span style="color: #757575;">run ck</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">run ck</span> > ck </pre> </div> @@ -409,23 +402,23 @@ Use <code>-DCMAKE_INSTALL_PREFIX</code> when running cmake to change the install </div> </div> -<div id="outline-container-org8db7ac9" class="outline-2"> -<h2 id="org8db7ac9">for devs</h2> -<div class="outline-text-2" id="text-org8db7ac9"> +<div id="outline-container-org421fdfb" class="outline-2"> +<h2 id="org421fdfb">for devs</h2> +<div class="outline-text-2" id="text-org421fdfb"> <p> Please be <a href="https://www.gnu.org/philosophy/kind-communication.html">kind</a> to each other. </p> </div> -<div id="outline-container-org42a6614" class="outline-3"> -<h3 id="org42a6614">CMake options</h3> -<div class="outline-text-3" id="text-org42a6614"> +<div id="outline-container-org98bcc06" class="outline-3"> +<h3 id="org98bcc06">CMake options</h3> +<div class="outline-text-3" id="text-org98bcc06"> <p> cmake accepts the following options: </p> <div class="org-src-container"> -<pre class="src src-cmake"><span style="color: #6aaf50;">option</span>(CK_DEBUG <span style="color: #bdbc61;">"Build with debug symbols, asan and warnings"</span>) -<span style="color: #6aaf50;">option</span>(CK_TESTS <span style="color: #bdbc61;">"Make the tests"</span>) -<span style="color: #6aaf50;">option</span>(CK_SHARED <span style="color: #bdbc61;">"Build with shared lib"</span>) +<pre class="src src-cmake"><span class="org-function-name">option</span>(CK_DEBUG <span class="org-string">"Build with debug symbols, asan and warnings"</span>) +<span class="org-function-name">option</span>(CK_TESTS <span class="org-string">"Make the tests"</span>) +<span class="org-function-name">option</span>(CK_SHARED <span class="org-string">"Build with shared lib"</span>) </pre> </div> @@ -439,41 +432,41 @@ To use any one of them append it after the cmake command like so: </div> </div> -<div id="outline-container-org5501d31" class="outline-3"> -<h3 id="org5501d31">compiler</h3> -<div class="outline-text-3" id="text-org5501d31"> +<div id="outline-container-org945fa72" class="outline-3"> +<h3 id="org945fa72">compiler</h3> +<div class="outline-text-3" id="text-org945fa72"> <p> Pick your favorite </p> <div class="org-src-container"> -<pre class="src src-sh">> export <span style="color: #baba36;">CC</span>=clang -<span style="color: #656565;"># </span><span style="color: #757575;">or</span> -> export <span style="color: #baba36;">CC</span>=gcc +<pre class="src src-sh">> export <span class="org-variable-name">CC</span>=clang +<span class="org-comment-delimiter"># </span><span class="org-comment">or</span> +> export <span class="org-variable-name">CC</span>=gcc </pre> </div> <div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">clone the repo</span> +<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">clone the repo</span> > cd ~/code; git clone https://gitlab.com/grm-grm/ck -<span style="color: #656565;"># </span><span style="color: #757575;">make a build directory and enter it</span> -> mkdir ~/ck_build; <span style="color: #528fd1;">cd</span> ~/ck_build; -<span style="color: #656565;"># </span><span style="color: #757575;">run cmake</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">make a build directory and enter it</span> +> mkdir ~/ck_build; <span class="org-builtin">cd</span> ~/ck_build; +<span class="org-comment-delimiter"># </span><span class="org-comment">run cmake</span> > cmake -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck -<span style="color: #656565;"># </span><span style="color: #757575;">run make</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">run make</span> > make -<span style="color: #656565;"># </span><span style="color: #757575;">check ck</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">check ck</span> > ./test-ck -<span style="color: #656565;"># </span><span style="color: #757575;">run ck</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">run ck</span> > ./ck </pre> </div> </div> </div> -<div id="outline-container-org3720cae" class="outline-3"> -<h3 id="org3720cae">tests</h3> -<div class="outline-text-3" id="text-org3720cae"> +<div id="outline-container-orge94d2b6" class="outline-3"> +<h3 id="orge94d2b6">tests</h3> +<div class="outline-text-3" id="text-orge94d2b6"> <p> The testing "suite" is a bash script that runs regression and unit tests. Regression tests are under the <code>tests/</code> directory @@ -482,9 +475,9 @@ under <code>unit/</code> directory and test the code. </p> </div> -<div id="outline-container-org7b06e14" class="outline-4"> -<h4 id="org7b06e14">run tests</h4> -<div class="outline-text-4" id="text-org7b06e14"> +<div id="outline-container-org6d98a70" class="outline-4"> +<h4 id="org6d98a70">run tests</h4> +<div class="outline-text-4" id="text-org6d98a70"> <p> First make sure you build ck with the <code>-DCK_TESTS=1</code> option. Then go to the build directory and type: @@ -496,9 +489,9 @@ go to the build directory and type: </div> </div> -<div id="outline-container-org7ad16bc" class="outline-4"> -<h4 id="org7ad16bc">test suite</h4> -<div class="outline-text-4" id="text-org7ad16bc"> +<div id="outline-container-orgdf6a992" class="outline-4"> +<h4 id="orgdf6a992">test suite</h4> +<div class="outline-text-4" id="text-orgdf6a992"> <div class="org-src-container"> <pre class="src src-sh">$ ./test-ck -h ck test suite @@ -516,400 +509,124 @@ flags: </div> </div> </div> -<div id="outline-container-orgfd8f2dc" class="outline-2"> -<h2 id="manual"><a id="orgfd8f2dc"></a>manual</h2> -<div class="outline-text-2" id="text-manual"> -<p> -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. -</p> - +<div id="outline-container-org5444b91" class="outline-2"> +<h2 id="org5444b91">ck configuration</h2> +<div class="outline-text-2" id="text-org5444b91"> <p> -Example usage: +See the <a href="#manpage">manpage</a> below. </p> -<div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">initialize new ck</span> -$ ck init /path_to/where_you_want/your_configs/to_be <span style="color: #bdbc61;">\</span> - /path_to/the_secret/directory - -<span style="color: #656565;"># </span><span style="color: #757575;">add emacs configs</span> -<span style="color: #656565;">## </span><span style="color: #757575;">primary config</span> -$ ck add emacs ~/.emacs.d/orgconf.org -p -<span style="color: #656565;">## </span><span style="color: #757575;">secret config, with passwords and naughty words</span> -$ ck add emacs ~/.emacs.d/accounts.org -s -<span style="color: #656565;">## </span><span style="color: #757575;">and another one for emacs</span> -$ ck add emacs ~/.emacs.d/init.el - -<span style="color: #656565;"># </span><span style="color: #757575;">add tmux config</span> -$ ck add tmux ~/.tmux.conf -p - -<span style="color: #656565;"># </span><span style="color: #757575;">list the configs</span> -$ ck list tree -$ ck list paths -t lisp -$ ck list programs -t python -$ ck list -p emacs - -<span style="color: #656565;"># </span><span style="color: #757575;">search the configs</span> -$ ck search search-term -$ ck search <span style="color: #bdbc61;">"\"search term with spaces\""</span> -$ ck search <span style="color: #bdbc61;">"\("</span> <span style="color: #656565;">#</span><span style="color: #757575;">escape symbols</span> -</pre> </div> - -<p> -The first command after typing <b>ck</b> is the action you wish to perform. Actions are -a very important concept of ck. With an action you can initialize <b>ck</b>, add/delete -configuration files to/from it, edit them, list them in various ways and search in their content. -</p> - -<p> -Actions expect their arguments in the order specified below. This is done to reduce the amount -of flags one has to pass to ck. -</p> </div> -<div id="outline-container-orgb40149d" class="outline-3"> -<h3 id="orgb40149d">ck configuration</h3> -<div class="outline-text-3" id="text-orgb40149d"> -<p> -ck uses sqlite to index the configuration files. The init -action creates a <b>.ck</b> directory (under <code>$HOME</code>) -in witch the <b>ckrc</b> and the <b>ckdb</b> reside. The first one contains -the two directories described above while the other one is the -sqlite db. -</p> - -<p> -One can have multiple config directories with different configurations -each. -</p> - +<div id="outline-container-org5727b06" class="outline-2"> +<h2 id="usage"><a id="org5727b06"></a>Usage</h2> +<div class="outline-text-2" id="text-usage"> <p> -Using the special keyword <b>config</b> (or <b>-c</b>) you can set the path -in which ck will search for the <b>.ck</b> directory. -</p> - -<p> -You can prefix every action with this and ck will use the configuration -directory of your choice. +ck's goal is to assist with the configuration file management. </p> <p> -Usage: +This section is an example usage. </p> -<div class="org-src-container"> -<pre class="src src-sh">$ ck config ~/ ... <span style="color: #656565;"># </span><span style="color: #757575;">the default behaviour</span> - -<span style="color: #656565;"># </span><span style="color: #757575;">/someplace/else must exist or</span> -<span style="color: #656565;"># </span><span style="color: #757575;">the action following it must be init</span> -$ ck -c /someplace/else ... -</pre> -</div> -</div> </div> - -<div id="outline-container-org52aba1d" class="outline-3"> -<h3 id="org52aba1d">Actions</h3> -<div class="outline-text-3" id="text-org52aba1d"> -</div> -<div id="outline-container-org7ba72be" class="outline-4"> -<h4 id="org7ba72be">init</h4> -<div class="outline-text-4" id="text-org7ba72be"> -<p> -or i or -i -</p> - -<p> -init takes exactly 2 arguments. -</p> - -<ul class="org-ul"> -<li><b>config_dir</b>: where all the configs will live</li> -<li><b>secret_dir</b>: where all the secret configs will live</li> -</ul> - -<p> -Use init to initialize a new ck database. -</p> - -<p> -Usage: -</p> +<div id="outline-container-orgd2e5354" class="outline-3"> +<h3 id="orgd2e5354">Initialize</h3> +<div class="outline-text-3" id="text-orgd2e5354"> <div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">initialize new ck</span> -$ ck init /path_to/where_you_want/your_configs/to_be <span style="color: #bdbc61;">\</span> - /path_to/the_secret/directory -</pre> -</div> -</div> -</div> - -<div id="outline-container-org9ae26ce" class="outline-4"> -<h4 id="org9ae26ce">add</h4> -<div class="outline-text-4" id="text-org9ae26ce"> -<p> -or a or -a -</p> - -<p> -Adds a configuration to the ck database. -Add takes 2 to 4 arguments. -</p> - -<ul class="org-ul"> -<li><b>program_name</b>: the name of the program you add a config to</li> -<li><b>config_path</b>: the path to the config</li> -<li>Optional: (order doesn't matter) -<ul class="org-ul"> -<li><b>-p</b>: the config will be the primary (relevant on edit below)</li> -<li><b>-s</b>: the config will be stored in the secret_dir</li> -</ul></li> -</ul> - -<p> -Keep in mind: -</p> -<ul class="org-ul"> -<li>The config has to exist.</li> -<li>If you are adding a config to a program already existing in ckdb make -sure to use the same name.</li> -<li>Each program can have only one primary config.</li> -</ul> +<pre class="src src-sh"><span class="org-builtin">cd</span> ~ +<span class="org-comment-delimiter"># </span><span class="org-comment">make the directories for the configs</span> +$ mkdir -p configs/vc configs/sec -<p> -Usage: -</p> -<div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">add config to ck</span> -$ ck add program_name config_path [-s] [-p] +<span class="org-comment-delimiter"># </span><span class="org-comment">initialize new ck</span> +$ ck init configs/vc configs/sec </pre> </div> </div> </div> -<div id="outline-container-orgb4adc9b" class="outline-4"> -<h4 id="orgb4adc9b">list</h4> -<div class="outline-text-4" id="text-orgb4adc9b"> -<p> -or ls or l or -l -</p> - -<p> -List stuff ck knows about. -</p> - -<p> -You can use the keywords: -</p> -<ul class="org-ul"> -<li><b>paths</b>: to print all the paths ck tracks</li> -<li><b>programs</b>: to print all the programs ck tracks</li> -<li><b>-p progName</b>: (without the "<>") to print the paths of a specific program</li> -</ul> - -<p> -With the flag <b>-t</b> and then one of the follwing types one can change -the way the list is printed: -</p> -<ul class="org-ul"> -<li><b>plain</b>: simple listing (default)</li> -<li><b>python</b>: print like a python list</li> -<li><b>lisp</b>: print like a lisp list</li> -</ul> - -<p> -Using the keyword <b>tree</b> ck can list the configurations under their -corresponding program, in a treelike structure. -</p> - -<p> -Passing the <b>-a</b> flag will enable the listing of config attributes (secret or primary). -It is best used with tree or plain paths. -</p> - -<p> -With the keyword <b>ckconf</b> ck will list it's own configuration values (in ckrc). -</p> - -<p> -Usage: -</p> +<div id="outline-container-orgfc9d01c" class="outline-3"> +<h3 id="orgfc9d01c">Add configs</h3> +<div class="outline-text-3" id="text-orgfc9d01c"> <div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">list tree structure, with attributes</span> -$ ck list tree -a -<span style="color: #656565;"># </span><span style="color: #757575;">list paths in python</span> -$ ck l paths -t python -<span style="color: #656565;"># </span><span style="color: #757575;">list programs in lisp</span> -$ ck ls programs -t lisp -<span style="color: #656565;"># </span><span style="color: #757575;">list emacs' configurations [with attributes]</span> -$ ck ls -p emacs [-a] -<span style="color: #656565;"># </span><span style="color: #757575;">list bash configurations in lisp</span> -$ ck ls -p bash -t lisp -<span style="color: #656565;"># </span><span style="color: #757575;">list ck configuration</span> -$ ck -l ckconf +<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">add emacs configs</span> +<span class="org-comment-delimiter">## </span><span class="org-comment">primary config</span> +$ ck add emacs .emacs.d/orgconf.org -p +<span class="org-comment-delimiter">## </span><span class="org-comment">secret config, with passwords and naughty words</span> +$ ck add emacs .emacs.d/accounts.org -s +<span class="org-comment-delimiter">## </span><span class="org-comment">and another one for emacs</span> +$ ck add emacs .emacs.d/init.el + +<span class="org-comment-delimiter"># </span><span class="org-comment">add tmux config</span> +$ ck add tmux .tmux.conf -p + +<span class="org-comment-delimiter"># </span><span class="org-comment">add X configs</span> +$ ck add X .xinitrc +$ ck add X .Xresources + +<span class="org-comment-delimiter"># </span><span class="org-comment">add ssh configs (secret)</span> +$ ck add ssh .ssh/config -s -p +$ ck add ssh .ssh/authorized_keys -s +<span class="org-comment-delimiter"># </span><span class="org-comment">When running with sudo, we need to specify the ck config</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">location.</span> +$ sudo ck -c /home/ckuser add ssh /etc/ssh/sshd_config -s </pre> </div> </div> </div> -<div id="outline-container-org442a05c" class="outline-4"> -<h4 id="org442a05c">search</h4> -<div class="outline-text-4" id="text-org442a05c"> -<p> -or grep or s or -s -</p> - -<p> -Perform infile grep in all the configurations ck keeps track of. -</p> - -<p> -Takes one argument, the <b>search-term</b>. -</p> - -<p> -To search for terms with spaces you have to put them in quotes. -</p> - -<p> -Usage: -</p> +<div id="outline-container-orga6dee7d" class="outline-3"> +<h3 id="orga6dee7d">Using the ck actions</h3> +<div class="outline-text-3" id="text-orga6dee7d"> <div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">search for parenthesis</span> -$ ck search <span style="color: #bdbc61;">\(</span> -<span style="color: #656565;"># </span><span style="color: #757575;">search term with spaces</span> -$ ck grep <span style="color: #bdbc61;">"This is a space"</span> -<span style="color: #656565;"># </span><span style="color: #757575;">both</span> -$ ck s <span style="color: #bdbc61;">"(add 2 4)"</span> -<span style="color: #656565;"># </span><span style="color: #757575;">and a normal one</span> -$ ck -s alias -</pre> -</div> - -<p> -If you want to use more advanced grep techniques or even -a different pattern matching program you can do it like so: -</p> - -<div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">with xargs</span> -$ ck ls paths | xargs grep -E <span style="color: #bdbc61;">'A|B'</span> -<span style="color: #656565;"># </span><span style="color: #757575;">or in bash</span> -$ for i<span style="color: #5180b3;"> in</span> $(ck ls paths); <span style="color: #5180b3;">do</span> grep -E <span style="color: #bdbc61;">'A|B'</span> $<span style="color: #baba36;">i</span>; <span style="color: #5180b3;">done</span> -<span style="color: #656565;"># </span><span style="color: #757575;">or in zsh</span> -$ for i ($(ck ls paths)) grep -E <span style="color: #bdbc61;">'A|B'</span> $<span style="color: #baba36;">i</span> -</pre> -</div> -</div> -</div> - -<div id="outline-container-org6320932" class="outline-4"> -<h4 id="org6320932">edit</h4> -<div class="outline-text-4" id="text-org6320932"> -<p> -or e or -e -</p> - -<p> -Edit configurations with <code>$EDITOR</code>. -</p> - -<p> -Edit takes at least one and up to two arguments. -</p> +<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">list the configs in a treelike structure with basename only</span> +$ ck list tree -b +<span class="org-comment-delimiter"># </span><span class="org-comment">or with the full path & attributes</span> +$ ck list tree -a -<p> -The first argument is the <b>programName</b>. 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. -</p> +<span class="org-comment-delimiter"># </span><span class="org-comment">list only the paths in python or lisp like lists</span> +$ ck list paths -t lisp +$ ck list programs -t python -b -a -<p> -The second argument is the <b>configName</b>. If it exists it will open, else it will -print the avaliable configurations and exit. -</p> +<span class="org-comment-delimiter"># </span><span class="org-comment">list emacs configs</span> +$ ck list -p emacs -<p> -Usage: -</p> -<div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">suppose this is our ck instance</span> -$ ck list tree -a -emacs: -|- init.el -|- accounts.el [s] -|- orgconf.org [p] +<span class="org-comment-delimiter"># </span><span class="org-comment">search the configs</span> +$ ck search Hostname +$ ck search <span class="org-string">"search term with spaces"</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">escape symbols</span> +$ ck search <span class="org-string">\(</span> -<span style="color: #656565;"># </span><span style="color: #757575;">edit the primary emacs config</span> +<span class="org-comment-delimiter"># </span><span class="org-comment">edit the primary config of emacs</span> $ ck edit emacs - -<span style="color: #656565;"># </span><span style="color: #757575;">edit a specific emacs config, other than the primary</span> -$ ck edit emacs accounts.el +<span class="org-comment-delimiter"># </span><span class="org-comment">edit a non-primary config of ssh</span> +$ ck e ssh authorized_keys +<span class="org-comment-delimiter"># </span><span class="org-comment">edit a root config</span> +$ sudo ck -c /home/ckuser e ssh sshd_config + +<span class="org-comment-delimiter"># </span><span class="org-comment">delete a program with all the configs</span> +$ ck delete emacs +<span class="org-comment-delimiter"># </span><span class="org-comment">or a specific config</span> +$ ck del -c /home/ckuser/.emacs.d/init.el + +<span class="org-comment-delimiter"># </span><span class="org-comment">restore all links (on a new instalation)</span> +$ ck restore all +<span class="org-comment-delimiter"># </span><span class="org-comment">restore a program's links</span> +$ ck r -p emacs + +<span class="org-comment-delimiter"># </span><span class="org-comment">get help for an action</span> +$ ck h add +$ ck --help e </pre> </div> </div> </div> - -<div id="outline-container-orgae8e7fb" class="outline-4"> -<h4 id="orgae8e7fb">restore</h4> -<div class="outline-text-4" id="text-orgae8e7fb"> -<p> -or r or -r -</p> - -<p> -Restore links. -</p> - -<p> -Given a working ck instance (ckdb + ckrc + directories in ckrc with configs) -restore shall recreate the links from the config directories in ckrc -back to their corresponding position when added in ck. -</p> - -<p> -It is useful for copying your configs to a new linux installation -or restoring deleted links. -</p> - -<p> -It can either restore a specific program or all of them: -</p> -<div class="org-src-container"> -<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">restore progName</span> -ck restore -p progName -<span style="color: #656565;"># </span><span style="color: #757575;">restore all</span> -ck r all -</pre> </div> -<p> -Note: -If ck tracks configs that are owned by root, simply running -`ck restore …` will fail due to permissions. To remedy this, ck will alter the -owner and group of a link to match the one in the ckrc directories. -Thus, running `sudo ck -c <i>home/myuser</i>.ck restore ..` will restore -the root user's links as it should and the user links will have -the user as the owner instead of the root. -</p> - -<p> -ck checks that the configs exist and that the location for the link -is avaliable before making any links. However, in the even that symlink -fails for some other reason, the process will stop as is. Make sure you -take care of the already created links, if that's the case. -</p> -</div> -</div> -</div> -</div> -<div id="outline-container-orgf44bdc3" class="outline-2"> -<h2 id="orgf44bdc3">manpage</h2> -<div class="outline-text-2" id="text-orgf44bdc3"> +<div id="outline-container-org9df6fcc" class="outline-2"> +<h2 id="manpage"><a id="org9df6fcc"></a>manpage</h2> +<div class="outline-text-2" id="text-manpage"> <!-- Creator : groff version 1.22.3 --> -<!-- CreationDate: Sun Oct 28 13:22:50 2018 --> +<!-- CreationDate: Mon Oct 29 17:20:18 2018 --> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> @@ -933,6 +650,7 @@ take care of the already created links, if that's the case. <a href="#NAME">NAME</a><br> <a href="#SYNOPSIS">SYNOPSIS</a><br> <a href="#DESCRIPTION">DESCRIPTION</a><br> +<a href="#CONFIGURATION">CONFIGURATION</a><br> <a href="#OPTIONS">OPTIONS</a><br> <a href="#ACTIONS">ACTIONS</a><br> <a href="#EXIT STATUS">EXIT STATUS</a><br> @@ -968,11 +686,12 @@ ck add</b> <i>PROGRAM_NAME CONFIG_PATH</i> [<b>−p</b>] ck delete</b> <i>PROGRAM_NAME</i>|{<b>−c </b><i>CONFIG_PATH</i>} <b><br> -ck list tree </b>[<b>−a</b>] <b><br> +ck list tree </b>[<b>−a</b>] [<b>−b</b>] +<b><br> ck list</b> {<b>-p </b><i>PROGRAM_NAME</i>}|<b>programs</b>|<b>paths </b>[<b>−t</b> {<b>plain</b>|<b>python</b>|<b>lisp</b>}] [<b>−a</b>] -<b><br> +[<b>−b</b>] <b><br> ck list ckconf <br> ck edit</b> <i>PROGRAM_NAME </i>[<i>CONFIG_BASENAME</i>] <b><br> @@ -1015,6 +734,26 @@ you can sync the <i>VERSION_CONRTOL_DIR</i> and given these two directories and the correspondig rc file and database.</p> +<h2>CONFIGURATION +<a name="CONFIGURATION"></a> +</h2> + + +<p style="margin-left:11%; margin-top: 1em"><b>ck</b> uses +<b>sqlite</b> to index the configuration files. The <b>init +action</b> by default creates a directory named <i>.ck</i> +under <i>$HOME</i> in witch the <i>ckrc</i> and <i>ckdb</i> +files reside. See the <b>FILES</b> section for more +details.</p> + +<p style="margin-left:11%; margin-top: 1em">One can have +multiple <b>config directories</b> with different +configurations each. Using the +<b>config </b>or <b>−c</b> option one can +set the path in which ck will search for <i>ckrc</i> and +<i>ckdb</i>. See the <b>OPTIONS</b> section for more +details.</p> + <h2>OPTIONS <a name="OPTIONS"></a> </h2> @@ -1204,11 +943,11 @@ List programs, configs and ck configuration values.</p> <p style="margin-left:11%; margin-top: 1em"><b>USAGE</b></p> <p style="margin-left:14%;"><b>ck list -tree </b>[<b>−a</b>] <b><br> +tree </b>[<b>−a</b>] [<b>−b</b>] <b><br> ck list</b> {<b>-p </b><i>PROGRAM_NAME</i>}|<b>programs</b>|<b>paths </b>[<b>−t</b> {<b>plain</b>|<b>python</b>|<b>lisp</b>}] [<b>−a</b>] -<b><br> +[<b>−b</b>] <b><br> ck list ckconf</b></p> @@ -1269,6 +1008,12 @@ or <b>lisp</b> to print it like a lisp list.</p> <b>[root]</b> if the file is owned by the root user.</p> +<p style="margin-left:14%; margin-top: 1em"><b>−b</b></p> + +<p style="margin-left:17%;">Print the <b>config</b> +basename instead of the full path.</p> + + <p style="margin-left:11%; margin-top: 1em"><b>EXAMPLES</b></p> <p style="margin-left:14%;">$ ck list tree -a <br> @@ -1374,6 +1119,32 @@ installation or <b>restoring</b> deleted links. It can either <b>restore</b> a specific <b>program</b> or all of them.</p> +<p style="margin-left:11%; margin-top: 1em"><b>NOTE</b>: If +<b>ck</b> tracks <b>configs</b> that are owned by root, +simply running</p> + +<p style="margin-left:14%;">$ ck restore ...</p> + +<p style="margin-left:11%;">will fail due to permissions. +To remedy this, <b>ck</b> will alter the +<b>owner </b>and <b>group</b> of a link to match +the one in the original <b>config</b> file. Thus, +running</p> + +<p style="margin-left:14%;">$ sudo ck -c /home/ckuser/.ck +restore ...</p> + +<p style="margin-left:11%;">will <b>restore</b> the root +user’s links as it should and the user links will have +the user as the owner instead of the root.</p> + +<p style="margin-left:11%; margin-top: 1em"><b>ck</b> +checks that the <b>configs</b> exist and that the location +for the link is avaliable before making any links. However, +in the even that <b>symlink</b> fails for some other reason, +the process will stop as is. The user will have to take care +of the already created links, if that’s the case.</p> + <p style="margin-left:11%; margin-top: 1em"><b>USAGE</b></p> @@ -1514,7 +1285,7 @@ flags</b>: @CMAKE_C_FLAGS@</p> </div> </div> <div id="postamble" class="status"> -<p class="date">Created: 2018-10-28 Sun 13:22</p> +<p class="date">Created: 2018-10-29 Mon 17:20</p> <p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p> </div> </body> @@ -47,7 +47,7 @@ that explains any inquires you might have. Grab the latest zip/tarball from the tag section in the [[https://ubuntos.dynu.net/git/ck][repo]] and proceed to the [[#build-instructions][build]] section. -You can also read the manual [[#manual][down below]]. +You can also read the manpage [[#manpage][down below]]. * build it :PROPERTIES: @@ -140,254 +140,97 @@ flags: use if the tests crush unexpectedly -h, --help, * print this #+END_SRC -* manual +* ck configuration +See the [[#manpage][manpage]] below. + +* Usage :PROPERTIES: - :CUSTOM_ID: manual + :CUSTOM_ID: usage :END: 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: +This section is an example usage. +** Initialize #+BEGIN_SRC sh + cd ~ + # make the directories for the configs + $ mkdir -p configs/vc configs/sec + # initialize new ck - $ ck init /path_to/where_you_want/your_configs/to_be \ - /path_to/the_secret/directory + $ ck init configs/vc configs/sec +#+END_SRC +** Add configs +#+BEGIN_SRC sh # add emacs configs ## primary config - $ ck add emacs ~/.emacs.d/orgconf.org -p + $ ck add emacs .emacs.d/orgconf.org -p ## secret config, with passwords and naughty words - $ ck add emacs ~/.emacs.d/accounts.org -s + $ ck add emacs .emacs.d/accounts.org -s ## and another one for emacs - $ ck add emacs ~/.emacs.d/init.el + $ 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 - $ ck list -p emacs - - # 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/delete -configuration files to/from 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 *-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. + $ ck add tmux .tmux.conf -p -Usage: -#+BEGIN_SRC sh - $ ck config ~/ ... # the default behaviour - - # /someplace/else must exist or - # the action following it must be init - $ ck -c /someplace/else ... -#+END_SRC - -** Actions -*** init -or i or -i + # add X configs + $ ck add X .xinitrc + $ ck add X .Xresources -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 + # add ssh configs (secret) + $ ck add ssh .ssh/config -s -p + $ ck add ssh .ssh/authorized_keys -s + # When running with sudo, we need to specify the ck config + # location. + $ sudo ck -c /home/ckuser add ssh /etc/ssh/sshd_config -s #+END_SRC -*** 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: +** Using the ck actions #+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 stuff ck knows about. - -You can use the keywords: -- *paths*: to print all the paths ck tracks -- *programs*: to print all the programs ck tracks -- *-p progName*: (without the "<>") to print the paths of a specific program - -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, in a treelike structure. - -Passing the *-a* flag will enable the listing of config attributes (secret or primary). -It is best used with tree or plain paths. - -With the keyword *ckconf* ck will list it's own configuration values (in ckrc). - -Usage: -#+BEGIN_SRC sh - # list tree structure, with attributes + # list the configs in a treelike structure with basename only + $ ck list tree -b + # or with the full path & attributes $ ck list tree -a - # list paths in python - $ ck l paths -t python - # list programs in lisp - $ ck ls programs -t lisp - # list emacs' configurations [with attributes] - $ ck ls -p emacs [-a] - # list bash configurations in lisp - $ ck ls -p bash -t lisp - # list ck configuration - $ ck -l ckconf -#+END_SRC -*** search -or grep or s or -s - -Perform infile grep in all the configurations ck keeps track of. - -Takes one argument, the *search-term*. + # list only the paths in python or lisp like lists + $ ck list paths -t lisp + $ ck list programs -t python -b -a -To search for terms with spaces you have to put them in quotes. + # list emacs configs + $ ck list -p emacs -Usage: -#+BEGIN_SRC sh - # search for parenthesis + # search the configs + $ ck search Hostname + $ ck search "search term with spaces" + # escape symbols $ ck search \( - # search term with spaces - $ ck grep "This is a space" - # both - $ ck s "(add 2 4)" - # and a normal one - $ ck -s alias -#+END_SRC -If you want to use more advanced grep techniques or even -a different pattern matching program you can do it like so: + # edit the primary config of emacs + $ ck edit emacs + # edit a non-primary config of ssh + $ ck e ssh authorized_keys + # edit a root config + $ sudo ck -c /home/ckuser e ssh sshd_config -#+BEGIN_SRC sh - # 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 -#+END_SRC - -*** edit -or e or -e - -Edit configurations with =$EDITOR=. - -Edit takes at least one and up to two arguments. + # delete a program with all the configs + $ ck delete emacs + # or a specific config + $ ck del -c /home/ckuser/.emacs.d/init.el -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. + # restore all links (on a new instalation) + $ ck restore all + # restore a program's links + $ ck r -p emacs -The second argument is the *configName*. If it exists it will open, else it will -print the avaliable configurations and exit. - -Usage: -#+BEGIN_SRC sh -# 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 + # get help for an action + $ ck h add + $ ck --help e #+END_SRC -*** restore -or r or -r - -Restore links. - -Given a working ck instance (ckdb + ckrc + directories in ckrc with configs) -restore shall recreate the links from the config directories in ckrc -back to their corresponding position when added in ck. - -It is useful for copying your configs to a new linux installation -or restoring deleted links. - -It can either restore a specific program or all of them: -#+BEGIN_SRC sh - # restore progName - ck restore -p progName - # restore all - ck r all -#+END_SRC - -Note: -If ck tracks configs that are owned by root, simply running -`ck restore ...` will fail due to permissions. To remedy this, ck will alter the -owner and group of a link to match the one in the ckrc directories. -Thus, running `sudo ck -c /home/myuser/.ck restore ..` will restore -the root user's links as it should and the user links will have -the user as the owner instead of the root. - -ck checks that the configs exist and that the location for the link -is avaliable before making any links. However, in the even that symlink -fails for some other reason, the process will stop as is. Make sure you -take care of the already created links, if that's the case. * manpage + :PROPERTIES: + :CUSTOM_ID: manpage + :END: #+BEGIN_SRC sh :results output html :exports results groff ck.1 -mandoc -Thtml #+END_SRC @@ -24,11 +24,13 @@ ck \- manage configuration across the system .br .B ck list .BR tree \ [ \-a ] +.RB [ \-b ] .br .B ck list .RB { -p \ \fIPROGRAM_NAME\fR}\fR| programs | paths \ [ \-t .RB { plain | python | lisp } \fR] .RB [ \-a ] +.RB [ \-b ] .br .B ck list ckconf .br @@ -87,6 +89,39 @@ and You can also .B restore the links given these two directories and the correspondig rc file and database. + +.SH CONFIGURATION +.B ck +uses +.B sqlite +to index the configuration files. The +.B init action +by default creates a directory named +.I .ck +under +.I $HOME +in witch the +.I ckrc +and +.I ckdb +files reside. See the +.B FILES +section for more details. +.P +One can have multiple +.B config directories +with different configurations each. +Using the +.BR config \ or \ \-c +option one can set the path +in which ck will search for +.I ckrc +and +.IR ckdb . +See the +.B OPTIONS +section for more details. +.P .SH OPTIONS Change .B ck @@ -310,11 +345,13 @@ List programs, configs and ck configuration values. .in +.2i .B ck list .BR tree \ [ \-a ] +.RB [ \-b ] .br .B ck list .RB { -p \ \fIPROGRAM_NAME\fR}\fR| programs | paths \ [ \-t .RB { plain | python | lisp } \fR] .RB [ \-a ] +.RB [ \-b ] .br .B ck list ckconf .br @@ -394,6 +431,13 @@ and .B [root] if the file is owned by the root user. .P +.in +.2i +.B \-b +.in +.2i +Print the +.B config +basename instead of the full path. +.P .B EXAMPLES .in +.2i $ ck list tree -a @@ -525,6 +569,42 @@ a specific .B program or all of them. .P +.BR NOTE : +If +.B ck +tracks +.B configs +that are owned by root, simply running +.br +.in +.2i +$ ck restore \.\.\. +.in +.br +will fail due to permissions. To remedy this, +.B ck +will alter the +.BR owner \ and \ group +of a link to match the one in the original +.B config +file. +Thus, running +.in +.2i +$ sudo ck -c /home/ckuser/.ck restore \.\.\. +.in +will +.B restore +the root user's links as it should and the user links will have +the user as the owner instead of the root. +.P +.B ck +checks that the +.B configs +exist and that the location for the link +is avaliable before making any links. However, in the even that +.B symlink +fails for some other reason, the process will stop as is. The user will have to +take care of the already created links, if that's the case. +.P .B USAGE .br .in +.2i diff --git a/src/actionhelper.c b/src/actionhelper.c index 6428ab0..5899024 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -202,6 +202,7 @@ ListOpt list_make_options(cklist *args) { ._lst = LST_PLAIN, .pName = NULL, .attr = 0, + .bName = 0, .err = 0 }; @@ -211,6 +212,10 @@ ListOpt list_make_options(cklist *args) { listOpt.attr = 1; continue; } + if (strcmp(list_get(args), "-b") == 0) { + listOpt.bName = 1; + continue; + } if (strcmp(list_get(args), "-t") == 0) { if (!list_next(args)) { listOpt.err = 1; @@ -421,7 +426,8 @@ void print_LIST_help() { ckhelp(" `-p program_name`: list only the configs of the specified program."); ckhelp(" `ckconf`: list the ck configuration values.\n"); ckhelp("There are also some flags:"); - ckhelp(" `-a`: add the attributes next to the config paths (secret,primary)"); + ckhelp(" `-a`: add the attributes next to the config paths (secret,primary,root)"); + ckhelp(" `-b`: print the config basenames instead of the full path"); ckhelp(" `-t`: change the list type. (does not work with tree or ckconf)"); ckhelp(" `plain`: default plain listing"); ckhelp(" `python`: enclose the list in [ , ]"); diff --git a/src/actionparser.c b/src/actionparser.c index f04c1d5..1648372 100644 --- a/src/actionparser.c +++ b/src/actionparser.c @@ -123,9 +123,9 @@ int parse_EDIT(UserOpt *opt) { } int parse_LIST(UserOpt *opt) { - /* List expects 1 to 5 arguments */ + /* List expects 1 to 6 arguments */ if (optNum < pos + 1 - || optNum > pos + 5) { + || optNum > pos + 6) { opt->err = PERR_LIST_WRONG; return -1; } @@ -360,7 +360,7 @@ void print_parser_error(UserOpt *opt) { sprintf(errStr, "Edit config with $EDITOR (%s)\nUsage: %s ProgramName [configBasename]", getenv("EDITOR"), names); break; case PERR_LIST_WRONG: - sprintf(errStr, "List programs, configs and more\nUsage: %s {programs|paths|-p ProgramName} [-t list-type] | {tree | ckconf} [-a]", names); + sprintf(errStr, "List programs, configs and more\nUsage: %s {programs|paths|-p ProgramName} [-t list-type] | {tree | ckconf} [-a] [-b]", names); break; case PERR_SEARCH_WRONG: sprintf(errStr, "Search through the configs with grep\nUsage: %s search-term", names); diff --git a/src/actions.c b/src/actions.c index 649ffb8..ddfe9b9 100644 --- a/src/actions.c +++ b/src/actions.c @@ -179,13 +179,13 @@ int run_LIST(UserOpt *opt, Conf *conf) { char tmp[STR_L] = ""; switch(listOpt._lt) { case LT_PATH: - list_get_paths(&db, the_list, listOpt.attr); + list_get_paths(&db, the_list, listOpt.bName, listOpt.attr); break; case LT_PROGRAM: list_get_programs(&db, the_list); break; case LT_TREE: - list_get_path_program_tree(&db, the_list, listOpt.attr); + list_get_path_program_tree(&db, the_list, listOpt.bName, listOpt.attr); list_print(the_list); goto close; case LT_CKCONF: @@ -207,7 +207,7 @@ int run_LIST(UserOpt *opt, Conf *conf) { ERR("Program %s doesn't exist in the database.", listOpt.pName); goto error; } - get_program_paths(&db, the_list, listOpt.pName, 0, listOpt.attr); + get_program_paths(&db, the_list, listOpt.pName, listOpt.bName, listOpt.attr); break; } switch(listOpt._lst) { @@ -237,7 +237,7 @@ int run_SEARCH(UserOpt *opt, Conf *conf) { } DB db = open_DB(opt); cklist *paths = list_make_new(); - list_get_paths(&db, paths, 0); + list_get_paths(&db, paths, 0 /*basename*/, 0/*attributes*/); close_DB(&db); if (list_size(paths) && list_size(opt->args)) { do { diff --git a/src/actions.h b/src/actions.h index 69c5616..e6fe336 100644 --- a/src/actions.h +++ b/src/actions.h @@ -77,6 +77,7 @@ struct ListOptions { ListShowType _lst; char *pName; int attr; + int bName; int err; }; diff --git a/src/dblayer.c b/src/dblayer.c index f517dbe..244db62 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -363,6 +363,16 @@ int add_get_or_insert_program_to_db(DB *db, const char *name) { return pid; } +int add_basename_exists(DB *db, const char *pName, const char *path) { + cklist *baseNames = list_make_new(); + get_program_paths(db, baseNames, pName, 1 /*basename */, 0); + char *tmp = strdup(path); + int rc = list_exists(baseNames, basename(tmp)); + free(tmp); + list_free(baseNames); + return rc; +} + int add_transaction_try(DB *db, const AddOpt * const opt) { __BEGIN_TRANSACTION__ int pid = add_get_or_insert_program_to_db(db, opt->progName); @@ -370,6 +380,10 @@ int add_transaction_try(DB *db, const AddOpt * const opt) { PRINT_ERR("Could not insert program to db.\n"); return 1; } + if (add_basename_exists(db, opt->progName, opt->confPath)) { + ERR("Cannot have two configs with the same basename, for the same program."); + return 1; + } int cid = add_get_or_insert_config_to_db(db, pid, opt->confPath, opt->secret, opt->prime); if (db->error == SQL_ERR_SQLITE) { PRINT_ERR("Could not insert config to db.\n"); @@ -540,7 +554,7 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att return -1; } -int list_get_paths(DB *db, cklist *ckl, int attr) { +int list_get_paths(DB *db, cklist *ckl, int bName, int attr) { sqlite3_stmt *stmt; int rc; @@ -553,8 +567,15 @@ int list_get_paths(DB *db, cklist *ckl, int attr) { } while (sqlite3_step(stmt) == SQLITE_ROW) { + char *tmp = strdup((char *)sqlite3_column_text(stmt, 0)); char path[STR_L] = ""; - strcat(path, (char *)sqlite3_column_text(stmt, 0)); + if (bName) { + strcat(path, basename(tmp)); + } + else { + strcat(path, tmp); + } + free(tmp); if (attr) { /* secret */ if (sqlite3_column_int(stmt, 1)) { @@ -596,7 +617,7 @@ int list_get_programs(DB *db, cklist *ckl) { return 1; } -int list_get_path_program_tree(DB *db, cklist *ckl, int attr) { +int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr) { sqlite3_stmt *stmt; int rc; @@ -638,7 +659,14 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int attr) { sqlite3_bind_text(stmt2, 1, (char *)sqlite3_column_text(stmt, 0), -1, 0); while (sqlite3_step(stmt2) == SQLITE_ROW) { char treePath[STR_L] = "|- "; - strcat(treePath, (char *)sqlite3_column_text(stmt2, 0)); + char *tmp = strdup((char *)sqlite3_column_text(stmt2, 0)); + if (bName) { + strcat(treePath, basename(tmp)); + } + else { + strcat(treePath, tmp); + } + free(tmp); if (attr) { /* secret */ if (sqlite3_column_int(stmt2, 1)) { diff --git a/src/dblayer.h b/src/dblayer.h index 13ac187..20ab4b2 100644 --- a/src/dblayer.h +++ b/src/dblayer.h @@ -43,7 +43,7 @@ extern DB open_DB(const UserOpt *opt); extern void close_DB(DB *db); extern int program_exists(DB *db, const char *pName); -extern int get_program_paths(DB *db, cklist *ckl, const char* pName, int basename, int attr); +extern int get_program_paths(DB *db, cklist *ckl, const char* pName, int bName, int attr); /********/ /* init */ @@ -72,9 +72,9 @@ extern int edit_get_config(DB *db, const char *pName, char *ret, const char *cNa /* list */ /********/ -extern int list_get_paths(DB *db, cklist *ckl, int attr); +extern int list_get_paths(DB *db, cklist *ckl, int bName, int attr); extern int list_get_programs(DB *db, cklist *ckl); -extern int list_get_path_program_tree(DB *db, cklist *ckl, int attr); +extern int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr); /*******/ /* del */ |