• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.config/znt/H21-Oct-2016-401111

doc/H21-Oct-2016-383273

.revision-hashH A D21-Oct-201612 21

LICENSEH A D21-Oct-201635.4 KiB701573

MakefileH A D21-Oct-20161.3 KiB3630

NEWSH A D21-Oct-2016817 1815

README.mdH A D21-Oct-201616.1 KiB430319

_n-killH A D21-Oct-2016834 4233

n-aliasesH A D21-Oct-2016918 4834

n-cdH A D21-Oct-20161.8 KiB7255

n-envH A D21-Oct-2016890 4835

n-functionsH A D21-Oct-20161.1 KiB5541

n-helpH A D21-Oct-20165.5 KiB136106

n-historyH A D21-Oct-201612.5 KiB372325

n-killH A D21-Oct-20162.1 KiB9777

n-listH A D21-Oct-201617 KiB516441

n-list-drawH A D21-Oct-20164.3 KiB134107

n-list-inputH A D21-Oct-20169.3 KiB378352

n-optionsH A D21-Oct-20161.9 KiB8564

n-panelizeH A D21-Oct-20161.5 KiB6953

znt-cd-widgetH A D21-Oct-2016196 96

znt-history-widgetH A D21-Oct-2016551 2317

znt-kill-widgetH A D21-Oct-2016200 96

znt-usetty-wrapperH A D21-Oct-2016675 4131

zsh-navigation-tools.plugin.zshH A D21-Oct-20162.3 KiB7336

README.md

1[![License (GPL version 3)](https://img.shields.io/badge/license-GNU%20GPL%20version%203-blue.svg?style=flat-square)](./LICENSE)
2[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
3![ZSH 5.0.0](https://img.shields.io/badge/zsh-v5.0.0-orange.svg?style=flat-square)
4
5![znt logo](http://imageshack.com/a/img905/2629/WK9qjN.png)
6
7# Zsh Navigation Tools
8
9Also check out [![ZCA](http://imageshack.com/a/img911/8084/qSpO8a.png) Zsh Command Architect](https://github.com/psprint/zsh-cmd-architect)
10and [Zconvey](https://github.com/psprint/zconvey)
11
12
13
14Videos:
15- [https://youtu.be/QwZ8IJEgXRE](https://youtu.be/QwZ8IJEgXRE)
16- [https://youtu.be/DN9QqssAYB8](https://youtu.be/DN9QqssAYB8)
17
18Screenshots:
19
20![n-history](http://imageshack.com/a/img921/5046/bqr0mk.png)
21
22![n-history](http://imageshack.com/a/img633/9905/WzfSdl.gif)
23
24Set of tools like `n-history` – multi-word history searcher, `n-cd` – directory
25bookmark manager, `n-kill` – `htop` like kill utility, and more. Based on
26`n-list`, a tool generating selectable curses-based list of elements that has
27access to current `Zsh` session, i.e. has broad capabilities to work together
28with it. Feature highlights include incremental multi-word searching, approximate
29matching, ANSI coloring, themes, unique mode, horizontal scroll, grepping, advanced
30history management and various integrations with `Zsh`.
31
32## News
33* 06-10-2016
34  - **Tmux-integration** – `Ctrl-B H` in Tmux to open `n-history` in new window.
35    Then select history entry, it will be copied to the original Tmux window.
36    Use this to execute local commands on remote hosts:
37
38    ![tmux integration](http://imageshack.com/a/img922/4760/oyX7eN.gif)
39
40    All that is needed is this line added to `~/.tmux.conf`:
41
42    ```
43    bind h run-shell -b "$ZNT_REPO_DIR/doc/znt-tmux.zsh"
44    ```
45
46    or – if Homebrew or other package manager is used:
47
48    ```
49    bind h run-shell -b "$ZNT_REPO_DIR/znt-tmux.zsh"
50    ```
51
52* 16-05-2016
53  - `n-kill` has completion. It proposes **words** from what's in `ps -A`. Giving `n-kill`
54    arguments means grepping – it will start only with matching `ps` entries.
55
56* 15-05-2016
57  - Fixed problem where zsh-syntax-highlighting could render `n-history` slow (for
58    long history entries).
59
60* 14-05-2016
61  - Configuration can be set from `zshrc` (starting from `v2.1.12`). Documentation is [below](#configuration). Example:
62
63    ```zsh
64    znt_list_instant_select=1
65    znt_list_border=0
66    znt_list_bold=1
67    znt_list_colorpair="green/black"
68    znt_functions_keywords=( "zplg" "zgen" "match" )
69    znt_cd_active_text="underline"
70    znt_env_nlist_coloring_color=$'\x1b[00;33m'
71    znt_cd_hotlist=( "~/.config/znt" "/usr/share/zsh/site-functions" "/usr/share/zsh"
72                     "/usr/local/share/zsh/site-functions" "/usr/local/share/zsh"
73                     "/usr/local/bin" )
74    ```
75
76* 10-05-2016
77  - Search query rotation – use `Ctrl-A` to rotate entered words right.
78    Words `1 2 3` become `3 1 2`.
79
80* 09-05-2016
81  - New feature: n-help tool, available also from n-history via `H` key. It
82    displays help screen with various information on `ZNT`.
83
84    ![n-help](http://imageshack.com/a/img922/7595/MvtJdI.gif)
85
86* 08-05-2016
87  - Approximate matching – pressing `f` or `Ctrl-F` will enter "`FIX`" mode,
88    in which `1` or `2` errors are allowed in what's searched. This utilizes
89    original Zsh approximate matching features and is intended to be used
90    after entering search query, when a typo is discovered.
91
92    ![fix mode](http://imageshack.com/a/img921/5756/64lFnv.gif)
93
94* 06-05-2016
95  - Private history can be edited. Use `e` key or `Ctrl-E` for that when in
96    n-history. Your `$EDITOR` will start. This is a way to have handy set of
97    bookmarks prepared in private history's file.
98  - Border can be disabled. Use following snippet in `~/.config/znt/n-list.conf`
99    or any other tool-targetted config file:
100
101    ```zsh
102    # Should draw the border?
103    local border=0
104    ```
105
106* 30-04-2016
107  - New feature: color themes. Use `Ctrl-T` and `Ctrl-G` to browse predefined
108    themes. They are listed in [~/.config/znt/n-list.conf](https://github.com/psprint/zsh-navigation-tools/blob/master/.config/znt/n-list.conf).
109    Use the file to permanently set a color scheme. Also, I sent a patch to Zsh developers
110    and starting from Zsh > 5.2 (not yet released) supported will be 256 colors.
111    The file [~/.config/znt/n-list.conf](https://github.com/psprint/zsh-navigation-tools/blob/master/.config/znt/n-list.conf)
112    already has set of 256-color themes prepared :)
113
114    ![themes](http://imageshack.com/a/img924/4310/EbRh30.gif)
115
116* 29-04-2016
117  - New feature: private history – n-history tracks selected history entries,
118    exposes them via new view (activated with `F1`). It is shared across all
119    sessions
120
121* 28-04-2016
122  - New features:
123    1. New n-history view (activated with `F1`): Most Frequent History Words
124    2. Predefined search keywords – use F2 to quickly search for chosen
125       keywords (video: [https://youtu.be/DN9QqssAYB8](https://youtu.be/DN9QqssAYB8))
126    3. Configuration option for doing instant selection in search mode
127
128## Installation
129
130```
131sh -c "$(curl -fsSL https://raw.githubusercontent.com/psprint/zsh-navigation-tools/master/doc/install.sh)"
132```
133
134To update run the command again.
135
136`ZNT` will be installed at `~/.config/znt/zsh-navigation-tools`, config files will be copied to `~/.config/znt`. `.zshrc`
137will be updated with only `8` lines of code, which will be added at the bottom.
138
139After installing and reloading shell give `ZNT` a quick try with `Ctrl-R` – this keyboard shortcut will open `n-history`.
140
141## Installation With [Zplugin](https://github.com/psprint/zplugin)
142Add `zplugin load psprint/zsh-navigation-tools` to `.zshrc`. The config files will be in `~/.config/znt`.
143
144## Installation With Zgen
145
146Add `zgen load psprint/zsh-navigation-tools` to `.zshrc` and issue a `zgen reset` (this assumes that there is a proper `zgen save` construct in `.zshrc`).
147The config files will be available in `~/.config/znt`.
148
149## Installation With Antigen
150Add `antigen bundle psprint/zsh-navigation-tools` to `.zshrc`. There also
151should be `antigen apply`. The config files will be in `~/.config/znt`.
152
153## Single File Manual Installation
154
155Running script `doc/generate_single_file` will create single-file version of `ZNT`.
156It can be sourced from `.zshrc`. Don't forget about configuration files as described
157above.
158
159## Manual Installation
160
161After extracting `ZNT` to `{some-directory}` add following two lines
162to `~/.zshrc`:
163
164```zsh
165fpath+=( {some-directory} )
166source "{some-directory}/zsh-navigation-tools.plugin.zsh"
167```
168
169As you can see, no plugin manager is needed to use the `*.plugin.zsh`
170file. The above two lines of code are all that almost **all** plugin
171managers do. In fact, what's actually needed is only:
172
173```zsh
174source "{some-directory}/zsh-navigation-tools.plugin.zsh"
175```
176
177because `ZNT` detects if it is used by **any** plugin manager and can
178handle `$fpath` update by itself.
179
180## Truly Manual Installation
181Copy (or link) all `n-*` and `znt-*` files to **/usr/share/zsh/site-functions/**
182(or **/usr/local/share/zsh/site-functions/**, check with `echo $fpath[1]`) and then add:
183
184    autoload n-list n-cd n-env n-kill n-panelize n-options n-aliases n-functions n-history n-help
185
186to `~/.zshrc`.
187
188Create aliases to avoid typing of the minus sign "-":
189
190```zsh
191alias naliases=n-aliases ncd=n-cd nenv=n-env nfunctions=n-functions nhistory=n-history
192alias nkill=n-kill noptions=n-options npanelize=n-panelize nhelp=n-help
193```
194
195Don't forget to copy [configuration files](https://github.com/psprint/zsh-navigation-tools/tree/master/.config/znt). They should go to `~/.config/znt`. Moreover, `n-cd` works together with option `AUTO_PUSHD` and you should have:
196
197```zsh
198setopt AUTO_PUSHD
199```
200
201in `.zshrc` (also recommend `PUSHD_IGNORE_DUPS`). Without the option `n-cd`
202will just work as incremental searcher of directory bookmarks.
203
204## History Widget
205
206To have `n-history` as the incremental searcher bound to `Ctrl-R` copy `znt-*`
207files into the `*/site-functions` dir (unless you do single file install) and
208add:
209
210```zsh
211autoload znt-history-widget
212zle -N znt-history-widget
213bindkey "^R" znt-history-widget
214```
215
216to `.zshrc`. This is done automatically when using the installer, zgen, antigen
217or single file install. Two other widgets exist, `znt-cd-widget` and
218`znt-kill-widget`, they too can be assigned to key combinations (`autoload` is done
219in `.zshrc` so no need of it):
220
221```zsh
222zle -N znt-cd-widget
223bindkey "^B" znt-cd-widget
224zle -N znt-kill-widget
225bindkey "^Y" znt-kill-widget
226```
227
228## Introduction
229
230The tools are:
231
232- `n-aliases` - browses aliases, relegates editing to `vared`
233- `n-cd` - browses dirstack and bookmarked directories, allows to enter selected directory
234- `n-functions` - browses functions, relegates editing to `zed` or `vared`
235- `n-history` - browses history, allows to edit and run commands from it
236- `n-kill` - browses processes list, allows to send signal to selected process
237- `n-env` - browses environment, relegates editing to `vared`
238- `n-options` - browses options, allows to toggle their state
239- `n-panelize` - loads output of given command into the list for browsing
240
241All tools support horizontal scroll with `<`,`>`, `{`,`}`, `h`,`l` or left and right cursors. Other keys are:
242
243- `H`, `?` (from n-history) - run n-help
244- `Ctrl-R` - start n-history, the incremental, multi-keyword history searcher (Zsh binding)
245- `Ctrl-A` - rotate entered words (1+2+3 -> 3+1+2)
246- `Ctrl-F` - fix mode (approximate matching)
247- `Ctrl-L` - redraw of whole display
248- `Ctrl-T` - browse themes (next theme)
249- `Ctrl-G` - browse themes (previous theme)
250- `Ctrl-U` - half page up
251- `Ctrl-D` - half page down
252- `Ctrl-P` - previous element (also done with vim's k)
253- `Ctrl-N` - next element (also done with vim's j)
254- `[`, `]` - jump directory bookmarks in n-cd and typical signals in n-kill
255- `g`, `G` - beginning and end of the list
256- `/` - show incremental search
257- `F3` - show/hide incremental search
258- `Esc` - exit incremental search, clearing filter
259- `Ctrl-W` (in incremental search) - delete whole word
260- `Ctrl-K` (in incremental search) - delete whole line
261- `Ctrl-O`, `o` - enter uniq mode (no duplicate lines)
262- `Ctrl-E`, `e` - edit private history (when in private history view)
263- `F1` - (in n-history) - switch view
264- `F2`, `Ctrl-X`, `Ctrl-/` - search predefined keywords (defined in config files)
265
266## Configuration
267
268`ZNT` has configuration files located in `~/.config/znt`. The files are:
269
270```
271n-aliases.conf
272n-cd.conf
273n-env.conf
274n-functions.conf
275n-history.conf
276n-kill.conf
277n-list.conf
278n-options.conf
279n-panelize.conf
280```
281
282`n-list.conf` contains main configuration variables:
283
284```zsh
285# Should the list (text, borders) be drawn in bold
286local bold=0
287
288# Main color pair (foreground/background)
289local colorpair="white/black"
290
291# Should draw the border?
292local border=1
293
294# Combinations of colors to try out with Ctrl-T and Ctrl-G
295# The last number is the bold option, 0 or 1
296local -a themes
297themes=( "white/black/1" "green/black/0" "green/black/1" "white/blue/0" "white/blue/1"
298         "magenta/black/0" "magenta/black/1" )
299```
300
301Read remaining configuration files to see what's in them. Nevertheless, configuration
302can be also set from `zshrc`. There are `5` standard `zshrc` configuration variables:
303
304```
305znt_history_active_text - underline or reverse - how should be active element highlighted
306znt_history_nlist_coloring_pattern - pattern that can be used to colorize elements
307znt_history_nlist_coloring_color - color with which to colorize
308znt_history_nlist_coloring_match_multiple - should multiple matches be colorized (0 or 1)
309znt_history_keywords (array) - search keywords activated with `Ctrl-X`, `F2` or `Ctrl-/`, e.g. ( "git" "vim" )
310```
311
312Above variables will work for `n-history` tool. For other tools, change `_history_` to
313e.g. `_cd_`, for the `n-cd` tool. The same works for all `8` tools.
314
315Common configuration of the tools uses variables with `_list_` in them:
316
317```
318znt_list_bold - should draw text in bold (0 or 1)
319znt_list_colorpair - main pair of colors to be used, e.g "green/black"
320znt_list_border - should draw borders around windows (0 or 1)
321znt_list_themes (array) - list of themes to try out with Ctrl-T, e.g. ( "white/black/1" "green/black/0" )
322znt_list_instant_select - should pressing enter in search mode leave tool (0 or 1)
323```
324
325If you used `ZNT` before `v2.1.12`, remove old configuration files `~/.config/znt/*.conf` so that `ZNT`
326can update them to the latest versions that support integration with `Zshrc`. If you used installer
327then run it again (after the remove of configuration files).
328
329## Programming
330
331The function `n-list` is used as follows:
332
333```zsh
334n-list {element1} [element2] ... [elementN]
335```
336
337This is all that is needed to be done to have the features like ANSI coloring,
338incremental multi-word search, unique mode, horizontal scroll, non-selectable
339elements (grepping is done outside `n-list`, see the tools for how it can be
340done). To set up non-selectable entries add their indices into array
341`NLIST_NONSELECTABLE_ELEMENTS`:
342
343```zsh
344typeset -a NLIST_NONSELECTABLE_ELEMENTS
345NLIST_NONSELECTABLE_ELEMENTS=( 1 )
346```
347
348Result is stored as `$reply[REPLY]` (`$` isn't needed before `REPLY` because
349of arithmetic context inside `[]`). The returned array might be different from
350input arguments as `n-list` can process them via incremental search or uniq
351mode. `$REPLY` is the index in that possibly processed array. If `$REPLY`
352equals `-1` it means that no selection have been made (user quitted via `q`
353key).
354
355To set up entries that can be jumped to with `[`,`]` keys add their indices to
356`NLIST_HOP_INDEXES` array:
357
358```zsh
359typeset -a NLIST_HOP_INDEXES
360NLIST_HOP_INDEXES=( 1 10 )
361```
362
363`n-list` can automatically colorize entries according to a `Zsh` pattern.
364Following example will colorize all numbers with blue:
365
366```zsh
367local NLIST_COLORING_PATTERN="[0-9]##"
368local NLIST_COLORING_COLOR=$'\x1b[00;34m'
369local NLIST_COLORING_END_COLOR=$'\x1b[0m'
370local NLIST_COLORING_MATCH_MULTIPLE=1
371
372n-list "This is a number 123" "This line too has a number: 456"
373```
374
375Blue is the default color, it doesn't have to be set. See `zshexpn` man page
376for more information on `Zsh` patterns. Briefly, comparing to regular
377expressions, `(#s)` is `^`, `(#e)` is `$`, `#` is `*`, `##` is `+`. Alternative
378will work when in parenthesis, i.e. `(a|b)`. BTW by using this method you can
379colorize output of the tools, via their config files (check out e.g. n-cd.conf,
380it is using this).
381
382## Performance
383
384`ZNT` are fastest with `Zsh` before `5.0.6` and starting from `5.2`
385
386## A tip
387
388Zsh plugins may look scary, as they seem to have some "architecture". In fact, what a plugin really is, is that:
389
3901. It has its directory added to `fpath`
3912. It has any first `*.plugin.zsh` file sourced
392
393That's it. When one contributes to Oh-My-Zsh or creates a plugin for any plugin manager, he only needs to account for this.
394The same with doing any non-typical Zsh Navigation Tools installation.
395
396## More
397
398- be aware of [this](https://github.com/psprint/zsh-navigation-tools/blob/f49f910d239ae5bc6e1a5bb34930307b4f4e3ffe/zsh-navigation-tools.plugin.zsh#L35-L49)
399
400## IRC Channel
401
402Channel `#zplugin@freenode` is a support place for all author's projects. Connect to:
403[chat.freenode.net:6697](ircs://chat.freenode.net:6697/%23zplugin) (SSL) or [chat.freenode.net:6667](irc://chat.freenode.net:6667/%23zplugin)
404 and join #zplugin.
405
406Following is a quick access via Webchat [![IRC](https://kiwiirc.com/buttons/chat.freenode.net/zplugin.png)](https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin)
407
408# Fixing tmux, screen and linux vt
409
410If `TERM=screen-256color` (often a case for `tmux` and `screen` sessions) then
411`ncv` terminfo capability will have `2`nd bit set.  This in general means that
412underline won't work. To fix this by creating your own `ncv=0`-equipped
413terminfo file, run:
414
415```zsh
416{ infocmp -x screen-256color; printf '\t%s\n' 'ncv@,'; } > /tmp/t && tic -x /tmp/t
417```
418
419A file will be created in directory `~/.terminfo` and will be automatically
420used, `tmux` and `screen` will work. Similar is for Linux virtual terminal:
421
422```zsh
423{ infocmp -x linux; printf '\t%s\n' 'ncv@,'; } > /tmp/t && tic -x /tmp/t
424```
425
426It will not display underline properly, but will instead highlight by a color,
427which is quite nice. The same will not work for FreeBSD's vt, `ZNT` will detect
428if that vt is used and will revert to highlighting elements via `reverse` mode.
429
430