add exclude functionality

* Exclude dirs listed in the $_Z_EXCLUDE_DIRS array
This commit is contained in:
rupa committed 2013-01-11 12:28:23 -05:00
1 parent dfd4308ae8
commit 8ed575354b
2 files changed
+13

No files matched your search

+6
View File
@@ -55,6 +55,8 @@ Optionally:
Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution.
.br
Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself.
.br
Set \fB$_Z_EXCLUDE_DIRS\fR to an array of directories to exclude.
.br
(These settings should go in .bashrc/.zshrc before the lines added above.)
.br
@@ -120,6 +122,10 @@ variable to maintain its database. In zsh, \fBz\fR appends a function
.P
The environment variable \fB$_Z_NO_PROMPT_COMMAND\fR can be set if you want to
handle \fBPROMPT_COMMAND\fR or \fBprecmd\fR yourself.
.P
The environment variable \fB$_Z_EXCLUDE_DIRS\fR can be set to an array of
directories to exclude from tracking. \fB$HOME\fR is always excluded.
Directories must be full paths without trailing slashes.
.SH FILES
Data is stored in \fB$HOME/.z\fR. This can be overridden by setting the
+7
View File
@@ -12,6 +12,7 @@
# set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).
# set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
# set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
# set $_Z_EXCLUDE_DIRS to an array of directories to exclude.
#
# USE:
# * z foo # cd to most frecent dir matching foo
@@ -34,6 +35,12 @@ _z() {
# $HOME isn't worth matching
[ "$*" = "$HOME" ] && return
# don't track excluded dirs
local exclude
for exclude in "${_Z_EXCLUDE_DIRS[@]}"; do
[ "$*" == "$exclude" ] && return
done
# maintain the file
local tempfile
tempfile="$(mktemp $datafile.XXXXXX)" || return