my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
9.6 KiB

3 years ago
  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. [![Gitter][gitter-image]][gitter-link]
  5. ![znt logo](https://imageshack.com/a/img905/2629/WK9qjN.png)
  6. # Zsh Navigation Tools
  7. Set of tools like `n-history` – multi-word history searcher, `n-cd` – directory
  8. bookmark manager, `n-kill``htop` like kill utility, and more. Based on
  9. `n-list`, a tool generating selectable curses-based list of elements that has
  10. access to current `Zsh` session, i.e. has broad capabilities to work together
  11. with it. Feature highlights include incremental multi-word searching, approximate
  12. matching, ANSI coloring, themes, unique mode, horizontal scroll, grepping, advanced
  13. history management and various integrations with `Zsh`.
  14. To use it, add `zsh-navigation-tools` to the plugins array in your zshrc file:
  15. ```zsh
  16. plugins=(... zsh-navigation-tools)
  17. ```
  18. Also check out [![ZCA](https://imageshack.com/a/img911/8084/qSpO8a.png) Zsh Command Architect](https://github.com/zdharma-continuum/zsh-cmd-architect)
  19. and [Zconvey](https://github.com/zdharma-continuum/zconvey)
  20. Videos:
  21. - [https://youtu.be/QwZ8IJEgXRE](https://youtu.be/QwZ8IJEgXRE)
  22. - [https://youtu.be/DN9QqssAYB8](https://youtu.be/DN9QqssAYB8)
  23. Screenshots:
  24. ![n-history](https://imageshack.com/a/img921/5046/bqr0mk.png)
  25. ![n-history](https://imageshack.com/a/img633/9905/WzfSdl.gif)
  26. ## History Widget
  27. To have `n-history` as the incremental searcher bound to `Ctrl-R` copy `znt-*`
  28. files into the `*/site-functions` dir (unless you do single file install) and
  29. add:
  30. ```zsh
  31. autoload znt-history-widget
  32. zle -N znt-history-widget
  33. bindkey "^R" znt-history-widget
  34. ```
  35. to `.zshrc`. This is done automatically when using the installer, zgen, antigen
  36. or single file install. Two other widgets exist, `znt-cd-widget` and
  37. `znt-kill-widget`, they too can be assigned to key combinations (`autoload` is done
  38. in `.zshrc` so no need of it):
  39. ```zsh
  40. zle -N znt-cd-widget
  41. bindkey "^B" znt-cd-widget
  42. zle -N znt-kill-widget
  43. bindkey "^Y" znt-kill-widget
  44. ```
  45. ## Introduction
  46. The tools are:
  47. - `n-aliases` - browses aliases, relegates editing to `vared`
  48. - `n-cd` - browses dirstack and bookmarked directories, allows to enter selected directory
  49. - `n-functions` - browses functions, relegates editing to `zed` or `vared`
  50. - `n-history` - browses history, allows to edit and run commands from it
  51. - `n-kill` - browses processes list, allows to send signal to selected process
  52. - `n-env` - browses environment, relegates editing to `vared`
  53. - `n-options` - browses options, allows to toggle their state
  54. - `n-panelize` - loads output of given command into the list for browsing
  55. All tools support horizontal scroll with `<`,`>`, `{`,`}`, `h`,`l` or left and right cursors. Other keys are:
  56. - `H`, `?` (from n-history) - run n-help
  57. - `Ctrl-R` - start n-history, the incremental, multi-keyword history searcher (Zsh binding)
  58. - `Ctrl-A` - rotate entered words (1+2+3 -> 3+1+2)
  59. - `Ctrl-F` - fix mode (approximate matching)
  60. - `Ctrl-L` - redraw of whole display
  61. - `Ctrl-T` - browse themes (next theme)
  62. - `Ctrl-G` - browse themes (previous theme)
  63. - `Ctrl-U` - half page up
  64. - `Ctrl-D` - half page down
  65. - `Ctrl-P` - previous element (also done with vim's k)
  66. - `Ctrl-N` - next element (also done with vim's j)
  67. - `[`, `]` - jump directory bookmarks in n-cd and typical signals in n-kill
  68. - `g`, `G` - beginning and end of the list
  69. - `/` - show incremental search
  70. - `F3` - show/hide incremental search
  71. - `Esc` - exit incremental search, clearing filter
  72. - `Ctrl-W` (in incremental search) - delete whole word
  73. - `Ctrl-K` (in incremental search) - delete whole line
  74. - `Ctrl-O`, `o` - enter uniq mode (no duplicate lines)
  75. - `Ctrl-E`, `e` - edit private history (when in private history view)
  76. - `F1` - (in n-history) - switch view
  77. - `F2`, `Ctrl-X`, `Ctrl-/` - search predefined keywords (defined in config files)
  78. ## Configuration
  79. `ZNT` has configuration files located in `~/.config/znt`. The files are:
  80. ```
  81. n-aliases.conf
  82. n-cd.conf
  83. n-env.conf
  84. n-functions.conf
  85. n-history.conf
  86. n-kill.conf
  87. n-list.conf
  88. n-options.conf
  89. n-panelize.conf
  90. ```
  91. `n-list.conf` contains main configuration variables:
  92. ```zsh
  93. # Should the list (text, borders) be drawn in bold
  94. local bold=0
  95. # Main color pair (foreground/background)
  96. local colorpair="white/black"
  97. # Should draw the border?
  98. local border=1
  99. # Combinations of colors to try out with Ctrl-T and Ctrl-G
  100. # The last number is the bold option, 0 or 1
  101. local -a themes
  102. themes=( "white/black/1" "green/black/0" "green/black/1" "white/blue/0" "white/blue/1"
  103. "magenta/black/0" "magenta/black/1" )
  104. ```
  105. Read remaining configuration files to see what's in them. Nevertheless, configuration
  106. can be also set from `zshrc`. There are `5` standard `zshrc` configuration variables:
  107. ```
  108. znt_history_active_text - underline or reverse - how should be active element highlighted
  109. znt_history_nlist_coloring_pattern - pattern that can be used to colorize elements
  110. znt_history_nlist_coloring_color - color with which to colorize
  111. znt_history_nlist_coloring_match_multiple - should multiple matches be colorized (0 or 1)
  112. znt_history_keywords (array) - search keywords activated with `Ctrl-X`, `F2` or `Ctrl-/`, e.g. ( "git" "vim" )
  113. ```
  114. Above variables will work for `n-history` tool. For other tools, change `_history_` to
  115. e.g. `_cd_`, for the `n-cd` tool. The same works for all `8` tools.
  116. Common configuration of the tools uses variables with `_list_` in them:
  117. ```
  118. znt_list_bold - should draw text in bold (0 or 1)
  119. znt_list_colorpair - main pair of colors to be used, e.g "green/black"
  120. znt_list_border - should draw borders around windows (0 or 1)
  121. znt_list_themes (array) - list of themes to try out with Ctrl-T, e.g. ( "white/black/1" "green/black/0" )
  122. znt_list_instant_select - should pressing enter in search mode leave tool (0 or 1)
  123. ```
  124. If you used `ZNT` before `v2.1.12`, remove old configuration files `~/.config/znt/*.conf` so that `ZNT`
  125. can update them to the latest versions that support integration with `Zshrc`. If you used installer
  126. then run it again (after the remove of configuration files).
  127. ## Programming
  128. The function `n-list` is used as follows:
  129. ```zsh
  130. n-list {element1} [element2] ... [elementN]
  131. ```
  132. This is all that is needed to be done to have the features like ANSI coloring,
  133. incremental multi-word search, unique mode, horizontal scroll, non-selectable
  134. elements (grepping is done outside `n-list`, see the tools for how it can be
  135. done). To set up non-selectable entries add their indices into array
  136. `NLIST_NONSELECTABLE_ELEMENTS`:
  137. ```zsh
  138. typeset -a NLIST_NONSELECTABLE_ELEMENTS
  139. NLIST_NONSELECTABLE_ELEMENTS=( 1 )
  140. ```
  141. Result is stored as `$reply[REPLY]` (`$` isn't needed before `REPLY` because
  142. of arithmetic context inside `[]`). The returned array might be different from
  143. input arguments as `n-list` can process them via incremental search or uniq
  144. mode. `$REPLY` is the index in that possibly processed array. If `$REPLY`
  145. equals `-1` it means that no selection have been made (user quitted via `q`
  146. key).
  147. To set up entries that can be jumped to with `[`,`]` keys add their indices to
  148. `NLIST_HOP_INDEXES` array:
  149. ```zsh
  150. typeset -a NLIST_HOP_INDEXES
  151. NLIST_HOP_INDEXES=( 1 10 )
  152. ```
  153. `n-list` can automatically colorize entries according to a `Zsh` pattern.
  154. Following example will colorize all numbers with blue:
  155. ```zsh
  156. local NLIST_COLORING_PATTERN="[0-9]##"
  157. local NLIST_COLORING_COLOR=$'\x1b[00;34m'
  158. local NLIST_COLORING_END_COLOR=$'\x1b[0m'
  159. local NLIST_COLORING_MATCH_MULTIPLE=1
  160. n-list "This is a number 123" "This line too has a number: 456"
  161. ```
  162. Blue is the default color, it doesn't have to be set. See `zshexpn` man page
  163. for more information on `Zsh` patterns. Briefly, comparing to regular
  164. expressions, `(#s)` is `^`, `(#e)` is `$`, `#` is `*`, `##` is `+`. Alternative
  165. will work when in parenthesis, i.e. `(a|b)`. BTW by using this method you can
  166. colorize output of the tools, via their config files (check out e.g. n-cd.conf,
  167. it is using this).
  168. ## Performance
  169. `ZNT` are fastest with `Zsh` before `5.0.6` and starting from `5.2`
  170. ## A tip
  171. Zsh plugins may look scary, as they seem to have some "architecture". In fact, what a plugin really is, is that:
  172. 1. It has its directory added to `fpath`
  173. 2. It has any first `*.plugin.zsh` file sourced
  174. That's it. When one contributes to Oh-My-Zsh or creates a plugin for any plugin manager, he only needs to account for this.
  175. The same with doing any non-typical Zsh Navigation Tools installation.
  176. ## More
  177. - be aware of [this](https://github.com/zdharma-continuum/zsh-navigation-tools/blob/f49f910d239ae5bc6e1a5bb34930307b4f4e3ffe/zsh-navigation-tools.plugin.zsh#L35-L49)
  178. # Fixing tmux, screen and linux vt
  179. If `TERM=screen-256color` (often a case for `tmux` and `screen` sessions) then
  180. `ncv` terminfo capability will have `2`nd bit set. This in general means that
  181. underline won't work. To fix this by creating your own `ncv=0`-equipped
  182. terminfo file, run:
  183. ```zsh
  184. { infocmp -x screen-256color; printf '\t%s\n' 'ncv@,'; } > /tmp/t && tic -x /tmp/t
  185. ```
  186. A file will be created in directory `~/.terminfo` and will be automatically
  187. used, `tmux` and `screen` will work. Similar is for Linux virtual terminal:
  188. ```zsh
  189. { infocmp -x linux; printf '\t%s\n' 'ncv@,'; } > /tmp/t && tic -x /tmp/t
  190. ```
  191. It will not display underline properly, but will instead highlight by a color,
  192. which is quite nice. The same will not work for FreeBSD's vt, `ZNT` will detect
  193. if that vt is used and will revert to highlighting elements via `reverse` mode.
  194. [gitter-image]: https://badges.gitter.im/zdharma-continuum/community.svg
  195. [gitter-link]: https://gitter.im/zdharma-continuum/community