From 6d162956409c0fa394920ba707109afdbff041e5 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Fri, 28 Sep 2018 23:23:08 +0300 Subject: fix minor grep nuiscance --- README.html | 260 +++++++++++++++++++++++++++++++--------------------------- README.org | 21 +++-- src/actions.c | 6 +- 3 files changed, 156 insertions(+), 131 deletions(-) diff --git a/README.html b/README.html index 7a0e391..a1f67cd 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + @@ -232,35 +232,35 @@ for the JavaScript code in this tag.

Table of Contents

-
-

ck

-
+
+

ck

+

The Config Keeper

-
-

build it

-
+
+

build it

+
-
-

requirements

-
+
+

requirements

+
  • clang (llvm) or gcc (gnu)
  • cmake
  • @@ -293,31 +293,31 @@ for the JavaScript code in this tag.
-
-

compiler

-
+
+

compiler

+
-
> export CC=clang
-# or
-> export CC=gcc
+
> export CC=clang
+# or
+> export CC=gcc
 
-
-

make

-
+
+

make

+
-
# clone the repo
+
# 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
+# make a build directory and enter it
+> mkdir ~/ck_build; cd ~/ck_build;
+# run cmake
 > cmake ~/code/ck
-# run make
+# run make
 > make
-# run ck
+# run ck
 > ./ck
 
@@ -325,21 +325,21 @@ for the JavaScript code in this tag.
-
-

for devs

-
+
+

for devs

+
-
-

CMake options

-
+
+

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")
+
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")
 
@@ -356,24 +356,24 @@ Just build with address sanitizer enabled like so: llvm has better asan than gcc, so I use that.

-
# clone the repo
+
# 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
+# 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
+# run make
 > make
-# run ck
+# run ck
 > ./ck
 
-
-

tests

-
+
+

tests

+

The testing "suite" is a bash script that runs regression and unit tests. Regression tests are under the tests/ directory @@ -382,9 +382,9 @@ under unit/ directory and test the code.

-
-

run tests

-
+
+

run tests

+

Simply go to the build dir and type.

@@ -395,9 +395,9 @@ Simply go to the build dir and type.
-
-

test suite

-
+
+

test suite

+
$ ./check_ck -h
 ck test suite
@@ -415,9 +415,9 @@ flags:
 
-
-

manual

-
+
+

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 @@ -428,30 +428,30 @@ and intuitive. Example usage:

-
# initialize new ck
-$ ck init /path_to/where_you_want/your_configs/to_be \
+
# initialize new ck
+$ ck init /path_to/where_you_want/your_configs/to_be \
   /path_to/the_secret/directory
 
-# add emacs configs
-## primary config
+# add emacs configs
+## primary config
 $ ck add emacs ~/.emacs.d/orgconf.org -p
-## secret config, with passwords and naughty words
+## secret config, with passwords and naughty words
 $ ck add emacs ~/.emacs.d/accounts.org -s
-## and another one for emacs
+## and another one for emacs
 $ ck add emacs ~/.emacs.d/init.el
 
-# add tmux config
+# add tmux config
 $ ck add tmux ~/.tmux.conf -p
 
-# list the configs
+# list the configs
 $ ck list tree
 $ ck list paths -t lisp
 $ ck list programs -t python
 
-# search the configs
+# search the configs
 $ ck search search-term
-$ ck search "\"search term with spaces\""
-$ ck search "\(" #escape symbols
+$ ck search "\"search term with spaces\""
+$ ck search "\(" #escape symbols
 
@@ -467,9 +467,9 @@ of flags one has to pass to ck.

-
-

ck configuration

-
+
+

ck configuration

+

ck uses sqlite to index the configuration files. The init action creates a .ck directory (under $HOME) @@ -497,13 +497,13 @@ directory of your choice. Usage:

-
$ ck config ~/ ... # the default behaviour
+
$ ck config ~/ ... # the default behaviour
 
-# /someplace/else must exist or
-# the action following it must be init
+# /someplace/else must exist or
+# the action following it must be init
 $ ck conf /someplace/else ... 
 
-# same thing
+# same thing
 $ ck c /someplace/else ... 
 $ ck -c /someplace/else ... 
 
@@ -511,13 +511,13 @@ $ ck -c /someplace/else ...
-
-

Actions

-
+
+

Actions

+
-
-

init

-
+
+

init

+

or i or -i

@@ -539,17 +539,17 @@ Use init to initialize a new ck database. Usage:

-
# initialize new ck
-$ ck init /path_to/where_you_want/your_configs/to_be \
+
# initialize new ck
+$ ck init /path_to/where_you_want/your_configs/to_be \
   /path_to/the_secret/directory
 
-
-

add

-
+
+

add

+

or a or -a

@@ -583,16 +583,16 @@ sure to use the same name. Usage:

-
# add config to ck
+
# add config to ck
 $ ck add program_name config_path [-s] [-p]
 
-
-

list

-
+
+

list

+

or ls or l or -l

@@ -625,20 +625,20 @@ It is best used with tree or plain paths. Usage:

-
# list tree structure, with attributes
+
# list tree structure, with attributes
 $ ck list tree -a
-# list paths in python
+# list paths in python
 $ ck l paths -t python
-# list programs in lisp
+# list programs in lisp
 $ ck ls programs -t lisp
 
-
-

search

-
+
+

search

+

or s or -s

@@ -652,30 +652,44 @@ Takes one argument, the search-term.

-To search for terms with spaces you have to put them in escaped quotes. -To search for special symbols you have to enclose them in quotes and escape them. +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
+
# 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

-
+
+

edit

+

or e or -e

@@ -701,7 +715,7 @@ To do it use:
-

Created: 2018-09-27 Thu 12:36

+

Created: 2018-09-28 Fri 23:23

Validate

diff --git a/README.org b/README.org index aa2ebae..004ea2e 100644 --- a/README.org +++ b/README.org @@ -230,21 +230,32 @@ Perform infile grep in all the configurations ck keeps track of. Takes one argument, the *search-term*. -To search for terms with spaces you have to put them in escaped quotes. -To search for special symbols you have to enclose them in quotes and escape them. +To search for terms with spaces you have to put them in quotes. Usage: #+BEGIN_SRC sh # search for parenthesis - $ ck search "\(" + $ ck search \( # search term with spaces - $ ck search "\"This is a space\"" + $ ck search "This is a space" # both - $ ck search "\"(add 2 4)\"" + $ ck search "(add 2 4)" # and a normal one $ ck search 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: + +#+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 diff --git a/src/actions.c b/src/actions.c index 70705e4..e6eb3d3 100644 --- a/src/actions.c +++ b/src/actions.c @@ -213,10 +213,10 @@ int run_SEARCH(UserOpt *opt, Conf *conf) { if (list_size(paths)) { do { FILE *cmd; - char result[4096] = ""; - char command[STR_L] = "grep -H -n "; + char result[STR_L] = ""; + char command[STR_L] = "grep -H -n \""; strcat(command, list_get(opt->args)); - strcat(command, " "); + strcat(command, "\" "); strcat(command, list_get(paths)); cmd = popen(command, "r"); if (cmd == NULL) { -- cgit v1.2.3