summaryrefslogtreecommitdiff
path: root/plugins/per-directory-history
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/per-directory-history')
-rw-r--r--plugins/per-directory-history/README.md76
-rw-r--r--plugins/per-directory-history/per-directory-history.zsh19
2 files changed, 47 insertions, 48 deletions
diff --git a/plugins/per-directory-history/README.md b/plugins/per-directory-history/README.md
index d8ff93dc0..69854aa38 100644
--- a/plugins/per-directory-history/README.md
+++ b/plugins/per-directory-history/README.md
@@ -1,56 +1,48 @@
-[Per-Directory-History][6]
-=========================
+per-directory-history plugin
+----------------------------
-Per directory history for zsh, as well as global history, and the
-ability to toggle between them with ^G.
+This plugin adds per-directory history for zsh, as well as a global history,
+and the ability to toggle between them with a keyboard shortcut. This is a
+bundle of the [official plugin by @jimhester][5].
-This is a implementation of per directory history for zsh, some
-implementations of which exist in bash[1][],[2][]. It also implements
-a per-directory-history-toggle-history function to change from using the
-directory history to using the global history. In both cases the history is
-always saved to both the global history and the directory history, so the
-toggle state will not effect the saved histories. Being able to switch
-between global and directory histories on the fly is a novel feature as far
-as I am aware.
+To use it, add `per-directory-history` to the plugins array in your zshrc file:
-This is a standalone repository for the script, however it is also included in
-[oh-my-zsh][4] as a plugin.
+```zsh
+plugins=(... per-directory-history)
+```
-----------------------------------------------------------------------------
-Usage
-----------------------------------------------------------------------------
+This is an implementation of per-directory history for zsh, some implementations
+of which exist in bash[1][],[2][]. It also implements a toggle-history function
+to change from using the directory history to using the global history. In both
+cases the history is always saved to both the global history and the directory
+history, so the toggle state will not effect the saved histories. Being able to
+switch between global and directory histories on the fly is a novel feature.
-1. Load this script into your interactive ZSH session:
+## Usage
- % source zsh-per-directory-history.zsh
+The default mode is per directory history, interact with your history as normal.
-2. The default mode if per directory history, interact with your history as normal.
+Press ^G (the <kbd>Control</kbd> and <kbd>G</kbd> keys simultaneously) to toggle
+between local and global histories. If you would prefer a different shortcut to
+toggle set the `PER_DIRECTORY_HISTORY_TOGGLE` environment variable.
-3. Press ^G (the Control and G keys simultaneously) to toggle between local
- and global histories.
+## Configuration
+* `HISTORY_BASE` is a global variable that defines the base directory in which the
+ directory histories are stored (default `$HOME/.directory_history`).
+* `per-directory-history-toggle-history` is the function to toggle between local
+ and global histories.
+* `PER_DIRECTORY_HISTORY_TOGGLE` is the key binding used to run the toggle-history
+ function above (default `^G`)
+## History
--------------------------------------------------------------------------------
-Configuration
--------------------------------------------------------------------------------
-
-* HISTORY_BASE a global variable that defines the base directory in which the
- directory histories are stored
-* per-directory-history-toggle-history is the function to toggle the history
-
--------------------------------------------------------------------------------
-History
--------------------------------------------------------------------------------
-
-The idea/inspiration for a per directory history is from [Stewart MacArthur][1]
-and [Dieter][2], the implementation idea is from [Bart Schaefer][3]. The
-implementation is by [Jim Hester][5] in September 2012.
+The idea/inspiration for a per directory history is from [Stewart MacArthur][1]
+and [Dieter][2], the implementation idea is from [Bart Schaefer][3]. The
+implementation is by [Jim Hester][4] in September 2012.
[1]: http://www.compbiome.com/2010/07/bash-per-directory-bash-history.html
[2]: http://dieter.plaetinck.be/per_directory_bash
-[3]: http://www.zsh.org/mla/users/1997/msg00226.html
-[4]: https://github.com/robbyrussell/oh-my-zsh
-[5]: http://jimhester.com
-[6]: http://github.com/jimhester/per-directory-history
-
+[3]: https://www.zsh.org/mla/users/1997/msg00226.html
+[4]: https://jimhester.com
+[5]: https://github.com/jimhester/per-directory-history
diff --git a/plugins/per-directory-history/per-directory-history.zsh b/plugins/per-directory-history/per-directory-history.zsh
index bdee341bd..41de2f91d 100644
--- a/plugins/per-directory-history/per-directory-history.zsh
+++ b/plugins/per-directory-history/per-directory-history.zsh
@@ -30,7 +30,7 @@
#
################################################################################
#
-# Copyright (c) 2012 Jim Hester
+# Copyright (c) 2014 Jim Hester
#
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
@@ -57,6 +57,7 @@
#-------------------------------------------------------------------------------
[[ -z $HISTORY_BASE ]] && HISTORY_BASE="$HOME/.directory_history"
+[[ -z $PER_DIRECTORY_HISTORY_TOGGLE ]] && PER_DIRECTORY_HISTORY_TOGGLE='^G'
#-------------------------------------------------------------------------------
# toggle global/directory history used for searching - ctrl-G by default
@@ -76,7 +77,7 @@ function per-directory-history-toggle-history() {
autoload per-directory-history-toggle-history
zle -N per-directory-history-toggle-history
-bindkey '^G' per-directory-history-toggle-history
+bindkey $PER_DIRECTORY_HISTORY_TOGGLE per-directory-history-toggle-history
#-------------------------------------------------------------------------------
# implementation details
@@ -108,8 +109,13 @@ function _per-directory-history-change-directory() {
}
function _per-directory-history-addhistory() {
- print -Sr -- ${1%%$'\n'}
- fc -p $_per_directory_history_directory
+ # respect hist_ignore_space
+ if [[ -o hist_ignore_space ]] && [[ "$1" == \ * ]]; then
+ true
+ else
+ print -Sr -- "${1%%$'\n'}"
+ fc -p $_per_directory_history_directory
+ fi
}
@@ -140,8 +146,9 @@ function _per-directory-history-set-global-history() {
#add functions to the exec list for chpwd and zshaddhistory
-chpwd_functions=(${chpwd_functions[@]} "_per-directory-history-change-directory")
-zshaddhistory_functions=(${zshaddhistory_functions[@]} "_per-directory-history-addhistory")
+autoload -U add-zsh-hook
+add-zsh-hook chpwd _per-directory-history-change-directory
+add-zsh-hook zshaddhistory _per-directory-history-addhistory
#start in directory mode
mkdir -p ${_per_directory_history_directory:h}