73591101b6db1e67ad3a0c2f90c81bc8174f4056

Author
psprint <sgniazdowski@gmail.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

znt: Update to v2.2.7 (#5576)

Diff

  1diff --git a/plugins/zsh-navigation-tools/NEWS b/plugins/zsh-navigation-tools/NEWS
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..acd9f2ebca82f6766c6934e8164acea3d0a53d59
  4--- /dev/null
  5+++ b/plugins/zsh-navigation-tools/NEWS
  6@@ -0,0 +1,17 @@
  7+-------------------------------------
  8+CHANGES FROM PREVIOUS VERSIONS OF ZNT
  9+-------------------------------------
 10+
 11+Changes from 2.2.1 to 2.2.7
 12+---------------------------
 13+
 14+Tmux integration has been added – bind file znt-tmux.zsh in Tmux as
 15+described in README.md and e.g. run local history on remote hosts. Tmux
 16+opens new window with n-history, and pastes selected history entry into
 17+immediate previous window (e.g. a remote session). Fixed plugin.zsh file
 18+to not use (outer scope) positional parameters. This fixes problem with
 19+Grlm's Zsh configuration. The file now doesn't use "test" builtin (but
 20+[[ instead), because it can be shadowed by alias or command. Private
 21+history has been fixed to not overwrite its history file with the same
 22+content. This improves performance when switching to private history
 23+view.
 24diff --git a/plugins/zsh-navigation-tools/README.md b/plugins/zsh-navigation-tools/README.md
 25index 7a679fe671dc88b6a4f5719f2f116de89531e0c6..ed532a16157d5dbb6fd65685ce5ca11ca5cfe88b 100644
 26--- a/plugins/zsh-navigation-tools/README.md
 27+++ b/plugins/zsh-navigation-tools/README.md
 28@@ -34,6 +34,60 @@ want to copy your previous data (from e.g. ~/.zhistory) into the new location.
 29 
 30 ## News
 31 
 32+* 06-10-2016
 33+  - Tmux-integration – Ctrl-b-h in Tmux to open n-history in new window.
 34+    Then select history entry, it will be copied to the original Tmux window.
 35+    Use this to execute local commands on remote hosts. All that is needed is
 36+    this line added to ~/.tmux.conf:
 37+
 38+    bind h run-shell -b "$ZNT_REPO_DIR/znt-tmux.zsh"
 39+
 40+* 16-05-2016
 41+  - n-kill has completion. It proposes *words* from what's in `ps -A`. Giving n-kill
 42+    arguments means grepping – it will start only with matching `ps` entries.
 43+
 44+* 15-05-2016
 45+  - Fixed problem where zsh-syntax-highlighting could render n-history slow (for
 46+    long history entries).
 47+
 48+* 14-05-2016
 49+  - Configuration can be set from zshrc. Example:
 50+
 51+    znt_list_instant_select=1
 52+    znt_list_border=0
 53+    znt_list_bold=1
 54+    znt_list_colorpair="green/black"
 55+    znt_functions_keywords=( "zplg" "zgen" "match" )
 56+    znt_cd_active_text="underline"
 57+    znt_env_nlist_coloring_color=$'\x1b[00;33m'
 58+    znt_cd_hotlist=( "~/.config/znt" "/usr/share/zsh/site-functions" "/usr/share/zsh"
 59+                     "/usr/local/share/zsh/site-functions" "/usr/local/share/zsh"
 60+                     "/usr/local/bin" )
 61+
 62+* 10-05-2016
 63+  - Search query rotation – use Ctrl-A to rotate entered words right.
 64+    Words `1 2 3` become `3 1 2`.
 65+
 66+* 09-05-2016
 67+  - New feature: n-help tool, available also from n-history via H key. It
 68+    displays help screen with various information on ZNT.
 69+
 70+* 08-05-2016
 71+  - Approximate matching – pressing f or Ctrl-F will enter FIX mode, in
 72+    which 1 or 2 errors are allowed in what is searched. This utilizes
 73+    original Zsh approximate matching features and is intended to be used
 74+    after entering search query, when a typo is discovered.
 75+
 76+* 06-05-2016
 77+  - Private history can be edited. Use e key or Ctrl-E for that when in
 78+    n-history. Your $EDITOR will start. This is a way to have handy set
 79+    of bookmarks prepared in private history's file.
 80+  - Border can be disabled. Use following snippet in ~/.config/znt/n-list.conf
 81+    or any other tool-targetted config file:
 82+
 83+    # Should draw the border?
 84+    local border=0
 85+
 86 * 30-04-2016
 87   - New feature: color themes. Use Ctrl-T and Ctrl-G to browse predefined
 88     themes. They are listed in ~/.config/znt/n-list.conf. Use the file to
 89diff --git a/plugins/zsh-navigation-tools/n-history b/plugins/zsh-navigation-tools/n-history
 90index af475dcb891d20f50b29aa5e2f971a39e7449005..b425ecd10f4bb7040636e718df5f40b0a455fb13 100644
 91--- a/plugins/zsh-navigation-tools/n-history
 92+++ b/plugins/zsh-navigation-tools/n-history
 93@@ -307,7 +307,7 @@ while (( 1 )); do
 94     elif [ "$active_view" = "1" ]; then
 95         if [ -s "$private_history_db" ]; then
 96             local title=$'\x1b[00;32m'"Private history:"$'\x1b[00;00m\0'
 97-            () { fc -ap -R "$private_history_db"; list=( "$title" ${history[@]} ) }
 98+            () { fc -Rap "$private_history_db" 20000 0; list=( "$title" ${history[@]} ) }
 99         else
100             list=( "Private history - history entries selected via this tool will be put here" )
101         fi
102@@ -335,21 +335,37 @@ done
103 
104 if [ "$REPLY" -gt 0 ]; then
105     selected="$reply[REPLY]"
106+
107+    # Append to private history
108+    if [[ "$active_view" = "0" ]]; then
109+        local newline=$'\n'
110+        local selected_ph="${selected//$newline/\\$newline}"
111+        print -r -- "$selected_ph" >> "$private_history_db"
112+    fi
113+
114+    # TMUX?
115+    if [[ "$ZNT_TMUX_MODE" = "1" ]]; then
116+        tmux send -t "$ZNT_TMUX_ORIGIN_SESSION:$ZNT_TMUX_ORIGIN_WINDOW.$ZNT_TMUX_ORIGIN_PANE" "$selected"
117+        tmux kill-window
118+        return 0
119     # ZLE?
120-    if [ "${(t)CURSOR}" = "integer-local-special" ]; then
121+    elif [ "${(t)CURSOR}" = "integer-local-special" ]; then
122         zle .redisplay
123         zle .kill-buffer
124         LBUFFER+="$selected"
125-
126-        # Append to private history
127-        local newline=$'\n'
128-        selected="${selected//$newline/\\$newline}"
129-        [ "$active_view" = "0" ] && print -r -- "$selected" >> "$private_history_db"
130     else
131         print -zr -- "$selected"
132     fi
133 else
134-    [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
135+    # TMUX?
136+    if [[ "$ZNT_TMUX_MODE" = "1" ]]; then
137+        tmux kill-window
138+    # ZLE?
139+    elif [[ "${(t)CURSOR}" = "integer-local-special" ]]; then
140+        zle redisplay
141+    fi
142 fi
143 
144+return 0
145+
146 # vim: set filetype=zsh:
147diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list
148index f3d2e5b3efc9fad1ca7e7c4a63c822dbc111773c..3fe5542a67906d919ab4f52733d43daf96fdf4bb 100644
149--- a/plugins/zsh-navigation-tools/n-list
150+++ b/plugins/zsh-navigation-tools/n-list
151@@ -310,8 +310,9 @@ while (( 1 )); do
152                         colsearch_pattern="${search_buffer// ##/|(#a2)}"
153                         list=( "${(@M)list:#(#ia2)*$~search_pattern*}" )
154                     else
155-                        # Patterns will be *foo*~^*bar* and (foo|bar)
156+                        # Pattern will be *foo*~^*bar* (inventor: Mikael Magnusson)
157                         search_pattern="${search_buffer// ##/*~^*}"
158+                        # Pattern will be (foo|bar)
159                         colsearch_pattern="${search_buffer// ##/|}"
160                         list=( "${(@M)list:#(#i)*$~search_pattern*}" )
161                     fi
162diff --git a/plugins/zsh-navigation-tools/znt-tmux.zsh b/plugins/zsh-navigation-tools/znt-tmux.zsh
163new file mode 100755
164index 0000000000000000000000000000000000000000..6a96e97a1662e89c971d021f5355724ae2db02ec
165--- /dev/null
166+++ b/plugins/zsh-navigation-tools/znt-tmux.zsh
167@@ -0,0 +1,50 @@
168+#!/usr/bin/env zsh
169+
170+# Copyright (c) 2016, Zsolt Lengyel
171+# Modifications copyright (c) 2016, Sebastian Gniazdowski
172+
173+#
174+# This script opens a new, temporary tmux pane and runs n-history. When
175+# a selection is made, the result (history entry) is pasted back into
176+# original tmux pane, and the temporary pane is closed. This allows to
177+# use local history on remote machines.
178+#
179+# To use, put this line to your ~/.tmux.conf. The tool is invoked with:
180+# Ctrl+b h
181+#
182+# bind h run-shell -b "$ZNT_REPO_DIR/znt-tmux.zsh"
183+#
184+
185+# get and save the current active tmux pane id
186+active_pane=$(tmux display -p -F ':#{session_id}:#I:#P:#{pane_active}:#{window_active}:#{session_attached}' )
187+a_active_pane=("${(@s/:/)active_pane}")
188+
189+active_session=${a_active_pane[2]//$}
190+active_window=$a_active_pane[3]
191+active_pane=$a_active_pane[4]
192+
193+# set variables for upcoming window
194+tmux setenv -t $active_session:$active_window.$active_pane "ZNT_TMUX_MODE" 1
195+tmux setenv -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_SESSION" "$active_session"
196+tmux setenv -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_WINDOW" "$active_window"
197+tmux setenv -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_PANE" "$active_pane"
198+
199+# create a new window in the active session and call it znt-hist
200+tmux new-window -t $active_session: -n znt-hist
201+
202+# unset the variables, so only above single window has them
203+tmux setenv -u -t $active_session:$active_window.$active_pane "ZNT_TMUX_MODE"
204+tmux setenv -u -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_SESSION"
205+tmux setenv -u -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_WINDOW"
206+tmux setenv -u -t $active_session:$active_window.$active_pane "ZNT_TMUX_ORIGIN_PANE"
207+
208+# znt's session id
209+znt_active_pane=$(tmux display -p -F ':#{session_id}:#I:#P:#{pane_active}:#{window_active}:#{session_attached}' )
210+znt_a_active_pane=("${(@s/:/)znt_active_pane}")
211+
212+znt_active_session=${znt_a_active_pane[2]//$}
213+znt_active_window=$znt_a_active_pane[3]
214+znt_active_pane=$znt_a_active_pane[4]
215+
216+# call znt
217+tmux send -t "$znt_active_session:$znt_active_window.$znt_active_pane" n-history ENTER
218diff --git a/plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh b/plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh
219index b2654915202a385ff3cdf77576a87b4c04fb298d..32b4ca0647f764bf674676df01a2df6ab5941928 100755
220--- a/plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh
221+++ b/plugins/zsh-navigation-tools/zsh-navigation-tools.plugin.zsh
222@@ -1,38 +1,43 @@
223 #!/usr/bin/env zsh
224 
225-REPO_DIR="${0%/*}"
226-CONFIG_DIR="$HOME/.config/znt"
227+0="${(%):-%N}" # this gives immunity to functionargzero being unset
228+export ZNT_REPO_DIR="${0%/*}"
229+export ZNT_CONFIG_DIR="$HOME/.config/znt"
230 
231 #
232 # Copy configs
233 #
234 
235-if ! test -d "$HOME/.config"; then
236-    mkdir "$HOME/.config"
237+if [[ ! -d "$HOME/.config" ]]; then
238+    command mkdir "$HOME/.config"
239 fi
240 
241-if ! test -d "$CONFIG_DIR"; then
242-    mkdir "$CONFIG_DIR"
243+if [[ ! -d "$ZNT_CONFIG_DIR" ]]; then
244+    command mkdir "$ZNT_CONFIG_DIR"
245 fi
246 
247 # 9 files
248-set n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
249+unset __ZNT_CONFIG_FILES
250+typeset -ga __ZNT_CONFIG_FILES
251+set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
252 
253 # Check for random 2 files if they exist
254 # This will shift 0 - 7 elements
255-shift $(( RANDOM % 8 ))
256-if ! test -f "$CONFIG_DIR/$1" || ! test -f "$CONFIG_DIR/$2"; then
257+shift $(( RANDOM % 8 )) __ZNT_CONFIG_FILES
258+if [[ ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[1]}" || ! -f "$ZNT_CONFIG_DIR/${__ZNT_CONFIG_FILES[2]}" ]]; then
259     # Something changed - examine every file
260-    set n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
261-    for i; do
262-        if ! test -f "$CONFIG_DIR/$i"; then
263-            cp "$REPO_DIR/.config/znt/$i" "$CONFIG_DIR"
264+    set +A __ZNT_CONFIG_FILES n-aliases.conf n-env.conf n-history.conf n-list.conf n-panelize.conf n-cd.conf n-functions.conf n-kill.conf n-options.conf
265+    unset __ZNT_CONFIG_FILE
266+    typeset -g __ZNT_CONFIG_FILE
267+    for __ZNT_CONFIG_FILE in "${__ZNT_CONFIG_FILES[@]}"; do
268+        if [[ ! -f "$ZNT_CONFIG_DIR/$__ZNT_CONFIG_FILE" ]]; then
269+            command cp "$ZNT_REPO_DIR/.config/znt/$__ZNT_CONFIG_FILE" "$ZNT_CONFIG_DIR"
270         fi
271     done
272+    unset __ZNT_CONFIG_FILE
273 fi
274 
275-# Don't leave positional parameters being set
276-set --
277+unset __ZNT_CONFIG_FILES
278 
279 #
280 # Load functions