Skip to content
Browse files

ZSH USERS NOTE BACKWARD COMPATIBILITY WARNING!

* z now handles precmd functionality for zsh, and no longer requires
  it to be set manually. However, this breaks backward compatibility
  with zsh.
  Existing users who use zsh should remove the precmd function they
  added when installing.
* z now respects _Z_NO_RESOLVE_SYMLINKS and _Z_NO_PROMPT_COMMAND
  variables under zsh.
* Documentation updated to reflect changes in installation instructions
  • Loading branch information...
1 parent 175a6d9 commit 138cf7a9edb7e20a4164199ab233666edf4d2a63 @rupa committed Aug 29, 2012
Showing with 64 additions and 72 deletions.
  1. +45 −44 README
  2. +11 −22 z.1
  3. +8 −6 z.sh
View
89 README
@@ -1,77 +1,82 @@
-Z(1) User Commands Z(1)
+*******************************************************************************
+* *
+* ZSH USERS BACKWARD COMPATIBILITY WARNING *
+* *
+* z now handles 'precmd' set up for zsh. Current users using zsh should *
+* remove the precmd function described in the Installation instructions. *
+* *
+* ZSH USERS BACKWARD COMPATIBILITY WARNING *
+* *
+*******************************************************************************
+
+Z(1) User Commands Z(1)
NAME
- z - jump around
+ z jump around
SYNOPSIS
- z [-h] [-l] [-r] [-t] [regex1 regex2 ... regexn]
+ z [h] [l] [r] [t] [regex1 regex2 ... regexn]
AVAILABILITY
bash, zsh
DESCRIPTION
- Tracks your most used directories, based on 'frecency'.
+ Tracks your most used directories, based on frecency.
- After a short learning phase, z will take you to the most 'frecent'
+ After a short learning phase, z will take you to the most frecent
directory that matches ALL of the regexes given on the command line.
OPTIONS
- -h show a brief help message
- -l list only
- -r match by rank only
- -t match by recent access only
+ h show a brief help message
+ l list only
+ r match by rank only
+ t match by recent access only
EXAMPLES
- z foo cd to most frecent dir matching foo
+ z foo cd to most frecent dir matching foo
z foo bar cd to most frecent dir matching foo and bar
- z -r foo cd to highest ranked dir matching foo
- z -t foo cd to most recently accessed dir matching foo
- z -l foo list all dirs matching foo (by frecency)
+ z r foo cd to highest ranked dir matching foo
+ z t foo cd to most recently accessed dir matching foo
+ z l foo list all dirs matching foo (by frecency)
NOTES
Installation:
- Put something like this in your $HOME/.bashrc:
-
- . /path/to/z.sh
-
- Put something like this in your $HOME/.zshrc:
+ Put something like this in your $HOME/.bashrc or $HOME/.zshrc:
- . /path/to/z.sh
- function precmd () {
- _z --add "$(pwd -P)"
- }
+ . /path/to/z.sh
cd around for a while to build up the db.
PROFIT!!
Optionally:
- Set $_Z_CMD in .bashrc/.zshrc to change the command (default z).
- Set $_Z_DATA to change the datafile (default $HOME/.z).
- Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
- Set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.
- (These settings should go before the lines added above.)
- Install the provided man page z.1 somewhere like /usr/local/man/man1.
+ Set $_Z_CMD to change the command name (default z).
+ Set $_Z_DATA to change the datafile (default $HOME/.z).
+ Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
+ Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd yourself.
+ (These settings should go in .bashrc/.zshrc before the lines added
+ above.)
+ Install the provided man page z.1 somewhere like /usr/local/man/man1.
Aging:
The rank of directories maintained by z undergoes aging based on a sim‐
ple formula. The rank of each entry is incremented every time it is
- accessed. When the sum of ranks is greater than 1000, all ranks are
+ accessed. When the sum of ranks is greater than 1000, all ranks are
multiplied by 0.9. Entries with a rank lower than 1 are forgotten.
Frecency:
- Frecency is a portmantaeu of 'recent' and 'frequency'. It is a weighted
+ Frecency is a portmantaeu of recent and frequency. It is a weighted
rank that depends on how often and how recently something occured. As
far as I know, Mozilla came up with the term.
@@ -92,37 +97,33 @@ NOTES
z supports tab completion. After any number of arguments, press TAB to
complete on directories that match each argument. Due to limitations of
- the completion implementations, only the last argument will be com‐
+ the completion implementations, only the last argument will be com‐
pleted in the shell.
- Internally, z decides you've requested a completion if the last argu‐
+ Internally, z decides youve requested a completion if the last argu‐
ment passed is an absolute path to an existing directory. This may
cause unexpected behavior if the last argument to z begins with /.
ENVIRONMENT
A function _z() is defined.
- An alias $_Z_CMD='_z 2>&1' is defined. If not set, $_Z_CMD defaults to
- z.
+ The contents of the variable $_Z_CMD is aliased to _z 2>&1. If not set,
+ $_Z_CMD defaults to z.
The environment variable $_Z_DATA can be used to control the datafile
location. If it is not defined, the location defaults to $HOME/.z.
The environment variable $_Z_NO_RESOLVE_SYMLINKS can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be
- resolved when added to the datafile.
-
- In bash, z uses the PROMPT_COMMAND environment variable to maintain its
- database. Specifically it prepends:
-
- _z --add "$(pwd -P 2>/dev/null)" 2>/dev/null;
+ resolved when added to the datafile..
- to any existing PROMPT_COMMAND. zsh users need to manually set precmd()
- as described in the installation instructions.
+ In bash, z prepends a command to the PROMPT_COMMAND environment vari‐
+ able to maintain its database. In zsh, z appends a function _z_precmd
+ to the precmd_functions array.
The environment variable $_Z_NO_PROMPT_COMMAND can be set if you want
- to handle PROMPT_COMMAND yourself.
+ to handle PROMPT_COMMAND or precmd yourself.
FILES
@@ -139,4 +140,4 @@ SEE ALSO
-z February 2011 Z(1)
+z February 2011 Z(1)
View
33 z.1
@@ -39,31 +39,24 @@ directory that matches ALL of the regexes given on the command line.
\fBInstallation:\fR
.P
-Put something like this in your \fB$HOME/.bashrc\fR:
+Put something like this in your \fB$HOME/.bashrc\fR or \fB$HOME/.zshrc\fR:
.P
\fB. /path/to/z.sh\fR
.P
-Put something like this in your \fB$HOME/.zshrc\fR:
-.P
- \fB. /path/to/z.sh
- function precmd () {
- _z --add "$(pwd -P)"
- }\fR
-.P
\fBcd\fR around for a while to build up the db.
.P
PROFIT!!
.P
Optionally:
- Set \fB$_Z_CMD\fR in .bashrc/.zshrc to change the command (default \fBz\fR).
+ Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR).
.br
Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR).
.br
Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution.
.br
- Set \fB$_Z_NO_PROMPT_COMMAND\fR if you're handling \fBPROMPT_COMMAND\fR yourself.
+ Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself.
.br
- (These settings should go before the lines added above.)
+ (These settings should go in .bashrc/.zshrc before the lines added above.)
.br
Install the provided man page \fBz.1\fR somewhere like \fB/usr/local/man/man1\fB.
.P
@@ -111,26 +104,22 @@ behavior if the last argument to \fBz\fR begins with \fB/\fR.
.SH ENVIRONMENT
A function \fB_z()\fR is defined.
.P
-An alias \fB$_Z_CMD\fR='_z 2>&1' is defined. If not set, \fB$_Z_CMD\fR defaults
-to \fBz\fR.
+The contents of the variable \fB$_Z_CMD\fR is aliased to \fB_z 2>&1\fR. If not
+set, \fB$_Z_CMD\fR defaults to \fBz\fR.
.P
The environment variable \fB$_Z_DATA\fR can be used to control the datafile
location. If it is not defined, the location defaults to \fB$HOME/.z\fR.
.P
The environment variable \fB$_Z_NO_RESOLVE_SYMLINKS\fR can be set to prevent
resolving of symlinks. If it is not set, symbolic links will be resolved when
-added to the datafile.
-.P
-In bash, \fBz\fR uses the \fBPROMPT_COMMAND\fR environment variable to maintain
-its database. Specifically it prepends:
-.P
- \fB_z --add "$(pwd -P 2>/dev/null)" 2>/dev/null;\fR
+added to the datafile..
.P
-to any existing \fBPROMPT_COMMAND\fR. zsh users need to manually set
-\fBprecmd()\fR as described in the installation instructions.
+In bash, \fBz\fR prepends a command to the \fBPROMPT_COMMAND\fR environment
+variable to maintain its database. In zsh, \fBz\fR appends a function
+\fB_z_precmd\fR to the \fBprecmd_functions\fR array.
.P
The environment variable \fB$_Z_NO_PROMPT_COMMAND\fR can be set if you want to
-handle \fRPROMPT_COMMAND\fR yourself.
+handle \fBPROMPT_COMMAND\fR or \fBprecmd\fR yourself.
.SH FILES
Data is stored in \fB$HOME/.z\fR. This can be overridden by setting the
View
14 z.sh
@@ -3,13 +3,8 @@
# maintains a jump-list of the directories you actually use
#
# INSTALL:
-# * put something like this in your .bashrc:
+# * put something like this in your .bashrc/.zshrc:
# . /path/to/z.sh
-# * put something like this in your .zshrc:
-# . /path/to/z.sh
-# function precmd () {
-# _z --add "$(pwd -P)"
-# }
# * cd around for a while to build up the db
# * PROFIT!!
# * optionally:
@@ -191,6 +186,13 @@ if complete &> /dev/null; then
[ $? -gt 0 ] && PROMPT_COMMAND='_z --add "$(pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null;'"$PROMPT_COMMAND"
}
elif compctl &> /dev/null; then
+ [ "$_Z_NO_PROMPT_COMMAND" ] || {
+ # populate directory list, avoid clobbering any other precmds
+ _z_precmd() {
+ _z --add "$(pwd $_Z_RESOLVE_SYMLINKS)"
+ }
+ precmd_functions+=(_z_precmd)
+ }
# zsh tab completion
_z_zsh_tab_completion() {
local compl

0 comments on commit 138cf7a

Please sign in to comment.
Something went wrong with that request. Please try again.