From c2b4d9ff40f2f965a5d9d282081f3f8bf51bb5b5 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Mon, 30 Nov 2015 10:48:30 +0100 Subject: znt: n-history supports multi-line cmds and starts with current buffer --- plugins/zsh-navigation-tools/.config/znt/n-cd.conf | 1 + plugins/zsh-navigation-tools/.config/znt/n-history.conf | 5 +++++ plugins/zsh-navigation-tools/n-history | 7 ++++--- plugins/zsh-navigation-tools/n-list | 15 +++++++++++++++ plugins/zsh-navigation-tools/znt-history-widget | 2 ++ 5 files changed, 27 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/zsh-navigation-tools/.config/znt/n-cd.conf b/plugins/zsh-navigation-tools/.config/znt/n-cd.conf index 5fcfe64fa..f8c49bfac 100644 --- a/plugins/zsh-navigation-tools/.config/znt/n-cd.conf +++ b/plugins/zsh-navigation-tools/.config/znt/n-cd.conf @@ -1,6 +1,7 @@ # Hotlist local hotlist hotlist=( + ~/.config/znt /usr/share/zsh/site-functions /usr/share/zsh /usr/local/share/zsh/site-functions diff --git a/plugins/zsh-navigation-tools/.config/znt/n-history.conf b/plugins/zsh-navigation-tools/.config/znt/n-history.conf index f798f7121..5d4bad822 100644 --- a/plugins/zsh-navigation-tools/.config/znt/n-history.conf +++ b/plugins/zsh-navigation-tools/.config/znt/n-history.conf @@ -3,3 +3,8 @@ # On Linux virtual terminal this will be enforced to reverse (because of poor # underline support on that terminal) local active_text=underline + +# Highlight a few keywords +local NLIST_COLORING_PATTERN="(while|for |sudo|make|(#s)git|vim(#e)|vim |emacs(#e)|emacs )" +local NLIST_COLORING_COLOR=$'\x1b[00;33m' +local NLIST_COLORING_MATCH_MULTIPLE=1 diff --git a/plugins/zsh-navigation-tools/n-history b/plugins/zsh-navigation-tools/n-history index e66f2a50a..c9e53316b 100644 --- a/plugins/zsh-navigation-tools/n-history +++ b/plugins/zsh-navigation-tools/n-history @@ -10,6 +10,7 @@ emulate -L zsh setopt extendedglob zmodload zsh/curses +zmodload zsh/parameter local IFS=" " @@ -24,16 +25,16 @@ local selected NLIST_REMEMBER_STATE=0 -list=( `builtin history -rn 1` ) +list=( "$history[@]" ) list=( "${(@M)list:#(#i)*$1*}" ) -local NLIST_GREP_STRING="$1" - if [ "$#list" -eq 0 ]; then echo "No matching history entries" return 1 fi +local NLIST_GREP_STRING="$1" +local NLIST_REPLACE_NEWLINES="1" n-list "${list[@]}" if [ "$REPLY" -gt 0 ]; then diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list index 3b326515e..c7066318e 100644 --- a/plugins/zsh-navigation-tools/n-list +++ b/plugins/zsh-navigation-tools/n-list @@ -139,6 +139,7 @@ if [ "$#" -lt 1 ]; then fi REPLY="-1" +typeset -ga reply reply=() integer term_height="$LINES" @@ -188,6 +189,11 @@ if [ "$NLIST_START_IN_SEARCH_MODE" -eq 1 ]; then NLIST_IS_SEARCH_MODE=1 fi +if [ -n "$NLIST_SET_SEARCH_TO" ]; then + NLIST_SEARCH_BUFFER="$NLIST_SET_SEARCH_TO" + NLIST_SET_SEARCH_TO="" +fi + if [ "$NLIST_START_IN_UNIQ_MODE" -eq 1 ]; then NLIST_START_IN_UNIQ_MODE=0 NLIST_IS_UNIQ_MODE=1 @@ -281,6 +287,9 @@ while (( 1 )); do if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) + + # We have display list, lets replace newlines with "\n" when needed (1/3) + [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) fi # Output colored list @@ -333,11 +342,17 @@ while (( 1 )); do if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) + + # We have display list, lets replace newlines with "\n" when needed (2/3) + [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) fi else if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" ) + + # We have display list, lets replace newlines with "\n" when needed (3/3) + [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" ) fi fi diff --git a/plugins/zsh-navigation-tools/znt-history-widget b/plugins/zsh-navigation-tools/znt-history-widget index 097de8233..9ddae606d 100644 --- a/plugins/zsh-navigation-tools/znt-history-widget +++ b/plugins/zsh-navigation-tools/znt-history-widget @@ -1,8 +1,10 @@ autoload znt-usetty-wrapper n-history local NLIST_START_IN_SEARCH_MODE=1 local NLIST_START_IN_UNIQ_MODE=1 +local NLIST_SET_SEARCH_TO="$BUFFER" znt-usetty-wrapper n-history "$@" unset NLIST_START_IN_SEARCH_MODE unset NLIST_START_IN_UNIQ_MODE +unset NLIST_SET_SEARCH_TO -- cgit v1.2.3-70-g09d2 From c8852902a93ec007c326ae51e711d7b3a9c5b0c4 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Mon, 30 Nov 2015 15:05:49 +0100 Subject: Renamed README.txt to README.md --- plugins/zsh-navigation-tools/README.md | 101 ++++++++++++++++++++++++++++++++ plugins/zsh-navigation-tools/README.txt | 101 -------------------------------- 2 files changed, 101 insertions(+), 101 deletions(-) create mode 100644 plugins/zsh-navigation-tools/README.md delete mode 100644 plugins/zsh-navigation-tools/README.txt (limited to 'plugins') diff --git a/plugins/zsh-navigation-tools/README.md b/plugins/zsh-navigation-tools/README.md new file mode 100644 index 000000000..4771742db --- /dev/null +++ b/plugins/zsh-navigation-tools/README.md @@ -0,0 +1,101 @@ +# Zsh Navigation Tools + +http://imageshack.com/a/img633/7967/ps6rKR.png + +A tool generating a selectable curses-based list of elements that has access to +current Zsh session, i.e. has broad capabilities to work together with it. +That's n-list. The files n-cd, n-env, n-kill, etc. are applications of +the tool. Feature highlights include incremental multi-word searching, ANSI +coloring, unique mode, horizontal scroll, non-selectable elements, grepping and +various integrations with Zsh. + +## History Widget + +To have n-history as the incremental searcher bound to Ctrl-R copy znt-* +files into the */site-functions dir (unless you use Oh My Zsh) and +add: + + autoload znt-history-widget + zle -N znt-history-widget + bindkey "^R" znt-history-widget + +to .zshrc. This is done automatically when using Oh My Zsh. Two other +widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned +to key combinations: + + zle -N znt-cd-widget + bindkey "^T" znt-cd-widget + zle -N znt-kill-widget + bindkey "^Y" znt-kill-widget + +## Introduction + +The tools are: + +- n-aliases - browses aliases, relegates editing to vared +- n-cd - browses dirstack and bookmarked directories, allows to enter selected directory +- n-functions - browses functions, relegates editing to zed or vared +- n-history - browses history, allows to edit and run commands from it +- n-kill - browses processes list, allows to send signal to selected process +- n-env - browses environment, relegates editing to vared +- n-options - browses options, allows to toggle their state +- n-panelize - loads output of given command into the list for browsing + +All tools support horizontal scroll with <,>, {,}, h,l or left and right +cursors. Other keys are: + +- [,] - jump directory bookmarks in n-cd and typical signals in n-kill +- Ctrl-d, Ctrl-u - half page up or down +- Ctrl-p, Ctrl-n - previous and next (also done with vim's j,k) +- Ctrl-l - redraw of whole display +- g, G - beginning and end of the list +- Ctrl-o, o - enter uniq mode (no duplicate lines) +- / - start incremental search +- Enter - finish incremental search, retaining filter +- Esc - exit incremental search, clearing filter +- Ctrl-w (in incremental search) - delete whole word +- Ctrl-k (in incremental search) - delete whole line + +## Programming + +The function n-list is used as follows: + + n-list {element1} [element2] ... [elementN] + +This is all that is needed to be done to have the features like ANSI coloring, +incremental multi-word search, unique mode, horizontal scroll, non-selectable +elements (grepping is done outside n-list, see the tools for how it can be +done). To set up non-selectable entries add their indices into array +NLIST_NONSELECTABLE_ELEMENTS: + + typeset -a NLIST_NONSELECTABLE_ELEMENTS + NLIST_NONSELECTABLE_ELEMENTS=( 1 ) + +Result is stored as $reply[REPLY] ($ isn't needed before REPLY because +of arithmetic context inside []). The returned array might be different from +input arguments as n-list can process them via incremental search or uniq +mode. $REPLY is the index in that possibly processed array. If $REPLY +equals -1 it means that no selection have been made (user quitted via q +key). + +To set up entries that can be jumped to with [,] keys add their indices to +NLIST_HOP_INDEXES array: + + typeset -a NLIST_HOP_INDEXES + NLIST_HOP_INDEXES=( 1 10 ) + +n-list can automatically colorize entries according to a Zsh pattern. +Following example will colorize all numbers with blue: + + local NLIST_COLORING_PATTERN="[0-9]##" + local NLIST_COLORING_COLOR=$'\x1b[00;34m' + local NLIST_COLORING_END_COLOR=$'\x1b[0m' + local NLIST_COLORING_MATCH_MULTIPLE=1 + n-list "This is a number 123" "This line too has a number: 456" + +Blue is the default color, it doesn't have to be set. See zshexpn man page +for more information on Zsh patterns. Briefly, comparing to regular +expressions, (#s) is ^, (#e) is $, # is *, ## is +. Alternative +will work when in parenthesis, i.e. (a|b). BTW by using this method you can +colorize output of the tools, via their config files (check out e.g. n-cd.conf, +it uses this). diff --git a/plugins/zsh-navigation-tools/README.txt b/plugins/zsh-navigation-tools/README.txt deleted file mode 100644 index 4771742db..000000000 --- a/plugins/zsh-navigation-tools/README.txt +++ /dev/null @@ -1,101 +0,0 @@ -# Zsh Navigation Tools - -http://imageshack.com/a/img633/7967/ps6rKR.png - -A tool generating a selectable curses-based list of elements that has access to -current Zsh session, i.e. has broad capabilities to work together with it. -That's n-list. The files n-cd, n-env, n-kill, etc. are applications of -the tool. Feature highlights include incremental multi-word searching, ANSI -coloring, unique mode, horizontal scroll, non-selectable elements, grepping and -various integrations with Zsh. - -## History Widget - -To have n-history as the incremental searcher bound to Ctrl-R copy znt-* -files into the */site-functions dir (unless you use Oh My Zsh) and -add: - - autoload znt-history-widget - zle -N znt-history-widget - bindkey "^R" znt-history-widget - -to .zshrc. This is done automatically when using Oh My Zsh. Two other -widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned -to key combinations: - - zle -N znt-cd-widget - bindkey "^T" znt-cd-widget - zle -N znt-kill-widget - bindkey "^Y" znt-kill-widget - -## Introduction - -The tools are: - -- n-aliases - browses aliases, relegates editing to vared -- n-cd - browses dirstack and bookmarked directories, allows to enter selected directory -- n-functions - browses functions, relegates editing to zed or vared -- n-history - browses history, allows to edit and run commands from it -- n-kill - browses processes list, allows to send signal to selected process -- n-env - browses environment, relegates editing to vared -- n-options - browses options, allows to toggle their state -- n-panelize - loads output of given command into the list for browsing - -All tools support horizontal scroll with <,>, {,}, h,l or left and right -cursors. Other keys are: - -- [,] - jump directory bookmarks in n-cd and typical signals in n-kill -- Ctrl-d, Ctrl-u - half page up or down -- Ctrl-p, Ctrl-n - previous and next (also done with vim's j,k) -- Ctrl-l - redraw of whole display -- g, G - beginning and end of the list -- Ctrl-o, o - enter uniq mode (no duplicate lines) -- / - start incremental search -- Enter - finish incremental search, retaining filter -- Esc - exit incremental search, clearing filter -- Ctrl-w (in incremental search) - delete whole word -- Ctrl-k (in incremental search) - delete whole line - -## Programming - -The function n-list is used as follows: - - n-list {element1} [element2] ... [elementN] - -This is all that is needed to be done to have the features like ANSI coloring, -incremental multi-word search, unique mode, horizontal scroll, non-selectable -elements (grepping is done outside n-list, see the tools for how it can be -done). To set up non-selectable entries add their indices into array -NLIST_NONSELECTABLE_ELEMENTS: - - typeset -a NLIST_NONSELECTABLE_ELEMENTS - NLIST_NONSELECTABLE_ELEMENTS=( 1 ) - -Result is stored as $reply[REPLY] ($ isn't needed before REPLY because -of arithmetic context inside []). The returned array might be different from -input arguments as n-list can process them via incremental search or uniq -mode. $REPLY is the index in that possibly processed array. If $REPLY -equals -1 it means that no selection have been made (user quitted via q -key). - -To set up entries that can be jumped to with [,] keys add their indices to -NLIST_HOP_INDEXES array: - - typeset -a NLIST_HOP_INDEXES - NLIST_HOP_INDEXES=( 1 10 ) - -n-list can automatically colorize entries according to a Zsh pattern. -Following example will colorize all numbers with blue: - - local NLIST_COLORING_PATTERN="[0-9]##" - local NLIST_COLORING_COLOR=$'\x1b[00;34m' - local NLIST_COLORING_END_COLOR=$'\x1b[0m' - local NLIST_COLORING_MATCH_MULTIPLE=1 - n-list "This is a number 123" "This line too has a number: 456" - -Blue is the default color, it doesn't have to be set. See zshexpn man page -for more information on Zsh patterns. Briefly, comparing to regular -expressions, (#s) is ^, (#e) is $, # is *, ## is +. Alternative -will work when in parenthesis, i.e. (a|b). BTW by using this method you can -colorize output of the tools, via their config files (check out e.g. n-cd.conf, -it uses this). -- cgit v1.2.3-70-g09d2 From 39e4dfb6a60cba39a47df68764075d841829be49 Mon Sep 17 00:00:00 2001 From: Sebastian Gniazdowski Date: Mon, 30 Nov 2015 15:31:19 +0100 Subject: Updated README.md --- plugins/zsh-navigation-tools/README.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/zsh-navigation-tools/README.md b/plugins/zsh-navigation-tools/README.md index 4771742db..686213c36 100644 --- a/plugins/zsh-navigation-tools/README.md +++ b/plugins/zsh-navigation-tools/README.md @@ -2,16 +2,17 @@ http://imageshack.com/a/img633/7967/ps6rKR.png -A tool generating a selectable curses-based list of elements that has access to -current Zsh session, i.e. has broad capabilities to work together with it. -That's n-list. The files n-cd, n-env, n-kill, etc. are applications of -the tool. Feature highlights include incremental multi-word searching, ANSI +Set of tools like n-history – multi-word history searcher, n-cd – directory +bookmark manager, n-kill – htop like kill utility, and more. Based on +n-list, a tool generating selectable curses-based list of elements that has +access to current Zsh session, i.e. has broad capabilities to work together +with it. Feature highlights include incremental multi-word searching, ANSI coloring, unique mode, horizontal scroll, non-selectable elements, grepping and various integrations with Zsh. ## History Widget -To have n-history as the incremental searcher bound to Ctrl-R copy znt-* +To have n-history as multi-word incremental searcher bound to Ctrl-R copy znt-* files into the */site-functions dir (unless you use Oh My Zsh) and add: @@ -21,13 +22,16 @@ add: to .zshrc. This is done automatically when using Oh My Zsh. Two other widgets exist, znt-cd-widget and znt-kill-widget, they can be too assigned -to key combinations: +to key combinations (no need for autoload when using Oh My Zsh): zle -N znt-cd-widget bindkey "^T" znt-cd-widget zle -N znt-kill-widget bindkey "^Y" znt-kill-widget +Oh My Zsh stores history into ~/.zsh_history. When you switch to OMZ you could +want to copy your previous data (from e.g. ~/.zhistory) into the new location. + ## Introduction The tools are: @@ -99,3 +103,9 @@ expressions, (#s) is ^, (#e) is $, # is *, ## is +. Alternative will work when in parenthesis, i.e. (a|b). BTW by using this method you can colorize output of the tools, via their config files (check out e.g. n-cd.conf, it uses this). + +## Performance +ZNT is fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to +be released). + +# vim:filetype=conf -- cgit v1.2.3-70-g09d2