1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-18 13:49:50 +00:00

Merge pull request #5 from 0xC0FFEE/feature/fix_typos

Feature/fix typos
This commit is contained in:
Linwei
2019-01-18 04:02:25 +08:00
committed by GitHub

130
README.md
View File

@@ -2,7 +2,7 @@
z - a better method to change directory.
An alternative to [z.sh](https://github.com/rupa/z) with windows and posix shells support and various improvements.
An alternative to [z.sh](https://github.com/rupa/z) with windows and posix shells support and various improvements.
## Description
@@ -19,7 +19,7 @@ For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`.
- Supports Windows cmd (with clink) and cmder
- Self contained, no dependence on awk/gawk
- Compatible with lua 5.1, 5.2 and 5.3+
- New "$_ZL_ADD_ONCE" to allow updating database only if `$PWD` changed.
- New "$_ZL_ADD_ONCE" to allow updating database only if `$PWD` changed.
- Enhanced matching mode with "$_ZL_MATCH_MODE" set to 1.
@@ -39,33 +39,33 @@ z -i foo # cd with interactive selection
## Install
- bash:
put something like this in your `.bashrc`:
eval "$(lua /path/to/z.lua --init bash)"
- zsh:
put something like this in your `.zshrc`:
eval "$(lua /path/to/z.lua --init zsh)"
- posix shells:
- bash:
put something like this in your `.bashrc`:
eval "$(lua /path/to/z.lua --init bash)"
- zsh:
put something like this in your `.zshrc`:
eval "$(lua /path/to/z.lua --init zsh)"
- posix shells:
put something like this in your `.profile`:
eval "$(lua /path/to/z.lua --init posix)"
(sh, ash, dash and busybox have been tested)
- Windows (with clink):
- Windows (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:
- Windows cmder:
- copy z.lua and z.cmd to cmder/vendor
- Add cmder/vendor to `%PATH%`
@@ -77,21 +77,21 @@ z -i foo # cd with interactive selection
- set `$_ZL_CMD` in .bashrc/.zshrc to change the command (default z).
- set `$_ZL_DATA` in .bashrc/.zshrc to change the datafile (default ~/.zlua).
- set `$_ZL_NO_PROMPT_COMMAND` if you're handling PROMPT_COMMAND yourself.
- set `$_ZL_EXCLUDE_DIRS` to an array of directories to exclude.
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed.
- set `$_ZL_MAXAGE` to define a aging threshold (default is 5000).
- set `$_ZL_EXCLUDE_DIRS` to an array of directories to exclude.
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed.
- set `$_ZL_MAXAGE` to define a aging threshold (default is 5000).
- set `$_ZL_CD` to specify your own cd command.
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
- set `$_ZL_MATCHMODE` to 1 to enable enhanced matching.
## Aging
he rank of directories maintained by z.lua 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 5000 (`$_ZL_MAXAGE`), all ranks are multiplied by 0.9. Entries with a rank lower than 1 are forgotten.
The rank of directories maintained by z.lua 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 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.
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.
@@ -101,27 +101,27 @@ To z.lua, a directory that has low ranking but has been accessed recently will q
z.lua has two different matching methods: 0 for default, 1 for enhanced:
### Default matching
By default, z.lua uses default matching method similar to the original z.sh. Paths must be match all of the regexes in order.
- cd to a directory contains foo:
j foo
- cd to a directory ends with foo:
j foo$
- use multiple arguments:
Assuming the following database:
30 /home/user/mail/inbox
10 /home/user/work/inbox
`"z in"` would cd into `/home/user/mail/inbox` as 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`.
### Default matching
By default, z.lua uses default matching method similar to the original z.sh. Paths must be match all of the regexes in order.
- cd to a directory contains foo:
j foo
- cd to a directory ends with foo:
j foo$
- use multiple arguments:
Assuming the following database:
30 /home/user/mail/inbox
10 /home/user/work/inbox
`"z in"` would cd into `/home/user/mail/inbox` as 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`.
### Enhanced matching
Enhanced matching can be enabled by export the environment:
@@ -129,16 +129,16 @@ Enhanced matching can be enabled by export the environment:
export _ZL_MATCH_MODE=1
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:
1. Queries match the path in order (same as default method).
2. 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:
- match the last segment of the path:
Assuming the following database:
10 /home/user/workspace
20 /home/user/workspace/project1
30 /home/user/workspace/project2
@@ -148,13 +148,13 @@ If no match is found, it will fall back to default matching method.
Since the last segment of a path is always easier to be recalled, it is sane to give it higher priority. You can also achieve this by typing `"z space$"` in both methods, but `"z wo"` is easier to type.
- cd to the existent path if there is no match:
- cd to the existent path if there is no match:
Sometimes if you use:
z foo
And there is no mathing result in the database, but there is an existent directory which can be accessed with the name "foo" from current directory, "`z foo`" will just work as:
And there is no matching result in the database, but there is an existent directory which can be accessed with the name "foo" from current directory, "`z foo`" will just work as:
cd foo
@@ -167,7 +167,7 @@ If no match is found, it will fall back to default matching method.
10 /Users/Great_Wall/.rbenv/versions/2.4.1/lib/ruby/gems
20 /Library/Ruby/Gems/2.0.0/gems
When I use `z gems` by default, it will take me to `/Library/Ruby/Gems/2.0.0/gems`, but it's not what I want, so I press up arrow and execute `z gems` again, it will take me to `/Users/Great_Wall/.rbenv/versions/2.4.1/lib/ruby/gems` and this what I want.
When I use `z gems` by default, it will take me to `/Library/Ruby/Gems/2.0.0/gems`, but it's not what I want, so I press up arrow and execute `z gems` again, it will take me to `/Users/Great_Wall/.rbenv/versions/2.4.1/lib/ruby/gems` and this what I want.
Of course I can always use `z env gems` to indicate what I want precisely. Skip the current directory means when you use `z xxx` you always want to change directory instead of stay in the same directory and do nothing if current directory is the best match.
@@ -176,7 +176,7 @@ The default matching method is designed to be compatible with original z.sh, but
## Add once
By default, z.lua will add current directory to database each time before display command prompt (correspond with z.sh). But there is an option to allow z.lua add path only if current working directory changed.
By default, z.lua will add current directory to database each time before display command prompt (correspond with z.sh). But there is an option to allow z.lua add path only if current working directory changed.
To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can init z.lua on linux like this:
@@ -190,7 +190,7 @@ It could be much faster on slow hardware or Cygwin/MSYS.
## Tips
Recommanded aliases you may find useful:
Recommended aliases you may find useful:
```bash
alias zc='z -c' # restrict matches to subdirs of $PWD
@@ -236,13 +236,13 @@ As you see, z.lua is the fastest one and requires less resource.
## Credit
Releated projects:
Related projects:
- [rupa/z](https://github.com/rupa/z): origin z.sh implementation
- [JannesMeyer/z.ps](https://github.com/JannesMeyer/z.ps): z for powershell
## License
Licensed under MIT license.
- [rupa/z](https://github.com/rupa/z): origin z.sh implementation
- [JannesMeyer/z.ps](https://github.com/JannesMeyer/z.ps): z for powershell
## License
Licensed under MIT license.