[
  {
    "path": "LICENSE",
    "content": "DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE \n                    Version 2, December 2004 \n\n Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> \n\n Everyone is permitted to copy and distribute verbatim or modified \n copies of this license document, and changing it is allowed as long \n as the name is changed. \n\n            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE \n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION \n\n  0. You just DO WHAT THE FUCK YOU WANT TO.\n"
  },
  {
    "path": "Makefile",
    "content": "readme:\n\t@groff -man -Tascii z.1 | col -bx\n\n.PHONY: readme\n"
  },
  {
    "path": "README",
    "content": "Z(1)                             User Commands                            Z(1)\n\n\n\nNAME\n       z - jump around\n\nSYNOPSIS\n       z [-chlrtx] [regex1 regex2 ... regexn]\n\nAVAILABILITY\n       bash, zsh\n\nDESCRIPTION\n       Tracks your most used directories, based on 'frecency'.\n\n       After  a  short  learning  phase, z will take you to the most 'frecent'\n       directory that matches ALL of the regexes given on the command line, in\n       order.\n\n       For example, z foo bar would match /foo/bar but not /bar/foo.\n\nOPTIONS\n       -c     restrict matches to subdirectories of the current directory\n\n       -e     echo the best match, don't cd\n\n       -h     show a brief help message\n\n       -l     list only\n\n       -r     match by rank only\n\n       -t     match by recent access only\n\n       -x     remove the current directory from the datafile\n\nEXAMPLES\n       z foo         cd to most frecent dir matching foo\n\n       z foo bar     cd to most frecent dir matching foo, then bar\n\n       z -r foo      cd to highest ranked dir matching foo\n\n       z -t foo      cd to most recently accessed dir matching foo\n\n       z -l foo      list all dirs matching foo (by frecency)\n\nNOTES\n   Installation:\n       Put something like this in your $HOME/.bashrc or $HOME/.zshrc:\n\n              . /path/to/z.sh\n\n       cd around for a while to build up the db.\n\n       PROFIT!!\n\n       Optionally:\n              Set $_Z_CMD to change the command name (default z).\n              Set $_Z_DATA to change the datafile (default $HOME/.z).\n              Set  $_Z_MAX_SCORE  lower  to  age  entries  out faster (default\n              9000).\n              Set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.\n              Set $_Z_NO_PROMPT_COMMAND to handle PROMPT_COMMAND/precmd  your-\n              self.\n              Set $_Z_EXCLUDE_DIRS to an array of directory trees to  exclude.\n              Set $_Z_OWNER to allow usage when in 'sudo -s' mode.\n              (These  settings  should  go  in  .bashrc/.zshrc before the line\n              added above.)\n              Install the provided man page z.1  somewhere  in  your  MANPATH,\n              like /usr/local/man/man1.\n\n   Aging:\n       The rank of directories maintained by z undergoes aging based on a sim-\n       ple formula. The rank of each entry is incremented  every  time  it  is\n       accessed.  When the sum of ranks is over 9000, all ranks are multiplied\n       by 0.99. Entries with a rank lower than 1 are forgotten.\n\n   Frecency:\n       Frecency is a portmanteau of 'recent' and 'frequency'. It is a weighted\n       rank  that depends on how often and how recently something occurred. As\n       far as I know, Mozilla came up with the term.\n\n       To z, a directory that has low ranking but has been  accessed  recently\n       will  quickly  have  higher rank than a directory accessed frequently a\n       long time ago.\n\n       Frecency is determined at runtime.\n\n   Common:\n       When multiple directories match all queries, and they all have a common\n       prefix, z will cd to the shortest matching directory, without regard to\n       priority.  This has been in effect, if  undocumented,  for  quite  some\n       time, but should probably be configurable or reconsidered.\n\n   Tab Completion:\n       z  supports tab completion. After any number of arguments, press TAB to\n       complete on directories that match each argument. Due to limitations of\n       the  completion  implementations,  only  the last argument will be com-\n       pleted in the shell.\n\n       Internally, z decides you've requested a completion if the  last  argu-\n       ment  passed  is  an  absolute  path to an existing directory. This may\n       cause unexpected behavior if the last argument to z begins with /.\n\nENVIRONMENT\n       A function _z() is defined.\n\n       The contents of the variable $_Z_CMD is aliased to _z 2>&1. If not set,\n       $_Z_CMD defaults to z.\n\n       The  environment  variable $_Z_DATA can be used to control the datafile\n       location. If it is not defined, the location defaults to $HOME/.z.\n\n       The environment variable $_Z_NO_RESOLVE_SYMLINKS can be set to  prevent\n       resolving  of  symlinks.  If  it  is  not  set,  symbolic links will be\n       resolved when added to the datafile.\n\n       In bash, z appends a command to the PROMPT_COMMAND environment variable\n       to maintain its database. In zsh, z appends a function _z_precmd to the\n       precmd_functions array.\n\n       The environment variable $_Z_NO_PROMPT_COMMAND can be set if  you  want\n       to handle PROMPT_COMMAND or precmd yourself.\n\n       The  environment  variable  $_Z_EXCLUDE_DIRS  can be set to an array of\n       directory trees to exclude from tracking.  $HOME  is  always  excluded.\n       Directories must be full paths without trailing slashes.\n\n       The  environment  variable  $_Z_OWNER  can  be set to your username, to\n       allow usage of z when your sudo environment keeps $HOME set.\n\nFILES\n       Data is stored in $HOME/.z. This  can  be  overridden  by  setting  the\n       $_Z_DATA  environment variable. When initialized, z will raise an error\n       if this path is a directory, and not function correctly.\n\n       A man page (z.1) is provided.\n\nSEE ALSO\n       regex(7), pushd, popd, autojump, cdargs\n\n       Please file bugs at https://github.com/rupa/z/\n\n\n\nz                                January 2013                             Z(1)\n"
  },
  {
    "path": "z.1",
    "content": ".TH \"Z\" \"1\" \"January 2013\" \"z\" \"User Commands\"\n.SH\nNAME\nz \\- jump around\n.SH\nSYNOPSIS\nz [\\-chlrtx] [regex1 regex2 ... regexn]\n.SH\nAVAILABILITY\nbash, zsh\n.SH\nDESCRIPTION\nTracks your most used directories, based on 'frecency'.\n.P\nAfter a short learning phase, \\fBz\\fR will take you to the most 'frecent'\ndirectory that matches ALL of the regexes given on the command line, in order.\n\nFor example, \\fBz foo bar\\fR would match \\fB/foo/bar\\fR but not \\fB/bar/foo\\fR.\n.SH\nOPTIONS\n.TP\n\\fB\\-c\\fR\nrestrict matches to subdirectories of the current directory\n.TP\n\\fB\\-e\\fR\necho the best match, don't cd\n.TP\n\\fB\\-h\\fR\nshow a brief help message\n.TP\n\\fB\\-l\\fR\nlist only\n.TP\n\\fB\\-r\\fR\nmatch by rank only\n.TP\n\\fB\\-t\\fR\nmatch by recent access only\n.TP\n\\fB\\-x\\fR\nremove the current directory from the datafile\n.SH EXAMPLES\n.TP 14\n\\fBz foo\\fR\ncd to most frecent dir matching foo\n.TP 14\n\\fBz foo bar\\fR\ncd to most frecent dir matching foo, then bar\n.TP 14\n\\fBz -r foo\\fR\ncd to highest ranked dir matching foo\n.TP 14\n\\fBz -t foo\\fR\ncd to most recently accessed dir matching foo\n.TP 14\n\\fBz -l foo\\fR\nlist all dirs matching foo (by frecency)\n.SH\nNOTES\n.SS\nInstallation:\n.P\nPut something like this in your \\fB$HOME/.bashrc\\fR or \\fB$HOME/.zshrc\\fR:\n.RS\n.P\n\\fB. /path/to/z.sh\\fR\n.RE\n.P\n\\fBcd\\fR around for a while to build up the db.\n.P\nPROFIT!!\n.P\nOptionally:\n.RS\nSet \\fB$_Z_CMD\\fR to change the command name (default \\fBz\\fR).\n.RE\n.RS\nSet \\fB$_Z_DATA\\fR to change the datafile (default \\fB$HOME/.z\\fR).\n.RE\n.RS\nSet \\fB$_Z_MAX_SCORE\\fR lower to age entries out faster (default \\fB9000\\fR).\n.RE\n.RS\nSet \\fB$_Z_NO_RESOLVE_SYMLINKS\\fR to prevent symlink resolution.\n.RE\n.RS\nSet \\fB$_Z_NO_PROMPT_COMMAND\\fR to handle \\fBPROMPT_COMMAND/precmd\\fR yourself.\n.RE\n.RS\nSet \\fB$_Z_EXCLUDE_DIRS\\fR to an array of directory trees to exclude.\n.RE\n.RS\nSet \\fB$_Z_OWNER\\fR to allow usage when in 'sudo -s' mode.\n.RE\n.RS\n(These settings should go in .bashrc/.zshrc before the line added above.)\n.RE\n.RS\nInstall the provided man page \\fBz.1\\fR somewhere in your \\f$MANPATH, like\n\\fB/usr/local/man/man1\\fR.\n.RE\n.SS\nAging:\nThe rank of directories maintained by \\fBz\\fR undergoes aging based on a simple\nformula. The rank of each entry is incremented every time it is accessed. When\nthe sum of ranks is over 9000, all ranks are multiplied by 0.99. Entries with a\nrank lower than 1 are forgotten.\n.SS\nFrecency:\nFrecency is a portmanteau of 'recent' and 'frequency'. It is a weighted rank\nthat depends on how often and how recently something occurred. As far as I\nknow, Mozilla came up with the term.\n.P\nTo \\fBz\\fR, a directory that has low ranking but has been accessed recently\nwill quickly have higher rank than a directory accessed frequently a long time\nago.\n.P\nFrecency is determined at runtime.\n.SS\nCommon:\nWhen multiple directories match all queries, and they all have a common prefix,\n\\fBz\\fR will cd to the shortest matching directory, without regard to priority.\nThis has been in effect, if undocumented, for quite some time, but should\nprobably be configurable or reconsidered.\n.SS\nTab Completion:\n\\fBz\\fR supports tab completion. After any number of arguments, press TAB to\ncomplete on directories that match each argument. Due to limitations of the\ncompletion implementations, only the last argument will be completed in the\nshell.\n.P\nInternally, \\fBz\\fR decides you've requested a completion if the last argument\npassed is an absolute path to an existing directory. This may cause unexpected\nbehavior if the last argument to \\fBz\\fR begins with \\fB/\\fR.\n.SH\nENVIRONMENT\nA function \\fB_z()\\fR is defined.\n.P\nThe contents of the variable \\fB$_Z_CMD\\fR is aliased to \\fB_z 2>&1\\fR. If not\nset, \\fB$_Z_CMD\\fR defaults to \\fBz\\fR.\n.P\nThe environment variable \\fB$_Z_DATA\\fR can be used to control the datafile\nlocation. If it is not defined, the location defaults to \\fB$HOME/.z\\fR.\n.P\nThe environment variable \\fB$_Z_NO_RESOLVE_SYMLINKS\\fR can be set to prevent\nresolving of symlinks. If it is not set, symbolic links will be resolved when\nadded to the datafile.\n.P\nIn bash, \\fBz\\fR appends a command to the \\fBPROMPT_COMMAND\\fR environment\nvariable to maintain its database. In zsh, \\fBz\\fR appends a function\n\\fB_z_precmd\\fR to the \\fBprecmd_functions\\fR array.\n.P\nThe environment variable \\fB$_Z_NO_PROMPT_COMMAND\\fR can be set if you want to\nhandle \\fBPROMPT_COMMAND\\fR or \\fBprecmd\\fR yourself.\n.P\nThe environment variable \\fB$_Z_EXCLUDE_DIRS\\fR can be set to an array of\ndirectory trees to exclude from tracking. \\fB$HOME\\fR is always excluded.\nDirectories must be full paths without trailing slashes.\n.P\nThe environment variable \\fB$_Z_OWNER\\fR can be set to your username, to\nallow usage of \\fBz\\fR when your sudo environment keeps \\fB$HOME\\fR set.\n.SH\nFILES\nData is stored in \\fB$HOME/.z\\fR. This can be overridden by setting the\n\\fB$_Z_DATA\\fR environment variable. When initialized, \\fBz\\fR will raise an\nerror if this path is a directory, and not function correctly.\n.P\nA man page (\\fBz.1\\fR) is provided.\n.SH\nSEE ALSO\nregex(7), pushd, popd, autojump, cdargs\n.P\nPlease file bugs at https://github.com/rupa/z/\n"
  },
  {
    "path": "z.sh",
    "content": "# Copyright (c) 2009 rupa deadwyler. Licensed under the WTFPL license, Version 2\n\n# maintains a jump-list of the directories you actually use\n#\n# INSTALL:\n#     * put something like this in your .bashrc/.zshrc:\n#         . /path/to/z.sh\n#     * cd around for a while to build up the db\n#     * PROFIT!!\n#     * optionally:\n#         set $_Z_CMD in .bashrc/.zshrc to change the command (default z).\n#         set $_Z_DATA in .bashrc/.zshrc to change the datafile (default ~/.z).\n#         set $_Z_MAX_SCORE lower to age entries out faster (default 9000).\n#         set $_Z_NO_RESOLVE_SYMLINKS to prevent symlink resolution.\n#         set $_Z_NO_PROMPT_COMMAND if you're handling PROMPT_COMMAND yourself.\n#         set $_Z_EXCLUDE_DIRS to an array of directories to exclude.\n#         set $_Z_OWNER to your username if you want use z while sudo with $HOME kept\n#\n# USE:\n#     * z foo     # cd to most frecent dir matching foo\n#     * z foo bar # cd to most frecent dir matching foo and bar\n#     * z -r foo  # cd to highest ranked dir matching foo\n#     * z -t foo  # cd to most recently accessed dir matching foo\n#     * z -l foo  # list matches instead of cd\n#     * z -e foo  # echo the best match, don't cd\n#     * z -c foo  # restrict matches to subdirs of $PWD\n#     * z -x      # remove the current directory from the datafile\n#     * z -h      # show a brief help message\n\n[ -d \"${_Z_DATA:-$HOME/.z}\" ] && {\n    echo \"ERROR: z.sh's datafile (${_Z_DATA:-$HOME/.z}) is a directory.\"\n}\n\n_z() {\n\n    local datafile=\"${_Z_DATA:-$HOME/.z}\"\n\n    # if symlink, dereference\n    [ -h \"$datafile\" ] && datafile=$(readlink \"$datafile\")\n\n    # bail if we don't own ~/.z and $_Z_OWNER not set\n    [ -z \"$_Z_OWNER\" -a -f \"$datafile\" -a ! -O \"$datafile\" ] && return\n\n    _z_dirs () {\n        [ -f \"$datafile\" ] || return\n\n        local line\n        while read line; do\n            # only count directories\n            [ -d \"${line%%\\|*}\" ] && echo \"$line\"\n        done < \"$datafile\"\n        return 0\n    }\n\n    # add entries\n    if [ \"$1\" = \"--add\" ]; then\n        shift\n\n        # $HOME and / aren't worth matching\n        [ \"$*\" = \"$HOME\" -o \"$*\" = '/' ] && return\n\n        # don't track excluded directory trees\n        if [ ${#_Z_EXCLUDE_DIRS[@]} -gt 0 ]; then\n            local exclude\n            for exclude in \"${_Z_EXCLUDE_DIRS[@]}\"; do\n                case \"$*\" in \"$exclude\"*) return;; esac\n            done\n        fi\n\n        # maintain the data file\n        local tempfile=\"$datafile.$RANDOM\"\n        local score=${_Z_MAX_SCORE:-9000}\n        _z_dirs | \\awk -v path=\"$*\" -v now=\"$(\\date +%s)\" -v score=$score -F\"|\" '\n            BEGIN {\n                rank[path] = 1\n                time[path] = now\n            }\n            $2 >= 1 {\n                # drop ranks below 1\n                if( $1 == path ) {\n                    rank[$1] = $2 + 1\n                    time[$1] = now\n                } else {\n                    rank[$1] = $2\n                    time[$1] = $3\n                }\n                count += $2\n            }\n            END {\n                if( count > score ) {\n                    # aging\n                    for( x in rank ) print x \"|\" 0.99*rank[x] \"|\" time[x]\n                } else for( x in rank ) print x \"|\" rank[x] \"|\" time[x]\n            }\n        ' 2>/dev/null >| \"$tempfile\"\n        # do our best to avoid clobbering the datafile in a race condition.\n        if [ $? -ne 0 -a -f \"$datafile\" ]; then\n            \\env rm -f \"$tempfile\"\n        else\n            [ \"$_Z_OWNER\" ] && chown $_Z_OWNER:\"$(id -ng $_Z_OWNER)\" \"$tempfile\"\n            \\env mv -f \"$tempfile\" \"$datafile\" || \\env rm -f \"$tempfile\"\n        fi\n\n    # tab completion\n    elif [ \"$1\" = \"--complete\" -a -s \"$datafile\" ]; then\n        _z_dirs | \\awk -v q=\"$2\" -F\"|\" '\n            BEGIN {\n                q = substr(q, 3)\n                if( q == tolower(q) ) imatch = 1\n                gsub(/ /, \".*\", q)\n            }\n            {\n                if( imatch ) {\n                    if( tolower($1) ~ q ) print $1\n                } else if( $1 ~ q ) print $1\n            }\n        ' 2>/dev/null\n\n    else\n        # list/go\n        local echo fnd last list opt typ\n        while [ \"$1\" ]; do case \"$1\" in\n            --) while [ \"$1\" ]; do shift; fnd=\"$fnd${fnd:+ }$1\";done;;\n            -*) opt=${1:1}; while [ \"$opt\" ]; do case ${opt:0:1} in\n                    c) fnd=\"^$PWD $fnd\";;\n                    e) echo=1;;\n                    h) echo \"${_Z_CMD:-z} [-cehlrtx] args\" >&2; return;;\n                    l) list=1;;\n                    r) typ=\"rank\";;\n                    t) typ=\"recent\";;\n                    x) \\sed -i -e \"\\:^${PWD}|.*:d\" \"$datafile\";;\n                esac; opt=${opt:1}; done;;\n             *) fnd=\"$fnd${fnd:+ }$1\";;\n        esac; last=$1; [ \"$#\" -gt 0 ] && shift; done\n        [ \"$fnd\" -a \"$fnd\" != \"^$PWD \" ] || list=1\n\n        # if we hit enter on a completion just go there\n        case \"$last\" in\n            # completions will always start with /\n            /*) [ -z \"$list\" -a -d \"$last\" ] && builtin cd \"$last\" && return;;\n        esac\n\n        # no file yet\n        [ -f \"$datafile\" ] || return\n\n        local cd\n        cd=\"$( < <( _z_dirs ) \\awk -v t=\"$(\\date +%s)\" -v list=\"$list\" -v typ=\"$typ\" -v q=\"$fnd\" -F\"|\" '\n            function frecent(rank, time) {\n              # relate frequency and time\n              dx = t - time\n              return int(10000 * rank * (3.75/((0.0001 * dx + 1) + 0.25)))\n            }\n            function output(matches, best_match, common) {\n                # list or return the desired directory\n                if( list ) {\n                    if( common ) {\n                        printf \"%-10s %s\\n\", \"common:\", common > \"/dev/stderr\"\n                    }\n                    cmd = \"sort -n >&2\"\n                    for( x in matches ) {\n                        if( matches[x] ) {\n                            printf \"%-10s %s\\n\", matches[x], x | cmd\n                        }\n                    }\n                } else {\n                    if( common && !typ ) best_match = common\n                    print best_match\n                }\n            }\n            function common(matches) {\n                # find the common root of a list of matches, if it exists\n                for( x in matches ) {\n                    if( matches[x] && (!short || length(x) < length(short)) ) {\n                        short = x\n                    }\n                }\n                if( short == \"/\" ) return\n                for( x in matches ) if( matches[x] && index(x, short) != 1 ) {\n                    return\n                }\n                return short\n            }\n            BEGIN {\n                gsub(\" \", \".*\", q)\n                hi_rank = ihi_rank = -9999999999\n            }\n            {\n                if( typ == \"rank\" ) {\n                    rank = $2\n                } else if( typ == \"recent\" ) {\n                    rank = $3 - t\n                } else rank = frecent($2, $3)\n                if( $1 ~ q ) {\n                    matches[$1] = rank\n                } else if( tolower($1) ~ tolower(q) ) imatches[$1] = rank\n                if( matches[$1] && matches[$1] > hi_rank ) {\n                    best_match = $1\n                    hi_rank = matches[$1]\n                } else if( imatches[$1] && imatches[$1] > ihi_rank ) {\n                    ibest_match = $1\n                    ihi_rank = imatches[$1]\n                }\n            }\n            END {\n                # prefer case sensitive\n                if( best_match ) {\n                    output(matches, best_match, common(matches))\n                    exit\n                } else if( ibest_match ) {\n                    output(imatches, ibest_match, common(imatches))\n                    exit\n                }\n                exit(1)\n            }\n        ')\"\n\n        if [ \"$?\" -eq 0 ]; then\n          if [ \"$cd\" ]; then\n            if [ \"$echo\" ]; then echo \"$cd\"; else builtin cd \"$cd\"; fi\n          fi\n        else\n          return $?\n        fi\n    fi\n}\n\nalias ${_Z_CMD:-z}='_z 2>&1'\n\n[ \"$_Z_NO_RESOLVE_SYMLINKS\" ] || _Z_RESOLVE_SYMLINKS=\"-P\"\n\nif type compctl >/dev/null 2>&1; then\n    # zsh\n    [ \"$_Z_NO_PROMPT_COMMAND\" ] || {\n        # populate directory list, avoid clobbering any other precmds.\n        if [ \"$_Z_NO_RESOLVE_SYMLINKS\" ]; then\n            _z_precmd() {\n                (_z --add \"${PWD:a}\" &)\n                : $RANDOM\n            }\n        else\n            _z_precmd() {\n                (_z --add \"${PWD:A}\" &)\n                : $RANDOM\n            }\n        fi\n        [[ -n \"${precmd_functions[(r)_z_precmd]}\" ]] || {\n            precmd_functions[$(($#precmd_functions+1))]=_z_precmd\n        }\n    }\n    _z_zsh_tab_completion() {\n        # tab completion\n        local compl\n        read -l compl\n        reply=(${(f)\"$(_z --complete \"$compl\")\"})\n    }\n    compctl -U -K _z_zsh_tab_completion _z\nelif type complete >/dev/null 2>&1; then\n    # bash\n    # tab completion\n    complete -o filenames -C '_z --complete \"$COMP_LINE\"' ${_Z_CMD:-z}\n    [ \"$_Z_NO_PROMPT_COMMAND\" ] || {\n        # populate directory list. avoid clobbering other PROMPT_COMMANDs.\n        grep \"_z --add\" <<< \"$PROMPT_COMMAND\" >/dev/null || {\n            PROMPT_COMMAND=\"$PROMPT_COMMAND\"$'\\n''(_z --add \"$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)\" 2>/dev/null &);'\n        }\n    }\nfi\n"
  }
]