A cli tool to search with contexts.
Project description
Context Cli
Context Cli is a cli tool to search with contexts.
Installation
$ pip install context-cli
Usage
Help
$ ctx -h
usage: ctx [-h] [-t TYPE] [-w] [-d DELIMITER_MATCHER]
[-D DELIMITER_MATCHER] [-s START_DELIMITER_MATCHER]
[-S START_DELIMITER_MATCHER] [-e END_DELIMITER_MATCHER]
[-E END_DELIMITER_MATCHER] [-x] [-X] [-i]
[-c CONTAINS_TEXT] [-C CONTAINS_REGEX] [-m MATCHES_TEXT]
[-M MATCHES_REGEX] [-c! NOT_CONTAINS_TEXT]
[-C! NOT_CONTAINS_REGEX] [-m! NOT_MATCHES_TEXT]
[-M! NOT_MATCHES_REGEX] [-l LINE_CONTAINS_TEXT]
[-L LINE_CONTAINS_REGEX] [-l! NOT_LINE_CONTAINS_TEXT]
[-L! NOT_LINE_CONTAINS_REGEX] [-o OUTPUT_DELIMITER]
[files [files ...]]
A cli tool to search with contexts.
positional arguments:
files
optional arguments:
-h, --help show this help message and exit
-t TYPE, --type TYPE type of search as specified in .ctxrc
-w, --write write the current context search to .ctxrc
-d DELIMITER_MATCHER, --delimiter-text DELIMITER_MATCHER
delimiter text
-D DELIMITER_MATCHER, --delimiter-regex DELIMITER_MATCHER
delimiter regex
-s START_DELIMITER_MATCHER, --delimiter-start-text START_DELIMITER_MATCHER
delimiter start text
-S START_DELIMITER_MATCHER, --delimiter-start-regex START_DELIMITER_MATCHER
delimiter start regex
-e END_DELIMITER_MATCHER, --delimiter-end-text END_DELIMITER_MATCHER
delimiter end text
-E END_DELIMITER_MATCHER, --delimiter-end-regex END_DELIMITER_MATCHER
delimiter end regex
-x, --exclude-start-delimiter
exclude start delimiter from the context
-X, --exclude-end-delimiter
exclude end delimiter from the context
-i, --ignore-end-delimiter
prevent end delimiter from being considered as a start
delimiter (only applies if -X is used)
-c CONTAINS_TEXT, --contains-text CONTAINS_TEXT
display only contexts that have line(s) that contain
this text
-C CONTAINS_REGEX, --contains-regex CONTAINS_REGEX
display only contexts that have line(s) that contain
this regex
-m MATCHES_TEXT, --matches-text MATCHES_TEXT
display only contexts that have line(s) that exactly
match this text
-M MATCHES_REGEX, --matches-regex MATCHES_REGEX
display only contexts that have line(s) that exactly
match this regex
-c! NOT_CONTAINS_TEXT, --not-contains-text NOT_CONTAINS_TEXT
display only contexts that have line(s) that don't
contain this text
-C! NOT_CONTAINS_REGEX, --not-contains-regex NOT_CONTAINS_REGEX
display only contexts that have line(s) that don't
contain this regex
-m! NOT_MATCHES_TEXT, --not-matches-text NOT_MATCHES_TEXT
display only contexts that have line(s) that don't
exactly match this text
-M! NOT_MATCHES_REGEX, --not-matches-regex NOT_MATCHES_REGEX
display only contexts that have line(s) that don't
exactly match this regex
-l LINE_CONTAINS_TEXT, --line-contains-text LINE_CONTAINS_TEXT
display only lines in the context that contain this
text
-L LINE_CONTAINS_REGEX, --line-contains-regex LINE_CONTAINS_REGEX
display only lines in the context that contain this
regex
-l! NOT_LINE_CONTAINS_TEXT, --not-line-contains-text NOT_LINE_CONTAINS_TEXT
display only lines in the context that don't contain
this text
-L! NOT_LINE_CONTAINS_REGEX, --not-line-contains-regex NOT_LINE_CONTAINS_REGEX
display only lines in the context that don't contain
this regex
-o OUTPUT_DELIMITER, --output-delimiter OUTPUT_DELIMITER
Output delimiter
Examples
Extracting code blocks from Markdown
$ ctx -xXi -S '^```$' -E '^```$' -o "========" README.md
This command excludes the start and ending tick blocks from the output. We need the -i to avoid the ticks that cose the code-block from being interpreted as the opening ticks.
The -o adds the "========" between each context.
Filter the output
Only display contexts that have "install"
$ ctx -xXi -S '^```$' -E '^```$' -c install -o "========" README.md
Save common arguments
If you use ctx with the same arguments over and over again, you can save those arguments under a name. In
the following example, we add my_saved_search by using the --type (or -t) and --write (or -w).
$ ctx --type my_saved_search -write -xXi -s '-----' -e 'end' -o '=========='
And then use it (note there is no --write anymore)
$ ctx -t my_saved_search my_file.txt
The configuration is saved to your home folder in a .ctxrc file.
TODO: Add more examples
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file context-cli-0.0.dev4.tar.gz.
File metadata
- Download URL: context-cli-0.0.dev4.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0178909b499ff00d10e508e3e12925f6732eba10e80ac1d731cc4d1441331c8d
|
|
| MD5 |
e067cd9e1cc94cdfcb8ec4bbeb732dc8
|
|
| BLAKE2b-256 |
e06313f552c40651052b4c5eee099b4a18f3ff644b9ed8dc09c8767c22d864a6
|
File details
Details for the file context_cli-0.0.dev4-py3-none-any.whl.
File metadata
- Download URL: context_cli-0.0.dev4-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34b35fec1776131f13eb162d61a7eb90c6c0389e070859e132c8d40cab2ad30d
|
|
| MD5 |
f58fb0d10b9b67c444c986ac36bbacab
|
|
| BLAKE2b-256 |
b33ca79a8ae76ebf648e4810b8c465ab07f46a19aa39d931f82635851819b4bf
|