aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-10-09 20:53:30 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-10-09 20:53:30 +0300
commit598e0522de924a50ea9c640955daab8512029eb4 (patch)
tree3f3cf027349a414e2f24d1a4c7976916e8b7dc21
parentfe781e5ae7116733e5b335a0ac016af97266db5f (diff)
downloadck-598e0522de924a50ea9c640955daab8512029eb4.tar.gz
ck-598e0522de924a50ea9c640955daab8512029eb4.tar.bz2
ck-598e0522de924a50ea9c640955daab8512029eb4.zip
Better list
-rw-r--r--README.html284
-rw-r--r--README.org18
-rw-r--r--src/actionhelper.c21
-rw-r--r--src/actionparser.c8
-rw-r--r--src/actions.c37
-rw-r--r--src/actions.h5
-rw-r--r--src/dblayer.c36
-rw-r--r--src/dblayer.h2
8 files changed, 248 insertions, 163 deletions
diff --git a/README.html b/README.html
index 2180663..45839fd 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-08 Mon 23:46 -->
+<!-- 2018-10-09 Tue 20:53 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>&lrm;</title>
@@ -232,35 +232,35 @@ for the JavaScript code in this tag.
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
-<li><a href="#org1c6aa01">ck</a></li>
-<li><a href="#orgbf1d4c5">build it</a>
+<li><a href="#org06be2ec">ck</a></li>
+<li><a href="#orgdd738de">build it</a>
<ul>
-<li><a href="#org8edf2df">requirements</a></li>
-<li><a href="#org30b18cc">compiler</a></li>
-<li><a href="#org28e3d41">make</a></li>
+<li><a href="#org00d5007">requirements</a></li>
+<li><a href="#org0c0a491">compiler</a></li>
+<li><a href="#org7ba7a71">make</a></li>
</ul>
</li>
-<li><a href="#orgcd61fbc">for devs</a>
+<li><a href="#org5cb365e">for devs</a>
<ul>
-<li><a href="#org713cf8f">CMake options</a></li>
-<li><a href="#orga6955dd">tests</a>
+<li><a href="#org148ba3a">CMake options</a></li>
+<li><a href="#org20e80d6">tests</a>
<ul>
-<li><a href="#org6219fcc">run tests</a></li>
-<li><a href="#orgd4349ab">test suite</a></li>
+<li><a href="#org75775b9">run tests</a></li>
+<li><a href="#orgf7207a9">test suite</a></li>
</ul>
</li>
</ul>
</li>
-<li><a href="#org1d127b7">manual</a>
+<li><a href="#org3401884">manual</a>
<ul>
-<li><a href="#orge5785e3">ck configuration</a></li>
-<li><a href="#orga717caf">Actions</a>
+<li><a href="#org41c11d4">ck configuration</a></li>
+<li><a href="#org72890ad">Actions</a>
<ul>
-<li><a href="#org29304ac">init</a></li>
-<li><a href="#org8841e7c">add</a></li>
-<li><a href="#orgc9a5e19">list</a></li>
-<li><a href="#org73e5182">search</a></li>
-<li><a href="#org9b41294">edit</a></li>
+<li><a href="#org3b0ec54">init</a></li>
+<li><a href="#orgc9498d4">add</a></li>
+<li><a href="#orge78ef4d">list</a></li>
+<li><a href="#org914dcb8">search</a></li>
+<li><a href="#orga1030cc">edit</a></li>
</ul>
</li>
</ul>
@@ -269,22 +269,22 @@ for the JavaScript code in this tag.
</div>
</div>
<p align="center"><img src="res/logo.png" width="30%" height="30%" /></p>
-<div id="outline-container-org1c6aa01" class="outline-2">
-<h2 id="org1c6aa01">ck</h2>
-<div class="outline-text-2" id="text-org1c6aa01">
+<div id="outline-container-org06be2ec" class="outline-2">
+<h2 id="org06be2ec">ck</h2>
+<div class="outline-text-2" id="text-org06be2ec">
<p>
<b>The Config Keeper</b>
</p>
</div>
</div>
-<div id="outline-container-orgbf1d4c5" class="outline-2">
-<h2 id="orgbf1d4c5">build it</h2>
-<div class="outline-text-2" id="text-orgbf1d4c5">
+<div id="outline-container-orgdd738de" class="outline-2">
+<h2 id="orgdd738de">build it</h2>
+<div class="outline-text-2" id="text-orgdd738de">
</div>
-<div id="outline-container-org8edf2df" class="outline-3">
-<h3 id="org8edf2df">requirements</h3>
-<div class="outline-text-3" id="text-org8edf2df">
+<div id="outline-container-org00d5007" class="outline-3">
+<h3 id="org00d5007">requirements</h3>
+<div class="outline-text-3" id="text-org00d5007">
<ul class="org-ul">
<li>clang (llvm) or gcc (gnu)</li>
<li>cmake</li>
@@ -293,31 +293,31 @@ for the JavaScript code in this tag.
</div>
</div>
-<div id="outline-container-org30b18cc" class="outline-3">
-<h3 id="org30b18cc">compiler</h3>
-<div class="outline-text-3" id="text-org30b18cc">
+<div id="outline-container-org0c0a491" class="outline-3">
+<h3 id="org0c0a491">compiler</h3>
+<div class="outline-text-3" id="text-org0c0a491">
<div class="org-src-container">
-<pre class="src src-sh">&gt; export <span style="color: #ffac4a;">CC</span>=clang
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">or</span>
-&gt; export <span style="color: #ffac4a;">CC</span>=gcc
+<pre class="src src-sh">&gt; export <span style="color: #baba36;">CC</span>=clang
+<span style="color: #656565;"># </span><span style="color: #757575;">or</span>
+&gt; export <span style="color: #baba36;">CC</span>=gcc
</pre>
</div>
</div>
</div>
-<div id="outline-container-org28e3d41" class="outline-3">
-<h3 id="org28e3d41">make</h3>
-<div class="outline-text-3" id="text-org28e3d41">
+<div id="outline-container-org7ba7a71" class="outline-3">
+<h3 id="org7ba7a71">make</h3>
+<div class="outline-text-3" id="text-org7ba7a71">
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">clone the repo</span>
+<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">clone the repo</span>
&gt; cd ~/code; git clone https://gitlab.com/grm-grm/ck
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">make a build directory and enter it</span>
-&gt; mkdir ~/ck_build; <span style="color: #ff0066;">cd</span> ~/ck_build;
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run cmake</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">make a build directory and enter it</span>
+&gt; mkdir ~/ck_build; <span style="color: #528fd1;">cd</span> ~/ck_build;
+<span style="color: #656565;"># </span><span style="color: #757575;">run cmake</span>
&gt; cmake ~/code/ck
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run make</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">run make</span>
&gt; make
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run ck</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">run ck</span>
&gt; ./ck
</pre>
</div>
@@ -325,21 +325,21 @@ for the JavaScript code in this tag.
</div>
</div>
-<div id="outline-container-orgcd61fbc" class="outline-2">
-<h2 id="orgcd61fbc">for devs</h2>
-<div class="outline-text-2" id="text-orgcd61fbc">
+<div id="outline-container-org5cb365e" class="outline-2">
+<h2 id="org5cb365e">for devs</h2>
+<div class="outline-text-2" id="text-org5cb365e">
</div>
-<div id="outline-container-org713cf8f" class="outline-3">
-<h3 id="org713cf8f">CMake options</h3>
-<div class="outline-text-3" id="text-org713cf8f">
+<div id="outline-container-org148ba3a" class="outline-3">
+<h3 id="org148ba3a">CMake options</h3>
+<div class="outline-text-3" id="text-org148ba3a">
<p>
cmake accepts the following options:
</p>
<div class="org-src-container">
-<pre class="src src-cmake"><span style="color: #63de5d;">option</span>(CK_ASAN <span style="color: #E6DB74;">"Build with asan"</span>)
-<span style="color: #63de5d;">option</span>(CK_DEBUG <span style="color: #E6DB74;">"Build with debug symbols"</span>)
-<span style="color: #63de5d;">option</span>(CK_TESTS <span style="color: #E6DB74;">"Make the tests"</span>)
-<span style="color: #63de5d;">option</span>(CK_SHARED <span style="color: #E6DB74;">"Build with shared lib"</span>)
+<pre class="src src-cmake"><span style="color: #6aaf50;">option</span>(CK_ASAN <span style="color: #bdbc61;">"Build with asan"</span>)
+<span style="color: #6aaf50;">option</span>(CK_DEBUG <span style="color: #bdbc61;">"Build with debug symbols"</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>
</div>
@@ -356,24 +356,24 @@ Just build with address sanitizer enabled like so:
llvm has better asan than gcc, so I use that.
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">clone the repo</span>
+<pre class="src src-sh"><span style="color: #656565;"># </span><span style="color: #757575;">clone the repo</span>
&gt; cd ~/code; git clone https://gitlab.com/grm-grm/ck
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">make a build directory and enter it</span>
-&gt; mkdir ~/ck_build; <span style="color: #ff0066;">cd</span> ~/ck_build;
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run cmake</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">make a build directory and enter it</span>
+&gt; mkdir ~/ck_build; <span style="color: #528fd1;">cd</span> ~/ck_build;
+<span style="color: #656565;"># </span><span style="color: #757575;">run cmake</span>
&gt; cmake -DCK_ASAN=1 -DCK_DEBUG=1 -DCK_TESTS=1 ~/code/ck
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run make</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">run make</span>
&gt; make
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">run ck</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">run ck</span>
&gt; ./ck
</pre>
</div>
</div>
</div>
-<div id="outline-container-orga6955dd" class="outline-3">
-<h3 id="orga6955dd">tests</h3>
-<div class="outline-text-3" id="text-orga6955dd">
+<div id="outline-container-org20e80d6" class="outline-3">
+<h3 id="org20e80d6">tests</h3>
+<div class="outline-text-3" id="text-org20e80d6">
<p>
The testing "suite" is a bash script that runs regression
and unit tests. Regression tests are under the <code>tests/</code> directory
@@ -382,9 +382,9 @@ under <code>unit/</code> directory and test the code.
</p>
</div>
-<div id="outline-container-org6219fcc" class="outline-4">
-<h4 id="org6219fcc">run tests</h4>
-<div class="outline-text-4" id="text-org6219fcc">
+<div id="outline-container-org75775b9" class="outline-4">
+<h4 id="org75775b9">run tests</h4>
+<div class="outline-text-4" id="text-org75775b9">
<p>
First make sure you build ck with the <code>-DCK_TESTS=1</code> option. Then
go to the build directory and type:
@@ -396,9 +396,9 @@ go to the build directory and type:
</div>
</div>
-<div id="outline-container-orgd4349ab" class="outline-4">
-<h4 id="orgd4349ab">test suite</h4>
-<div class="outline-text-4" id="text-orgd4349ab">
+<div id="outline-container-orgf7207a9" class="outline-4">
+<h4 id="orgf7207a9">test suite</h4>
+<div class="outline-text-4" id="text-orgf7207a9">
<div class="org-src-container">
<pre class="src src-sh">$ ./test-ck -h
ck test suite
@@ -416,9 +416,9 @@ flags:
</div>
</div>
</div>
-<div id="outline-container-org1d127b7" class="outline-2">
-<h2 id="org1d127b7">manual</h2>
-<div class="outline-text-2" id="text-org1d127b7">
+<div id="outline-container-org3401884" class="outline-2">
+<h2 id="org3401884">manual</h2>
+<div class="outline-text-2" id="text-org3401884">
<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
@@ -429,30 +429,31 @@ and intuitive.
Example usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">initialize new ck</span>
-$ ck init /path_to/where_you_want/your_configs/to_be <span style="color: #E6DB74; font-weight: bold;">\</span>
+<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: #6A6D70;"># </span><span style="color: #6A6D70;">add emacs configs</span>
-<span style="color: #6A6D70;">## </span><span style="color: #6A6D70;">primary config</span>
+<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: #6A6D70;">## </span><span style="color: #6A6D70;">secret config, with passwords and naughty words</span>
+<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: #6A6D70;">## </span><span style="color: #6A6D70;">and another one for emacs</span>
+<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: #6A6D70;"># </span><span style="color: #6A6D70;">add tmux config</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">add tmux config</span>
$ ck add tmux ~/.tmux.conf -p
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">list the configs</span>
+<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: #6A6D70;"># </span><span style="color: #6A6D70;">search the configs</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">search the configs</span>
$ ck search search-term
-$ ck search <span style="color: #E6DB74;">"\"search term with spaces\""</span>
-$ ck search <span style="color: #E6DB74;">"\("</span> <span style="color: #6A6D70;">#</span><span style="color: #6A6D70;">escape symbols</span>
+$ 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>
@@ -468,9 +469,9 @@ of flags one has to pass to ck.
</p>
</div>
-<div id="outline-container-orge5785e3" class="outline-3">
-<h3 id="orge5785e3">ck configuration</h3>
-<div class="outline-text-3" id="text-orge5785e3">
+<div id="outline-container-org41c11d4" class="outline-3">
+<h3 id="org41c11d4">ck configuration</h3>
+<div class="outline-text-3" id="text-org41c11d4">
<p>
ck uses sqlite to index the configuration files. The init
action creates a <b>.ck</b> directory (under $HOME)
@@ -498,13 +499,13 @@ directory of your choice.
Usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh">$ ck config ~/ ... <span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">the default behaviour</span>
+<pre class="src src-sh">$ ck config ~/ ... <span style="color: #656565;"># </span><span style="color: #757575;">the default behaviour</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">/someplace/else must exist or</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">the action following it must be init</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 conf /someplace/else ...
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">same thing</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">same thing</span>
$ ck c /someplace/else ...
$ ck -c /someplace/else ...
</pre>
@@ -512,13 +513,13 @@ $ ck -c /someplace/else ...
</div>
</div>
-<div id="outline-container-orga717caf" class="outline-3">
-<h3 id="orga717caf">Actions</h3>
-<div class="outline-text-3" id="text-orga717caf">
+<div id="outline-container-org72890ad" class="outline-3">
+<h3 id="org72890ad">Actions</h3>
+<div class="outline-text-3" id="text-org72890ad">
</div>
-<div id="outline-container-org29304ac" class="outline-4">
-<h4 id="org29304ac">init</h4>
-<div class="outline-text-4" id="text-org29304ac">
+<div id="outline-container-org3b0ec54" class="outline-4">
+<h4 id="org3b0ec54">init</h4>
+<div class="outline-text-4" id="text-org3b0ec54">
<p>
or i or -i
</p>
@@ -540,17 +541,17 @@ Use init to initialize a new ck database.
Usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">initialize new ck</span>
-$ ck init /path_to/where_you_want/your_configs/to_be <span style="color: #E6DB74; font-weight: bold;">\</span>
+<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-org8841e7c" class="outline-4">
-<h4 id="org8841e7c">add</h4>
-<div class="outline-text-4" id="text-org8841e7c">
+<div id="outline-container-orgc9498d4" class="outline-4">
+<h4 id="orgc9498d4">add</h4>
+<div class="outline-text-4" id="text-orgc9498d4">
<p>
or a or -a
</p>
@@ -584,25 +585,34 @@ sure to use the same name.</li>
Usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">add config to ck</span>
+<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]
</pre>
</div>
</div>
</div>
-<div id="outline-container-orgc9a5e19" class="outline-4">
-<h4 id="orgc9a5e19">list</h4>
-<div class="outline-text-4" id="text-orgc9a5e19">
+<div id="outline-container-orge78ef4d" class="outline-4">
+<h4 id="orge78ef4d">list</h4>
+<div class="outline-text-4" id="text-orge78ef4d">
<p>
or ls or l or -l
</p>
<p>
-List can show the <b>paths</b> or the <b>programs</b> that ck keeps track of.
+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 "&lt;&gt;") 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>
@@ -614,7 +624,7 @@ the way the list is printed:
<p>
Using the keyword <b>tree</b> ck can list the configurations under their
-corresponding program.
+corresponding program, in a treelike structure.
</p>
<p>
@@ -623,23 +633,33 @@ 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 class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">list tree structure, with attributes</span>
+<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: #6A6D70;"># </span><span style="color: #6A6D70;">list paths in python</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">list paths in python</span>
$ ck l paths -t python
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">list programs in lisp</span>
+<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>
</div>
</div>
</div>
-<div id="outline-container-org73e5182" class="outline-4">
-<h4 id="org73e5182">search</h4>
-<div class="outline-text-4" id="text-org73e5182">
+<div id="outline-container-org914dcb8" class="outline-4">
+<h4 id="org914dcb8">search</h4>
+<div class="outline-text-4" id="text-org914dcb8">
<p>
or s or -s
</p>
@@ -660,13 +680,13 @@ To search for terms with spaces you have to put them in quotes.
Usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">search for parenthesis</span>
-$ ck search <span style="color: #E6DB74;">\(</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">search term with spaces</span>
-$ ck search <span style="color: #E6DB74;">"This is a space"</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">both</span>
-$ ck search <span style="color: #E6DB74;">"(add 2 4)"</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">and a normal one</span>
+<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 search <span style="color: #bdbc61;">"This is a space"</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">both</span>
+$ ck search <span style="color: #bdbc61;">"(add 2 4)"</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">and a normal one</span>
$ ck search alias
</pre>
</div>
@@ -677,20 +697,20 @@ 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: #6A6D70;"># </span><span style="color: #6A6D70;">with xargs</span>
-$ ck ls paths | xargs grep -E <span style="color: #E6DB74;">'A|B'</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">or in bash</span>
-$ for i<span style="color: #ff0066;"> in</span> $(ck ls paths); <span style="color: #ff0066;">do</span> grep -E <span style="color: #E6DB74;">'A|B'</span> $<span style="color: #ffac4a;">i</span>; <span style="color: #ff0066;">done</span>
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">or in zsh</span>
-$ for i ($(ck ls paths)) grep -E <span style="color: #E6DB74;">'A|B'</span> $<span style="color: #ffac4a;">i</span>
+<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-org9b41294" class="outline-4">
-<h4 id="org9b41294">edit</h4>
-<div class="outline-text-4" id="text-org9b41294">
+<div id="outline-container-orga1030cc" class="outline-4">
+<h4 id="orga1030cc">edit</h4>
+<div class="outline-text-4" id="text-orga1030cc">
<p>
or e or -e
</p>
@@ -719,17 +739,17 @@ print the avaliable configurations and exit.
Usage:
</p>
<div class="org-src-container">
-<pre class="src src-sh"><span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">suppose this is our ck instance</span>
+<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 style="color: #6A6D70;"># </span><span style="color: #6A6D70;">edit the primary emacs config</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">edit the primary emacs config</span>
$ ck edit emacs
-<span style="color: #6A6D70;"># </span><span style="color: #6A6D70;">edit a specific emacs config, other than the primary</span>
+<span style="color: #656565;"># </span><span style="color: #757575;">edit a specific emacs config, other than the primary</span>
$ ck edit emacs accounts.el
</pre>
</div>
@@ -739,7 +759,7 @@ $ ck edit emacs accounts.el
</div>
</div>
<div id="postamble" class="status">
-<p class="date">Created: 2018-10-08 Mon 23:46</p>
+<p class="date">Created: 2018-10-09 Tue 20:53</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
diff --git a/README.org b/README.org
index 446ff02..c03a093 100644
--- a/README.org
+++ b/README.org
@@ -112,6 +112,7 @@ Example usage:
$ ck list tree
$ ck list paths -t lisp
$ ck list programs -t python
+ $ ck list -p emacs
# search the configs
$ ck search search-term
@@ -200,7 +201,12 @@ Usage:
*** list
or ls or l or -l
-List can show the *paths* or the *programs* that ck keeps track of.
+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:
@@ -209,11 +215,13 @@ the way the list is printed:
- *lisp*: print like a lisp list
Using the keyword *tree* ck can list the configurations under their
-corresponding program.
+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
@@ -222,6 +230,12 @@ Usage:
$ 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
diff --git a/src/actionhelper.c b/src/actionhelper.c
index 3e898af..582333e 100644
--- a/src/actionhelper.c
+++ b/src/actionhelper.c
@@ -149,15 +149,12 @@ void add_make_link(const AddOpt *opt, const Conf *conf) {
}
}
-int edit_make_options(cklist *args) {
- UNUSED(args);
-}
-
ListOpt list_make_options(cklist *args) {
list_rewind(args);
ListOpt listOpt = {
._lt = LT_NONE,
._lst = LST_PLAIN,
+ .pName = NULL,
.attr = 0,
.err = 0
};
@@ -195,8 +192,21 @@ ListOpt list_make_options(cklist *args) {
else if (strcmp(list_get(args), "tree") == 0) {
listOpt._lt = LT_TREE;
}
+ else if (strcmp(list_get(args), "ckconf") == 0) {
+ listOpt._lt = LT_CKCONF;
+ }
+ else if (strcmp(list_get(args), "-p") == 0) {
+ if (list_next(args)) {
+ listOpt._lt = LT_PROG_CONFS;
+ listOpt.pName = list_get(args);
+ }
+ else {
+ listOpt.err = 1;
+ break;
+ }
+ }
else {
- listOpt.err = 1;
+ listOpt.err = 1;
}
} while(list_next(args));
}
@@ -240,7 +250,6 @@ void print_LIST_result(int err) {
if (!err) {
return;
}
- ERR("Wrong list arguments");
}
void print_SEARCH_result(int err) {
diff --git a/src/actionparser.c b/src/actionparser.c
index 7c1186a..1da1d2f 100644
--- a/src/actionparser.c
+++ b/src/actionparser.c
@@ -130,7 +130,7 @@ int parse_EDIT(UserOpt *opt) {
int parse_LIST(UserOpt *opt) {
/* List expects a maximum of than 3 arguments */
- if (optNum <= pos || optNum > pos + 4) {
+ if (optNum <= pos || optNum > pos + 5) {
opt->err = PERR_LIST_WRONG;
return -1;
}
@@ -329,13 +329,13 @@ void print_parser_error(UserOpt *opt) {
sprintf(errStr, "Add config \nUsage: %s ProgramName ConfigPath [-s](secret) [-p](primary)", names);
break;
case PERR_DEL_WRONG:
- sprintf(errStr, "Delete config or program\nUsage: %s ....", names);
+ sprintf(errStr, "Delete config or program\nUsage: %s {ProgramName} | {-c ConfigPath (as shown by ck list)}", names);
break;
case PERR_EDIT_WRONG:
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 value-to-list (or tree) [-t list-type] [-a]", names);
+ sprintf(errStr, "List programs, configs and more\nUsage: %s {programs|paths|-p ProgramName} [-t list-type] | {tree | ckconf} [-a]", names);
break;
case PERR_SEARCH_WRONG:
sprintf(errStr, "Search through the configs with grep\nUsage: %s search-term", names);
@@ -344,7 +344,7 @@ void print_parser_error(UserOpt *opt) {
sprintf(errStr, "Usage: ........");
break;
}
- ERR("%s", errStr);
+ HELP("%s", errStr);
}
void print_parser_help() {
diff --git a/src/actions.c b/src/actions.c
index 4ff6816..1b4c9b5 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -134,8 +134,11 @@ int run_EDIT(UserOpt *opt, Conf *conf) {
/* If the program has many configs */
else {
HELP("Ambiguous config. Please type the config name after the program.");
- cklist *paths = list_make_new();
- edit_get_avaliable_paths(&db, paths, pName);
+ char name[STR_M] = "";
+ strcat(name, pName);
+ strcat(name, ":");
+ cklist *paths = list_make_and_add(name);
+ get_program_paths(&db, paths, pName, 1, 0);
list_print(paths);
list_free(paths);
goto error;
@@ -147,8 +150,11 @@ int run_EDIT(UserOpt *opt, Conf *conf) {
char *cName = list_get(opt->args);
if (edit_get_config(&db, pName, confName, cName, &secret)) {
ERR("Program %s doesn't have a config named %s", pName, cName);
- cklist *paths = list_make_new();
- edit_get_avaliable_paths(&db, paths, pName);
+ char name[STR_M] = "";
+ strcat(name, pName);
+ strcat(name, ":");
+ cklist *paths = list_make_and_add(name);
+ get_program_paths(&db, paths, pName, 1, 0);
list_print(paths);
list_free(paths);
goto error;
@@ -171,7 +177,6 @@ int run_EDIT(UserOpt *opt, Conf *conf) {
}
int run_LIST(UserOpt *opt, Conf *conf) {
- UNUSED(conf);
DB db = open_DB(opt);
if (db.ptr == NULL) {
if (db.error == SQL_ERR_NO_TABLES) {
@@ -186,6 +191,7 @@ int run_LIST(UserOpt *opt, Conf *conf) {
if (listOpt.err) {
goto error;
}
+ char tmp[STR_L] = "";
switch(listOpt._lt) {
case LT_PATH:
list_get_paths(&db, the_list, listOpt.attr);
@@ -197,6 +203,27 @@ int run_LIST(UserOpt *opt, Conf *conf) {
list_get_path_program_tree(&db, the_list, listOpt.attr);
list_print(the_list);
goto close;
+ case LT_CKCONF:
+ strcat(tmp, "ck configuration directory path: ");
+ strcat(tmp, opt->confDir);
+ list_add(the_list, tmp);
+#define X(var, str, name) \
+ strcpy(tmp, ""); \
+ strcat(tmp, name); \
+ strcat(tmp, ": "); \
+ strcat(tmp, conf->var); \
+ list_add(the_list, tmp);
+ CONFIG_VARIABLES_TABLE;
+#undef X
+ list_print(the_list);
+ goto close;
+ case LT_PROG_CONFS:
+ if (!program_exists(&db, listOpt.pName)) {
+ ERR("Program %s doesn't exist in the database.", listOpt.pName);
+ goto error;
+ }
+ get_program_paths(&db, the_list, listOpt.pName, 0, listOpt.attr);
+ break;
case LT_NONE:
goto error;
}
diff --git a/src/actions.h b/src/actions.h
index c9da4fb..624ae30 100644
--- a/src/actions.h
+++ b/src/actions.h
@@ -56,10 +56,12 @@ struct DelOptions {
typedef enum ListTypes ListType;
enum ListTypes {
+ LT_NONE,
LT_PATH,
LT_PROGRAM,
LT_TREE,
- LT_NONE,
+ LT_CKCONF,
+ LT_PROG_CONFS
};
typedef enum ListShowTypes ListShowType;
@@ -73,6 +75,7 @@ typedef struct ListOptions ListOpt;
struct ListOptions {
ListType _lt;
ListShowType _lst;
+ char *pName;
int attr;
int err;
};
diff --git a/src/dblayer.c b/src/dblayer.c
index 4290a7a..973d561 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -478,9 +478,10 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int
sqlite3_finalize(stmt);
return flag;
}
+ return -1;
}
-int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) {
+int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int attr) {
int pid = get_program_id(db, pName);
/* error */
if (pid == -2) {
@@ -493,6 +494,10 @@ int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) {
int rc;
char selection[STR_M] = COL_CONFIG_PATH;
+ strcat(selection, ",");
+ strcat(selection, COL_CONFIG_SECRET);
+ strcat(selection, ",");
+ strcat(selection, COL_CONFIG_PRIMARY);
char condition[STR_M] = TBL_PROGRAM;
strcat(condition, ".");
strcat(condition, COL_PROGRAM_ID);
@@ -506,21 +511,32 @@ int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName) {
return -2;
}
- char name[STR_M] = "";
- strcat(name, pName);
- strcat(name, ":");
- list_add(ckl, name);
while (sqlite3_step(stmt) == SQLITE_ROW) {
char *tmp = strdup((char *)sqlite3_column_text(stmt, 0));
char entry[STR_M] = "";
- strcat(entry, "|- ");
- strcat(entry, basename(tmp));
+ if (bname) {
+ strcat(entry, basename(tmp));
+ }
+ else {
+ strcat(entry, tmp);
+ }
+ if (attr) {
+ /* secret */
+ if (sqlite3_column_int(stmt, 1)) {
+ strcat(entry, " [s]");
+ }
+ /* primary */
+ if (sqlite3_column_int(stmt, 2)) {
+ strcat(entry, " [p]");
+ }
+ }
list_add(ckl, entry);
free(tmp);
}
sqlite3_finalize(stmt);
return 0;
}
+ return -1;
}
int list_get_paths(DB *db, cklist *ckl, int attr) {
@@ -732,15 +748,11 @@ int get_program_relations(DB *db, int pid) {
int get_config_number(DB *db, char* pName) {
int pid = get_program_id(db, pName);
- /* error */
- if (pid == -2) {
- return -1;
- }
-
/* program exists */
if (pid > -1) {
return get_program_relations(db, pid);
}
+ return -1;
}
/* Removes the relationship of `cid` with the corresponding program.
diff --git a/src/dblayer.h b/src/dblayer.h
index 05ba5bd..c99f143 100644
--- a/src/dblayer.h
+++ b/src/dblayer.h
@@ -43,6 +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);
/********/
/* init */
@@ -66,7 +67,6 @@ extern int add_transaction_try(DB *db, const AddOpt * const opt);
extern int edit_get_prime_config_from_program(DB *db, char *pName, char *ret, int *secret);
extern int get_config_number(DB *db, char *pName);
extern int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int *sec);
-extern int edit_get_avaliable_paths(DB *db, cklist *ckl, const char* pName);
/********/
/* list */