Skip to content
mutdmourPublic
forked from rupa/z

About

z - jump around

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

232 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Z(1)                             User Commands                            Z(1)



NAME
       z - jump around

SYNOPSIS
       z [-chlrtx] [regex1 regex2 ... regexn]

AVAILABILITY
       bash, zsh

DESCRIPTION
       Tracks your most used directories, based on 'frecency'.

       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, in
       order.

       For example, z foo bar would match /foo/bar but not /bar/foo.

       If  nothing  in  the jump-list matches, and a single argument was given
       that names an existing directory, z acts as a cd alias and goes  there.
       See cd Fallback below.

OPTIONS
       -c     restrict matches to subdirectories of the current directory

       -e     echo the best match, don't cd

       -h     show a brief help message

       -l     list only

       -r     match by rank only

       -t     match by recent access only

       -x     remove the current directory from the datafile

EXAMPLES
       z foo         cd to most frecent dir matching foo

       z foo bar     cd to most frecent dir matching foo, then 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 foo         cd to ./foo, if nothing in the jump-list matches foo

       z ...         cd two directories up

NOTES
   Installation:
       Put something like this in your $HOME/.bashrc or $HOME/.zshrc:

              . /path/to/z.sh

       cd around for a while to build up the db.

       PROFIT!!

       Optionally:
              Set $_Z_CMD to change the command name (default z).
              Set $_Z_DATA to change the datafile (default $HOME/.z).
              Set  $_Z_MAX_SCORE  lower  to  age  entries  out faster (default
              9000).
              Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.
              Set  $_Z_NO_CD_FALLBACK  to  not  cd  to unmatched but existing
              directories.
              Set  $_Z_NO_FZF  to complete without fzf even when it is  in-
              stalled.
              Set $_Z_FZF_PRUNE_DIRS to an array of directory names fzf should-
              n't offer.
              Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd  your-
              self.
              Set $_Z_EXCLUDE_DIRS to an array of directory trees to  exclude.
              Set $_Z_OWNER to allow usage when in 'sudo -s' mode.
              (These  settings  should  go  in  .bashrc/.zshrc before the line
              added above.)
              Install the provided man page z.1 somewhere in  your  $MANPATH,
              with  make  install-man,  or by hand into a directory such as
              /usr/local/share/man/man1. Then man z works.

   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 over 9000, all ranks are multiplied
       by 0.99. Entries with a rank lower than 1 are forgotten.

   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.

       To z, 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.

       Frecency is determined at runtime.

   Common:
       When multiple directories match all queries, and they all have a common
       prefix, z 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.

   Going Up:
       An  argument of nothing but dots walks up the tree, one directory per dot
       past the first: z .. is the parent, z ... its parent, z .... the one
       above  that.  Asking for more levels than there are stops at /. A single
       . is left alone, since it is a perfectly good regex.

       This is checked before the datafile, because as a regex .. matches almost
       every path in it, and so used to jump somewhere arbitrary.

   cd Fallback:
       When  no directory in the datafile matches the query, z falls back to be-
       having like cd: if exactly one argument was given, and it is a path to an
       existing  directory,  z  cds  to  it. This makes z usable on directories
       it has never seen, such as freshly created ones.

       The datafile always takes priority, so a query that matches a known  di-
       rectory  jumps there even if a directory of the same name exists in $PWD.
       The fallback is also skipped for -l and -e, and can be disabled entirely
       by setting $_Z_NO_CD_FALLBACK.

   Tab Completion:
       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-
       pleted in the shell.

       If fzf(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 $PWD, then its parent and your siblings, so the picker
       can go up and across as well as down. $PWD 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.

       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.

       In  zsh  the  directory you choose is jumped to immediately: TAB is a
       widget there, so the jump runs as ${_Z_CMD:-z} <dir>, which also puts it
       in your history, and cancelling the picker discards the line the way ^C
       does. bash's readline cannot run a command from a  completion,  so  there
       the choice is inserted on the command line for you to accept with return.

       Only  one  level  either side of the directory being looked at is of-
       fered, so the list stays short and TAB stays instant; depth comes from the
       jump-list, and from pressing TAB. .git, .hg, .svn and node_modules are
       left out, as are any names in $_Z_FZF_PRUNE_DIRS. Appearance and keybind-
       ings come from fzf's own $FZF_DEFAULT_OPTS.  Set $_Z_NO_FZF to complete
       in place instead.

       Internally, z decides you've 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.

       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.

       The  environment  variable  $_Z_NO_CD_FALLBACK can be set to prevent z
       from falling back to cd when the query matches nothing in the datafile.

       The environment variable $_Z_NO_FZF can be set to complete in place even
       when fzf is installed. $_Z_FZF_PRUNE_DIRS can be set to  an  array  of
       directory names to leave out when listing subdirectories; it adds to the
       always-omitted .git, .hg, .svn and node_modules.

       In bash, z appends a command to the PROMPT_COMMAND environment variable
       to maintain its database. In zsh, z appends a function _z_precmd to the
       precmd_functions array.

       In zsh with fzf installed, z binds TAB to a zle widget, _z_zsh_tab_wid-
       get, so that picking a directory can run the jump instead of only typing
       it  out.  The widget hands TAB straight to whatever it was bound to be-
       fore for every line that isn't a z command, so other completions are un-
       touched; with $_Z_NO_FZF set at the time z.sh is sourced, TAB is left
       alone entirely.

       In  zsh,  z registers its completion with compctl and, when the newer
       completion system is loaded, with compdef as well. The latter is required:
       compinit ignores compctl, and completes the alias by expanding it to _z,
       which zsh's own _compadd claims for every _* command. If compinit has not
       run  by the time z.sh is sourced, the compdef call is retried once from
       precmd_functions; with $_Z_NO_PROMPT_COMMAND set there is no retry, so
       source z.sh after compinit.

       The environment variable $_Z_NO_PROMPT_COMMAND can be set if  you  want
       to handle PROMPT_COMMAND or precmd yourself.

       The  environment  variable  $_Z_EXCLUDE_DIRS  can be set to an array of
       directory trees to exclude from tracking.  $HOME  is  always  excluded.
       Directories must be full paths without trailing slashes.

       The  environment  variable  $_Z_OWNER  can  be set to your username, to
       allow usage of z when your sudo environment keeps $HOME set.

FILES
       Data is stored in $HOME/.z. This  can  be  overridden  by  setting  the
       $_Z_DATA  environment variable. When initialized, z will raise an error
       if this path is a directory, and not function correctly.

       A man page (z.1) is provided.

SEE ALSO
       regex(7), fzf(1), pushd, popd, autojump, cdargs

       Please file bugs at https://github.com/rupa/z/



z                                January 2013                             Z(1)

About

z - jump around

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages