.TH "Z" "1" "January 2013" "z" "User Commands" .SH NAME z \- jump around .SH SYNOPSIS z [\-chlrtx] [regex1 regex2 ... regexn] .SH AVAILABILITY bash, zsh .SH DESCRIPTION Tracks your most used directories, based on 'frecency'. .P After a short learning phase, \fBz\fR will take you to the most 'frecent' directory that matches ALL of the regexes given on the command line, in order. For example, \fBz foo bar\fR would match \fB/foo/bar\fR but not \fB/bar/foo\fR. .P If nothing in the jump-list matches, and a single argument was given that names an existing directory, \fBz\fR acts as a \fBcd\fR alias and goes there. See \fBcd Fallback\fR below. .SH OPTIONS .TP \fB\-c\fR restrict matches to subdirectories of the current directory .TP \fB\-e\fR echo the best match, don't cd .TP \fB\-h\fR show a brief help message .TP \fB\-l\fR list only .TP \fB\-r\fR match by rank only .TP \fB\-t\fR match by recent access only .TP \fB\-x\fR remove the current directory from the datafile .SH EXAMPLES .TP 14 \fBz foo\fR cd to most frecent dir matching foo .TP 14 \fBz foo bar\fR cd to most frecent dir matching foo, then bar .TP 14 \fBz -r foo\fR cd to highest ranked dir matching foo .TP 14 \fBz -t foo\fR cd to most recently accessed dir matching foo .TP 14 \fBz -l foo\fR list all dirs matching foo (by frecency) .TP 14 \fBz foo\fR cd to ./foo, if nothing in the jump-list matches foo .TP 14 \fBz ...\fR cd two directories up .SH NOTES .SS Installation: .P Put something like this in your \fB$HOME/.bashrc\fR or \fB$HOME/.zshrc\fR: .RS .P \fB. /path/to/z.sh\fR .RE .P \fBcd\fR around for a while to build up the db. .P PROFIT!! .P Optionally: .RS Set \fB$_Z_CMD\fR to change the command name (default \fBz\fR). .RE .RS Set \fB$_Z_DATA\fR to change the datafile (default \fB$HOME/.z\fR). .RE .RS Set \fB$_Z_MAX_SCORE\fR lower to age entries out faster (default \fB9000\fR). .RE .RS Set \fB$_Z_NO_RESOLVE_SYMLINKS\fR to prevent symlink resolution. .RE .RS Set \fB$_Z_NO_CD_FALLBACK\fR to not cd to unmatched but existing directories. .RE .RS Set \fB$_Z_NO_FZF\fR to complete without \fBfzf\fR even when it is installed. .RE .RS Set \fB$_Z_FZF_PRUNE_DIRS\fR to an array of directory names \fBfzf\fR shouldn't offer. .RE .RS Set \fB$_Z_NO_PROMPT_COMMAND\fR to handle \fBPROMPT_COMMAND/precmd\fR yourself. .RE .RS Set \fB$_Z_EXCLUDE_DIRS\fR to an array of directory trees to exclude. .RE .RS Set \fB$_Z_OWNER\fR to allow usage when in 'sudo -s' mode. .RE .RS (These settings should go in .bashrc/.zshrc before the line added above.) .RE .RS Install the provided man page \fBz.1\fR somewhere in your \fB$MANPATH\fR, with \fBmake install-man\fR, or by hand into a directory such as \fB/usr/local/share/man/man1\fR. Then \fBman z\fR works. .RE .SS Aging: The rank of directories maintained by \fBz\fR undergoes aging based on a simple formula. The rank of each entry is incremented every time it is accessed. When the sum of ranks is over 9000, all ranks are multiplied by 0.99. Entries with a rank lower than 1 are forgotten. .SS Frecency: Frecency is a portmanteau of 'recent' and 'frequency'. It is a weighted rank that depends on how often and how recently something occurred. As far as I know, Mozilla came up with the term. .P To \fBz\fR, a directory that has low ranking but has been accessed recently will quickly have higher rank than a directory accessed frequently a long time ago. .P Frecency is determined at runtime. .SS Common: When multiple directories match all queries, and they all have a common prefix, \fBz\fR will cd to the shortest matching directory, without regard to priority. This has been in effect, if undocumented, for quite some time, but should probably be configurable or reconsidered. .SS Going Up: An argument of nothing but dots walks up the tree, one directory per dot past the first: \fBz ..\fR is the parent, \fBz ...\fR its parent, \fBz ....\fR the one above that. Asking for more levels than there are stops at \fB/\fR. A single \fB.\fR is left alone, since it is a perfectly good regex. .P This is checked before the datafile, because as a regex \fB..\fR matches almost every path in it, and so used to jump somewhere arbitrary. .SS cd Fallback: When no directory in the datafile matches the query, \fBz\fR falls back to behaving like \fBcd\fR: if exactly one argument was given, and it is a path to an existing directory, \fBz\fR cds to it. This makes \fBz\fR usable on directories it has never seen, such as freshly created ones. .P The datafile always takes priority, so a query that matches a known directory jumps there even if a directory of the same name exists in \fB$PWD\fR. The fallback is also skipped for \fB\-l\fR and \fB\-e\fR, and can be disabled entirely by setting \fB$_Z_NO_CD_FALLBACK\fR. .SS Tab Completion: \fBz\fR 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 completed in the shell. .P If \fBfzf\fR(1) is installed, TAB opens it instead of completing in place. The candidates are the whole jump-list, most 'frecent' first, then the subdirectories of \fB$PWD\fR, then its parent and your siblings, so the picker can go up and across as well as down. \fB$PWD\fR itself is left out. Whatever you had typed becomes the starting query, and a single match is taken without drawing the picker at all, so TAB on an unambiguous query stays instant. .P TAB inside the picker looks inside the highlighted directory: the list is replaced by what surrounds that directory, as though you had jumped there and pressed TAB again, and the directory itself is offered first so that return goes where you just looked. The query is cleared, since it has already served its purpose. Press TAB repeatedly to walk down a tree a level at a time. .P In zsh the directory you choose is jumped to immediately: TAB is a widget there, so the jump runs as \fB${_Z_CMD:-z}