Skip to content

Commit 2a895e5

Browse files
committed
Tweaks to docs. More plugins.
1 parent 08d829a commit 2a895e5

File tree

7 files changed

+350
-269
lines changed

7 files changed

+350
-269
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ www/:
2323
mkdir -p ./www
2424

2525
gif:
26-
gifcut -b1 "$$(capture -Wt20)" "window-$$(date +%s).gif"
26+
gifcut -b1 "$$(capture -Wt20)" "www/img/window-$$(date +%s).gif"
2727

2828
.PHONY: gif lint test unit www

README.md

Lines changed: 95 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,41 @@
22

33
## About
44

5-
Cz is a bash script that provides a common interface to interactive line selection tools.
5+
Cz is a bash script that provides a common interface to interactive line
6+
selection tools.
67

7-
What is an "interactive line selection tool"? It's a class of programs that take as input a list of lines to be selected from then presents an interactive menu for the user to select one line.
8+
What is an "interactive line selection tool"? It's a kind of program
9+
that reads text input then presents an interactive menu for the user to
10+
select one line.
811

9-
Some run only in the terminal and others are graphical - cz runs an avalable tool appropriate for the situation.
12+
Some line selection tools run only in the terminal and others are
13+
graphical - cz uses a tool appropriate for the situation.
1014

11-
Cz also acts as a framework for pluggable line selection based applications.
15+
Cz also acts as a framework for pluggable line selection based
16+
applications. Included are over 250 plugins covering a variety of use
17+
cases. For example:
1218

13-
Included are over 240 plugins for common use cases. Out of the box you can select from:
14-
15-
- files and directories
16-
- system processes
17-
- items from [bash's built-in completion](https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion-Builtins-1)
18-
- [git](https://git-scm.com/) branches, commits, tags, etc.
19-
- [unicode](https://home.unicode.org/) characters
20-
- man pages and other documentation sources
19+
- items from [bash's built-in
20+
completion](https://www.gnu.org/software/bash/manual/bash.html#Programmable-Completion-Builtins-1)
21+
- [Git](https://git-scm.com/) branches, commits, tags, etc.
22+
- [Unicode](https://home.unicode.org/) characters
2123
- [pass(1)](https://www.passwordstore.org/) passwords
22-
- elements from [JSON](https://www.json.org/)/[YAML](http://yaml.org/)/[XML](https://www.w3.org/XML/) documents
23-
- [docker](https://www.docker.com/) images
24+
- elements from
25+
[JSON](https://www.json.org/)/[YAML](http://yaml.org/)/[XML](https://www.w3.org/XML/)
26+
documents
27+
- [Docker](https://www.docker.com/)
2428
- [i3 window manager](https://i3wm.org/) components
25-
- [terraform](https://www.terraform.io/) elements
26-
- [mpd](https://www.musicpd.org/) tracks
27-
- [systemd](https://systemd.io/) info
28-
- [tmux](https://github.com/tmux/tmux) components
29+
- [Terraform](https://www.terraform.io/) elements
30+
- [Mpd](https://www.musicpd.org/) tracks and tags
31+
- [Systemd](https://systemd.io/) units
32+
- [Tmux](https://github.com/tmux/tmux) components
2933

3034
And a whole lot more\!
3135

32-
## Pitch
33-
34-
Do you find yourself running commands just to copy some specific string into another command? Do you turn to a search engine for data that is available locally? With cz a short script can eliminate that repeated toil.
35-
36-
The core concept of cz is getting some known text into place as easily as possible. In a shell cz lets you select and insert commonly needed text right where it's needed. In a graphical environment cz can quickly select the text you need and get it onto your clipboard.
37-
3836
## Tools
3937

40-
Cz supports the following line selection tools:
38+
The following line selection tools are
39+
supported:
4140

4241
- [choose](https://github.com/chipsenkbeil/choose)
4342
- [dmenu](https://tools.suckless.org/dmenu)
@@ -72,15 +71,15 @@ bash\`.
7271

7372
cz [OPTIONS] [PLUGIN...] [ARGS ...] [< LINES]
7473
Select a line using your preferred interactive line selection tool.
75-
74+
7675
OPTIONS
7776
These options print some information and exit:
7877
-h : help : Show this help text or help text for plugin.
7978
-H : example : List example commands.
8079
-k : tools : List supported line selection tools.
8180
-l : plugins : List detected plugins.
8281
-v : version : Show version string.
83-
82+
8483
These options set the program mode. Select a line then... :
8584
-p : print : Print the line. This is the default mode.
8685
-q : quoted : Print fields from the line in shell quotes.
@@ -89,48 +88,48 @@ bash\`.
8988
-t : template : Print a templated string.
9089
-u : unquoted : Print fields from the line literally.
9190
-o : : Only print input lines instead of selecting a line.
92-
91+
9392
These options set a template:
9493
-e TEMPLATE : Set the command template. This option implies mode '-r'.
9594
-f FIELDS : Set the field template. This option implies mode '-q'.
96-
95+
9796
These options control input and line splitting:
9897
-c : Do not use cached input lines.
9998
-d DELIMITER : Set the field splitting characters.
10099
-g : Buffer stdin and pass it to command set with '-e'.
101100
-0 : Read null terminated lines from input.
102101
-i IN-FILE : Set file from which to read selections instead of stdin.
103-
102+
104103
These options control which line selection utility is used:
105104
-x : Use a graphical line selection tool.
106105
-y : Use a terminal line selection tool.
107106
-z TOOL : Use the given line selection tool.
108-
107+
109108
TOOLS
110109
The following interactive line selection tools are supported:
111110
choose, dmenu, fzf, fzy, iselect, pick, pipedial, rofi, selecta, sentaku,
112111
slmenu, and vis-menu.
113-
112+
114113
PLUGINS
115114
Plugins use cz for an application specific task. Each plugin defines input
116115
lines and options like the delimiter and templates.
117116
Run 'cz -l' to list plugins and 'cz -h PLUGIN' or 'cz help' for help text.
118117
All commands starting with 'cz_' are considered plugins.
119-
118+
120119
TEMPLATES
121-
Substrings of TEMPLATE in the following formats are replaced with
120+
Sub-strings of TEMPLATE in the following formats are replaced with
122121
one or more fields from a selected line split by DELIMITER.
123122
{X} - field X
124123
{X:} - fields X through end of fields
125124
{X:Y} - fields X through X + Y
126125
{X,Y,Z} - fields X, Y, and Z
127-
126+
128127
Append @C, @E, @P, or @Q to transform selected fields:
129128
{X@C} - Insert argument directly. This is risky for command strings!
130129
{X@E} - Replace backslash escape sequences in arguments with bash $'...' quotes.
131130
{X@P} - Expand arguments for use in prompt strings.
132131
{X@Q} - Quote arguments for use in command input. This is the default.
133-
132+
134133
ENVIRONMENT
135134
CZ_GUI : The preferred interface (1=graphical 0=terminal).
136135
CZ_BINS : A list of line selection tools in order of preference.
@@ -140,97 +139,86 @@ bash\`.
140139

141140
## Configuration
142141

143-
To get the most out of cz users should consider binding shell and window manager keys.
142+
To get the most out of cz users should consider binding shell and window
143+
manager keys.
144144

145145
### Bash
146146

147-
Download this [example bash config](conf/cz.bashrc) then copy it into
147+
Download this \[example bash config\](conf/cz.bashrc) then copy it into
148148
your bashrc file.
149149

150-
The example config defines several key bindings that each *insert text into the shell's edit buffer* or run a relevant interactive program like $EDITOR.
151-
152-
- C-x x : select a plugin, run it, and insert fields from the selected
153-
line
154-
- C-x X : select a plugin, run it, and insert the selected line
155-
- C-x z : select a plugin, run it, and insert templated command output
156-
- C-x Z : select a plguin, run it, and insert templated command string
157-
- C-x r : Select and insert a command from history
158-
- C-x u : select and insert a unicode character
159-
- C-x g : select an uncomitted file in current git repo and insert its
160-
path
161-
- C-x G : select a comitted file in current git repo and insert its
162-
path
163-
- C-x d : select a directory matching the word at cursor
164-
- C-x D : select a directory under the directory at cursor
165-
- C-x f : select a file matching the word at cursor
166-
- C-x F : select a file under the directory at cursor
167-
- C-x l : select a file in the locate database matching word at cursor
168-
- C-x e : select a file containing the word at cursor
169-
- C-x E : edit the line matching the pattern at cursor
170-
171-
Bash users should source cz to load included function 'rleval'.
172-
173-
rleval [OPTIONS] COMMAND [ARGS ...]
174-
Evaluate command then...
175-
-i : insert its output into the readline buffer at cursor point.
176-
-w : replace the word at cursor point with its output.
177-
-r : run the command attached to the terminal.
178-
179-
The command string is templated using the current readline tokens.
180-
The word at cursor point is '{0}'. The first token in the command is '{1}' and so on.
181-
This function is intended to be used with the bash builtin 'bind -x'.
182-
183-
EXAMPLES
184-
Insert the first token from the current readline buffer:
185-
$ bind -x '"\C-x0":rleval -i echo {1}'
186-
187-
Insert fortunes on demand:
188-
$ bind -x '"\C-xf":rleval -i fortune"'
189-
190-
Replace the current word with a generated password:
191-
$ bind -x '"\C-xp":rleval -w pwgen 20 1'
192-
193-
Replace the current word with itself reversed:
194-
$ bind -x '"\C-xt":rleval -w "rev <<< {0}"'
195-
196-
Encode and decode base64 strings at cursor point:
197-
$ bind -x '"\C-xb":rleval -w "base64 <<< {0}"'
198-
$ bind -x '"\C-xB":rleval -w "base64 -d <<< {0}"'
199-
200-
Open the man page for the topic at cursor point:
201-
$ bind -x '"\C-xh":rleval -r man {0}'
150+
The example config defines key bindings that run cz to provide
151+
interactive functionality.
152+
153+
Some of the key bindings use the included function \`reval\` to do one
154+
of the following:
155+
156+
- Insert output from cz into the bash command buffer at cursor point.
157+
- Replace the word at cursor point in the bash command buffer with
158+
output from cz.
159+
- Run cz to launch an interactive program (like $EDITOR) using some
160+
part of the selection.
161+
162+
The example key bindings are as follows:
163+
164+
- C-x x : Select a cz plugin, run it in quote mode, and insert one or
165+
more fields from the selection.
166+
- C-x X : Select a cz plugin, run it print mode, and insert the
167+
selection.
168+
- C-x z : Select a cz plugin, run it in run mode, and insert the
169+
output of the command.
170+
- C-x Z : Select a cz plguin, run it in simulate mode and insert the
171+
command templated with the selection.
172+
- C-x r : Select a command from bash history and insert it.
173+
- C-x u : Select a unicode character and insert it.
174+
- C-x g : Select an uncomitted file in current git repository and
175+
insert its path.
176+
- C-x G : Select a comitted file in current git repository and insert
177+
its path.
178+
- C-x d : Using the current word as a directory, replace it with a
179+
selected descendant directory.
180+
- C-x D : Using the current word as a pattern, replace it with a
181+
selected matching descendant directory under $PWD.
182+
- C-x f : Using the current word as a directory, replace it with a
183+
selected descendant file.
184+
- C-x F : Using the current word as a pattern, replace it with a
185+
selected matching descendant file under $PWD.
186+
- C-x l : Using the current word as a pattern, replace it with a
187+
selected matching file from the locate database.
188+
- C-x e : Using the current word as a pattern, replace it with the
189+
path of a file matching it under $PWD.
190+
- C-x E : Using the current word as a pattern, run $EDITOR to open
191+
selected file matching it under $PWD.
202192

203193
### Zsh
204194

205-
Download this [example zsh config](conf/cz.zshrc) then copy it into
206-
your zshrc file.
195+
Download the example zsh config then copy it into your zshrc file.
207196

208197
The example config defines the same key bindings described in the bash
209198
section above.
210199

211200
### i3 Window Manager
212201

213-
Download this [example i3 config](conf/cz-i3.conf) then copy it into
214-
your i3 config.
202+
Download the example i3 config then copy it into your i3 config.
215203

216204
The example config defines the following key bindings:
217205

218-
- Mod-x : select a plugin, run it, and put fields from selected line
219-
into a clipboard
220-
- Mod-X : select a plugin, run it, and put selected line into a
221-
clipboard
222-
- Mod-z : select a plugin, run it, and put command output into a
223-
clipboard
224-
- Mod-Z : select a plguin, run it, and put command string into a
206+
- Mod-x : Select a cz plugin, run it, and put fields from selected
207+
line into a clipboard
208+
- Mod-X : Select a cz plugin, run it, and put selected line into a
225209
clipboard
226-
- Mod-c : select a command and run it
227-
- Mod-C : select a clipboard and pipe its contents through the
210+
- Mod-z : Select a cz plugin, run it in , and put command output into
211+
a clipboard
212+
- Mod-Z : Select a cz plguin, run it in simulate mode, and put the
213+
output into a clipboard
214+
- Mod-c : Select a command and run it
215+
- Mod-C : Select a clipboard and pipe its contents through the
228216
selected command
229-
- Mod-o : select a clipboard then select from URLs extracted from its
217+
- Mod-o : Select a clipboard then select a URL extracted from its
230218
contents to open in a browser
231-
- Mod-Shift-Space : select an i3 a tag and jump to the selected window
232-
- Mod-Tab : select an i3 window and jump to it
233-
- Mod-Shift-Tab : select an i3 workspace and switch to it
219+
- Mod-Shift-Space : Select an i3 a tag and jump to the selected window
220+
- Mod-Tab : Select an i3 window and jump to it
221+
- Mod-Shift-Tab : Select an i3 workspace and switch to it
234222

235223
## Plugins
236224

conf/cz.bashrc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# Bash Cz Config
22

3-
# Download and source cz
4-
if ! type cz &>/dev/null
5-
. <(curl -sS https://raw.githubusercontent.com/apathor/cz/master/cz)
6-
fi
3+
. cz
74

85
# Disable graphical line selection for the shell
96
export CZ_GUI=0
@@ -40,10 +37,10 @@ bind -x '"\C-xG":rleval cz -q git file' # insert path of selected git tra
4037

4138
# File Lookup
4239
# Replace the word under readline cursor with a selected file
43-
bind -x '"\C-xd":rleval -w cz -q find dir . {0}' # find dir matching word at cursor
44-
bind -x '"\C-xD":rleval -w cz -q find dir {0}' # find dir under directory at cursor
45-
bind -x '"\C-xf":rleval -w cz -q find file . {0}' # find file matching word at cursor
46-
bind -x '"\C-xF":rleval -w cz -q find file {0}' # find file under directory at cursor
47-
bind -x '"\C-xl":rleval -w cz -q locate {0}' # locate file matching word at cursor
48-
bind -x '"\C-xe":rleval -w cz -q grep {0}' # select a file containing the word at cursor
40+
bind -x '"\C-xd":rleval -w cz -q find dir {0}' # find dir under directory at cursor
41+
bind -x '"\C-xD":rleval -w cz -q find dir . {0}' # find dir matching word at cursor
42+
bind -x '"\C-xf":rleval -w cz -q find file {0}' # find file under directory at cursor
43+
bind -x '"\C-xF":rleval -w cz -q find file . {0}' # replace word at cursor with find file matching word at cursor
44+
bind -x '"\C-xl":rleval -w cz -q locate {0}' # replace word at cursor with name of file from locate database matching it
45+
bind -x '"\C-xe":rleval -w cz -q grep {0}' # replace word at cursor with name of selected file matching it
4946
bind -x '"\C-xE":rleval -r cz -r grep {0}' # edit the line matching the pattern at cursor

0 commit comments

Comments
 (0)