0744acd663216b8e1c0c75878c166d53684d75bc

Author
Jim Hester <james.f.hester@gmail.com>
Committer
Jim Hester <james.f.hester@gmail.com>
Date

Message

Update to latest per-directory-history

See [https://github.com/jimhester/per-directory-history]

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/per-directory-history/README.md b/plugins/per-directory-history/README.md
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..d8ff93dc0f18dd0e9cbccbe23d91fde6ded9f254
  4--- /dev/null
  5+++ b/plugins/per-directory-history/README.md
  6@@ -0,0 +1,56 @@
  7+[Per-Directory-History][6]
  8+=========================
  9+
 10+Per directory history for zsh, as well as global history, and the
 11+ability to toggle between them with ^G.
 12+
 13+This is a implementation of per directory history for zsh, some 
 14+implementations of which exist in bash[1][],[2][].  It also implements 
 15+a per-directory-history-toggle-history function to change from using the 
 16+directory history to using the global history.  In both cases the history is 
 17+always saved to both the global history and the directory history, so the 
 18+toggle state will not effect the saved histories.  Being able to switch 
 19+between global and directory histories on the fly is a novel feature as far 
 20+as I am aware.
 21+
 22+This is a standalone repository for the script, however it is also included in
 23+[oh-my-zsh][4] as a plugin.
 24+
 25+----------------------------------------------------------------------------
 26+Usage
 27+----------------------------------------------------------------------------
 28+
 29+1.  Load this script into your interactive ZSH session:
 30+
 31+        % source zsh-per-directory-history.zsh
 32+
 33+2.  The default mode if per directory history, interact with your history as normal.
 34+
 35+3.  Press ^G (the Control and G keys simultaneously) to toggle between local
 36+    and global histories. 
 37+
 38+
 39+
 40+-------------------------------------------------------------------------------
 41+Configuration
 42+-------------------------------------------------------------------------------
 43+
 44+* HISTORY_BASE a global variable that defines the base directory in which the 
 45+  directory histories are stored
 46+* per-directory-history-toggle-history is the function to toggle the history
 47+
 48+-------------------------------------------------------------------------------
 49+History
 50+-------------------------------------------------------------------------------
 51+
 52+The idea/inspiration for a per directory history is from [Stewart MacArthur][1] 
 53+and [Dieter][2], the implementation idea is from [Bart Schaefer][3].  The 
 54+implementation is by [Jim Hester][5] in September 2012.
 55+
 56+[1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
 57+[2]: http://dieter.plaetinck.be/per_directory_bash
 58+[3]: http://www.zsh.org/mla/users/1997/msg00226.html
 59+[4]: https://github.com/robbyrussell/oh-my-zsh
 60+[5]: http://jimhester.com
 61+[6]: http://github.com/jimhester/per-directory-history
 62+
 63diff --git a/plugins/per-directory-history/per-directory-history.plugin.zsh b/plugins/per-directory-history/per-directory-history.plugin.zsh
 64deleted file mode 100644
 65index 61e8b5a62753d7d4af5772115203d32acff1e743..0000000000000000000000000000000000000000
 66--- a/plugins/per-directory-history/per-directory-history.plugin.zsh
 67+++ /dev/null
 68@@ -1,149 +0,0 @@
 69-#!/usr/bin/env zsh
 70-#
 71-# This is a implementation of per directory history for zsh, some 
 72-# implementations of which exist in bash[1,2].  It also implements 
 73-# a per-directory-history-toggle-history function to change from using the 
 74-# directory history to using the global history.  In both cases the history is 
 75-# always saved to both the global history and the directory history, so the 
 76-# toggle state will not effect the saved histories.  Being able to switch 
 77-# between global and directory histories on the fly is a novel feature as far 
 78-# as I am aware.
 79-#
 80-#-------------------------------------------------------------------------------
 81-# Configuration
 82-#-------------------------------------------------------------------------------
 83-#
 84-# HISTORY_BASE a global variable that defines the base directory in which the 
 85-# directory histories are stored
 86-#
 87-#-------------------------------------------------------------------------------
 88-# History
 89-#-------------------------------------------------------------------------------
 90-#
 91-# The idea/inspiration for a per directory history is from Stewart MacArthur[1] 
 92-# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh 
 93-# mailing list[3].  The implementation is by Jim Hester in September 2012.
 94-#
 95-# [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
 96-# [2]: http://dieter.plaetinck.be/per_directory_bash
 97-# [3]: http://www.zsh.org/mla/users/1997/msg00226.html
 98-#
 99-################################################################################
100-#
101-# Copyright (c) 2012 Jim Hester
102-#
103-# This software is provided 'as-is', without any express or implied warranty.  
104-# In no event will the authors be held liable for any damages arising from the 
105-# use of this software.
106-#
107-# Permission is granted to anyone to use this software for any purpose, 
108-# including commercial applications, and to alter it and redistribute it 
109-# freely, subject to the following restrictions:
110-#
111-# 1. The origin of this software must not be misrepresented; you must not claim 
112-# that you wrote the original software. If you use this software in a product, 
113-# an acknowledgment in the product documentation would be appreciated but is 
114-# not required.
115-#
116-# 2. Altered source versions must be plainly marked as such, and must not be 
117-# misrepresented as being the original software.
118-#
119-# 3. This notice may not be removed or altered from any source distribution..
120-#
121-################################################################################
122-
123-#-------------------------------------------------------------------------------
124-# configuration, the base under which the directory histories are stored
125-#-------------------------------------------------------------------------------
126-
127-[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
128-
129-#-------------------------------------------------------------------------------
130-# toggle global/directory history used for searching - ctrl-G by default
131-#-------------------------------------------------------------------------------
132-
133-function per-directory-history-toggle-history() {
134-  if [[ $_per_directory_history_is_global == true ]]; then
135-    _per-directory-history-set-directory-history
136-    print "\nusing local history\n"
137-  else
138-    _per-directory-history-set-global-history
139-    print "\nusing global history\n"
140-  fi
141-  zle .push-line
142-  zle .accept-line
143-}
144-
145-autoload per-directory-history-toggle-history
146-zle -N per-directory-history-toggle-history
147-bindkey '^G' per-directory-history-toggle-history
148-
149-#-------------------------------------------------------------------------------
150-# implementation details
151-#-------------------------------------------------------------------------------
152-
153-_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
154-
155-function _per-directory-history-change-directory() {
156-  _per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
157-  mkdir -p ${_per_directory_history_directory:h}
158-  if [[ $_per_directory_history_is_global == false ]]; then
159-    #save to the global history
160-    fc -AI $HISTFILE
161-    #save history to previous file
162-    local prev="$HISTORY_BASE${OLDPWD:A}/history"
163-    mkdir -p ${prev:h}
164-    fc -AI $prev
165-
166-    #discard previous directory's history
167-    local original_histsize=$HISTSIZE
168diff --git a/plugins/per-directory-history/per-directory-history.plugin.zsh b/plugins/per-directory-history/per-directory-history.plugin.zsh
169new file mode 120000
170index 0000000000000000000000000000000000000000..142d9541dca5c72510ce02b806335451cdd8eea6
171--- /dev/null
172+++ b/plugins/per-directory-history/per-directory-history.plugin.zsh
173@@ -0,0 +1 @@
174+per-directory-history.zsh
175diff --git a/plugins/per-directory-history/per-directory-history.zsh b/plugins/per-directory-history/per-directory-history.zsh
176new file mode 100644
177index 0000000000000000000000000000000000000000..d500090803d142dc8d090f39627e1570419d803d
178--- /dev/null
179+++ b/plugins/per-directory-history/per-directory-history.zsh
180@@ -0,0 +1,149 @@
181+#!/usr/bin/env zsh
182+#
183+# This is a implementation of per directory history for zsh, some 
184+# implementations of which exist in bash[1,2].  It also implements 
185+# a per-directory-history-toggle-history function to change from using the 
186+# directory history to using the global history.  In both cases the history is 
187+# always saved to both the global history and the directory history, so the 
188+# toggle state will not effect the saved histories.  Being able to switch 
189+# between global and directory histories on the fly is a novel feature as far 
190+# as I am aware.
191+#
192+#-------------------------------------------------------------------------------
193+# Configuration
194+#-------------------------------------------------------------------------------
195+#
196+# HISTORY_BASE a global variable that defines the base directory in which the 
197+# directory histories are stored
198+#
199+#-------------------------------------------------------------------------------
200+# History
201+#-------------------------------------------------------------------------------
202+#
203+# The idea/inspiration for a per directory history is from Stewart MacArthur[1] 
204+# and Dieter[2], the implementation idea is from Bart Schaefer on the the zsh 
205+# mailing list[3].  The implementation is by Jim Hester in September 2012.
206+#
207+# [1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
208+# [2]: http://dieter.plaetinck.be/per_directory_bash
209+# [3]: http://www.zsh.org/mla/users/1997/msg00226.html
210+#
211+################################################################################
212+#
213+# Copyright (c) 2012 Jim Hester
214+#
215+# This software is provided 'as-is', without any express or implied warranty.  
216+# In no event will the authors be held liable for any damages arising from the 
217+# use of this software.
218+#
219+# Permission is granted to anyone to use this software for any purpose, 
220+# including commercial applications, and to alter it and redistribute it 
221+# freely, subject to the following restrictions:
222+#
223+# 1. The origin of this software must not be misrepresented; you must not claim 
224+# that you wrote the original software. If you use this software in a product, 
225+# an acknowledgment in the product documentation would be appreciated but is 
226+# not required.
227+#
228+# 2. Altered source versions must be plainly marked as such, and must not be 
229+# misrepresented as being the original software.
230+#
231+# 3. This notice may not be removed or altered from any source distribution..
232+#
233+################################################################################
234+
235+#-------------------------------------------------------------------------------
236+# configuration, the base under which the directory histories are stored
237+#-------------------------------------------------------------------------------
238+
239+[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
240+
241+#-------------------------------------------------------------------------------
242+# toggle global/directory history used for searching - ctrl-G by default
243+#-------------------------------------------------------------------------------
244+
245+function per-directory-history-toggle-history() {
246+  if [[ $_per_directory_history_is_global == true ]]; then
247+    _per-directory-history-set-directory-history
248+    print -n "\nusing local history"
249+  else
250+    _per-directory-history-set-global-history
251+    print -n "\nusing global history"
252+  fi
253+  zle .push-line
254+  zle .accept-line
255+}
256+
257+autoload per-directory-history-toggle-history
258+zle -N per-directory-history-toggle-history
259+bindkey '^G' per-directory-history-toggle-history
260+
261+#-------------------------------------------------------------------------------
262+# implementation details
263+#-------------------------------------------------------------------------------
264+
265+_per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
266+
267+function _per-directory-history-change-directory() {
268+  _per_directory_history_directory="$HISTORY_BASE${PWD:A}/history"
269+  mkdir -p ${_per_directory_history_directory:h}
270+  if [[ $_per_directory_history_is_global == false ]]; then
271+    #save to the global history
272+    fc -AI $HISTFILE
273+    #save history to previous file
274+    local prev="$HISTORY_BASE${OLDPWD:A}/history"
275+    mkdir -p ${prev:h}
276+    fc -AI $prev
277+
278+    #discard previous directory's history
279+    local original_histsize=$HISTSIZE