Z.lua
:zap: A new cd command that helps you navigate faster by learning your habits.
Install / Use
/learn @skywind3000/Z.luaREADME
z.lua
A command line tool which helps you navigate faster by learning your habits :zap:
An alternative to z.sh with windows and posix shells support and various improvements.
Description
z.lua is a faster way to navigate your filesystem. It 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.
Reputation
From people using z.lua:
- I like this in principal. I’m pretty damn predictable at the command line and far too lazy to make shortcuts
- It feels far more intuitive and it's so incredibly convenient to be able to jump between folders I'm working in without having to traverse an entire tree. The shell used to feel so constraining for me, but tools like this are making me enjoy it so much more.
- I can finally have autojump-like functionality on my Raspberry Pi 1 without waiting 30 seconds every time I open a new shell. Thanks z.lua devs.
- Anyway, z.lua is a promising project. If you only need directory jumping, it may be the best choice.
Features
- 10x times faster than fasd and autojump, 3x times faster than z.sh.
- Gain the ultimate speed with an optional native module written in C.
- Available for posix shells: bash, zsh, dash, sh, ash, ksh, busybox and etc.
- Available for Fish Shell, Nushell, Power Shell and Windows cmd.
- Enhanced matching algorithm takes you to where ever you want precisely.
- Allow updating database only if
$PWDchanged with "$_ZL_ADD_ONCE" set to 1. - Interactive selection enables you to choose where to go before cd.
- Integrated with FZF (optional) for interactive selection and completion.
- Quickly go back to a parent directory instead of typing "cd ../../..".
- Corresponding experience in different shells and operating systems.
- Compatible with Lua (5.1, 5.2, 5.3+) and luajit.
- Self contained, distributed as a single
z.luascript, no other dependence.
Examples
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 the highest ranked dir matching foo
z -t foo # cd to most recently accessed dir matching foo
z -l foo # list matches instead of cd
z -c foo # restrict matches to subdirs of $PWD
z -e foo # echo the best match, don't cd
z -i foo # cd with interactive selection
z -I foo # cd with interactive selection using fzf
z -b foo # cd to the parent directory starting with foo
z -b foo bar # replace foo with bar in cwd and cd there
Install
-
Bash:
put something like this in your
.bashrc:eval "$(lua /path/to/z.lua --init bash)"the default matching algorithm is similar to z.sh to keep compatible, you may like the enhanced matching algorithm for productivity:
eval "$(lua /path/to/z.lua --init bash enhanced once)"and perhaps this:
eval "$(lua /path/to/z.lua --init bash enhanced once echo)"if you want
z.luaprint the new directory after cd.For
fzftab completion use:eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"NixOS users using home-manager can add this to their user profile:
programs.z-lua.enable = true; programs.z-lua.enableBashIntegration = true; programs.z-lua.options = [ "enhanced" "once" "fzf" ]; # modify as neededNOTE: For wsl-1 users,
lua-filesystemmust be installed:sudo apt-get install lua-filesystemTo avoid a wsl-1 defect.
-
Zsh:
put something like this in your
.zshrc:eval "$(lua /path/to/z.lua --init zsh)"Options like "enhanced", "once" and "fzf" can be used after
--inittoo. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).NixOS users using home-manager can add this to their user profile:
programs.z-lua.enable = true; programs.z-lua.enableZshIntegration = true; programs.z-lua.options = [ "enhanced" "once" "fzf" ]; # modify as neededNOTE: for wsl-1 users,
lua-filesystemmust be installed. -
Posix Shells:
put something like this in your
.profile:eval "$(lua /path/to/z.lua --init posix)"For old shells like ksh (Korn Shell), some features are missing, you can try:
eval "$(lua /path/to/z.lua --init posix legacy)"To generate old posix compatible script.
-
Fish Shell (version
2.4.0or above):Create
~/.config/fish/conf.d/z.fishwith following codelua /path/to/z.lua --init fish | sourceIf you'd like
z.luato cooperate with fish's own directory history, you can putset -gx _ZL_CD cdinto the same file.
NixOS users using home-manager can add this to their user profile:
programs.z-lua.enable = true; programs.z-lua.enableFishIntegration = true; programs.z-lua.options = [ "enhanced" "once" "fzf" ]; # modify as needed -
Nushell
Put something like this in your
env.nu:lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nuThen put something like this in your
config.nu:source ~/.cache/zlua.nuNote: Only Nushell v0.96+ is supported
-
Power Shell:
⚠️ WARNING: users of Starship Prompt should add the following command after
starship init.put something like this in your
profile.ps1:Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" }) -
Windows cmd (with clink):
- Copy z.lua and z.cmd to clink's home directory
- Add clink's home to
%PATH%(z.cmd can be called anywhere) - Ensure that "lua" can be called in
%PATH%
-
Windows cmder:
- Copy z.lua and z.cmd to cmder/vendor
- Add cmder/vendor to
%PATH% - Ensure that "lua" can be called in
%PATH%
-
Windows WSL-1:
Install
lua-filesystemmodule before init z.lua:sudo apt-get install lua-filesystemThis module is required due to a wsl-1 defect.
Options
- set
$_ZL_CMDin .bashrc/.zshrc to change the command (default z). - set
$_ZL_DATAin .bashrc/.zshrc to change the datafile (default ~/.zlua). - set
$_ZL_NO_PROMPT_COMMANDif you're handling PROMPT_COMMAND yourself. - set
$_ZL_EXCLUDE_DIRSto a comma separated list of dirs to exclude. - set
$_ZL_ADD_ONCEto '1' to update database only if$PWDchanged. - set
$_ZL_MAXAGEto define a aging threshold (default is 5000). - set
$_ZL_CDto specify your own cd command (default isbuiltin cdin Unix shells). - set
$_ZL_ECHOto 1 to display new directory name after cd. - set
$_ZL_MATCH_MODEto 1 to enable enhanced matching. - set
$_ZL_NO_CHECKto 1 to disable path validation, usez --purgeto clean - set
$_ZL_HYPHENto 0 to treat a hyphen (-) as a lua regexp special character, set$_ZL_HYPHENto 1 to treat a hyphen as a normal character. If$_ZL_HYPHENis not set or if it is set toauto, z.lua tries to treat-as a lua regexp special character first. If there are no matches, z.lua tries again, this time treating-as a normal character. - set
$_ZL_CLINK_PROMPT_PRIORITYchange clink prompt register priority (default 99).
Aging
The rank of directories maintained by z.lua 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 5000 ($_ZL_MAXAGE), all ranks are multiplied by 0.9. 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.lua, 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.
Default Matching
By default, z.lua uses default matching algorithm similar to the original z.sh. Paths must be match all of the regexes in order.
-
cd to a directory contains foo:
z foo -
use multiple arguments:
Assuming the following database:
10 /home/user/work/inbox 30 /home/user/mail/inbox"z in"would cd into/home/user/mail/inboxas the higher weighted entry. However you can pass multiple arguments to z.lua to prefer a different entry. In the above example,"z w in"would then change directory to/home/user/work/inbox. -
use regexes:
z foo$ # cd to a directory ends with foo z %d # cd to a directory that contains a digitUnlike
z.sh,z.luauses the Lua regular expression syntax.
Enhanced Matching
Enhanced matching can be enabled by exporting the environment:
export _ZL_MATCH_MODE=1
Or, append a enhanced after --init xxx:
eval "$(lua /path/to/z.lua --init bash enhanced)"
For a given set of queries (the set of command-line arguments passed to z.lua), a path is a match if and only if:
- Queries match the path in order (same as default method).
- The last query matches the last segment of the path.
If no match is found, it will fall back to default matching method.
-
match the last segment of the path:
Assuming the following database:
10 /home/user/worksp
Related Skills
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
openclaw-plugin-loom
Loom Learning Graph Skill This skill guides agents on how to use the Loom plugin to build and expand a learning graph over time. Purpose - Help users navigate learning paths (e.g., Nix, German)
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
research_rules
Research & Verification Rules Quote Verification Protocol Primary Task "Make sure that the quote is relevant to the chapter and so you we want to make sure that we want to have it identifie
