1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-22 15:49:47 +00:00

18 Commits

Author SHA1 Message Date
Linwei
a3d4f5db68 Merge pull request #138 from FlTr/path-exists-17
path valid if error code 17 by os.rename
2021-05-05 16:41:06 +08:00
TRF2SGM
a991162428 #136 path valid if error code 17 by os.rename 2021-05-03 12:13:34 +02:00
Linwei
8210c56414 Merge pull request #132 from ilyagr/patch-1
Improve Fish installation instructions
2021-03-08 23:16:40 +08:00
Ilya Grigoriev
a01b28a8d3 Fixup #2 2021-03-08 01:26:22 -08:00
Ilya Grigoriev
695533cee1 Fixup 2021-03-08 01:17:50 -08:00
Ilya Grigoriev
58425dad65 Improve Fish installation instructions
Most notably, this adds instructions of changing $_Z_CD.  I think many
`fish` users would find them useful.
See https://github.com/skywind3000/z.lua/pull/131 for more background.

This makes the installation instructions more conventional (`|source` 
instead of `psub`). This also deletes the second (equivalent) set of instructions.
If the warning in that sentence is important, we could add it back, but
it would apply to all the shells, wouldn't it?

Finally, some wording is improved.
2021-03-08 01:15:26 -08:00
Linwei
44a2489ba3 Merge pull request #131 from ilyagr/add_builtin_cd_doc
Add default to docs for $_ZL_CD
2021-03-04 22:28:18 +08:00
Ilya Grigoriev
6e01d4ad52 Add default to docs for $_ZL_CD
I don't know if the default of `builtin cd` is a good one, as opposed to simple `cd`. It took me quite a bit of debugging before I figured out why, on my `fish` shell, changing directories with `z.lua` messed up the `cdh` (cd history) command.

I think the best thing would be to change the default. However, if you have a good reason to stick with it, I thought that documenting this potentially unexpected behavior might help.
2021-03-04 00:56:51 -08:00
skywind3000
c3c15a3ca9 remove redundant comments 2021-02-15 05:13:24 +08:00
skywind3000
cfad8f54ce update doc 2021-02-15 00:06:38 +08:00
skywind3000
501f619f94 improve powershell 7 compatibility 2021-02-15 00:02:23 +08:00
skywind3000
7a8acd469d update z.lua to 1.8.11 2020-12-31 02:11:09 +08:00
skywind3000
52e066aae7 commit new z.lua 2020-12-31 02:05:46 +08:00
skywind3000
e1a44ee9a5 fix: pushd leak in windows cmd 2020-12-31 01:47:18 +08:00
Linwei
9c0eb6cfbc Merge pull request #127 from chrisant996/fixpushd
Fix leaked pushd
2020-12-30 23:01:17 +08:00
Chris Antos
e646d5baa5 A better fix for the final blank line. 2020-12-30 05:00:26 -08:00
Chris Antos
be90b1a528 Match original output.
Originally `z foo` printed a blank line after the command.  My recent
change accidentally changed how CMD interpreted the end of the file such
that CMD stopped printing the blank line.  This change adjusts the end
of the file to once again cause CMD to print a blank line on finish.
2020-12-30 04:50:29 -08:00
Chris Antos
bda94435fc Fix leaked pushd.
`z somedir` uses double `pushd` to tunnel the new path out past the
endlocal that restores the environment state.  But it ended up leaving
a pushd on the dir stack.

This change exploits normal variable expansion to restore the dir stack
to its initial state while still successfully tunneling the new path out
past the endlocal.
2020-12-30 04:42:05 -08:00
4 changed files with 63 additions and 21 deletions

View File

@@ -65,7 +65,12 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
antigen bundle skywind3000/z.lua antigen bundle skywind3000/z.lua
就可以了(主要要放在 antigen apply 语句之前)。 就可以了(主要要放在 antigen apply 语句之前)。
**注意**:使用 WSL-1 的用户,需要安装 `lua-filesystem` 包:
sudo apt-get install lua-filesystem
这是由于 wsl-1 的 [bug](https://github.com/microsoft/WSL/issues/5505) 引起的,使用 lua-filesystem 可以避免该问题。
- Fish Shell: - Fish Shell:
@@ -83,7 +88,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句: 在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句:
iex ($(lua /path/to/z.lua --init powershell) -join "`n") Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink): - Windows cmd (with clink):

View File

@@ -69,13 +69,19 @@ z -b foo # cd to the parent directory starting with foo
and perhaps this: and perhaps this:
export _ZL_ECHO=1 eval "$(lua /path/to/z.lua --init bash enhanced once echo)"
if you want `z.lua` print the new directory after cd. if you want `z.lua` print the new directory after cd.
If you want `fzf` tab completion use: For `fzf` tab completion use:
eval "$(lua /path/to/z.lua --init bash enhanced once fzf)" eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"
**NOTE**: For wsl-1 users, `lua-filesystem` must be installed:
sudo apt-get install lua-filesystem
To avoid a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
- Zsh: - Zsh:
@@ -85,6 +91,8 @@ z -b foo # cd to the parent directory starting with foo
Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh). Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).
**NOTE**: for wsl-1 users, `lua-filesystem` must be installed.
- Posix Shells: - Posix Shells:
put something like this in your `.profile`: put something like this in your `.profile`:
@@ -97,37 +105,45 @@ z -b foo # cd to the parent directory starting with foo
To generate old posix compatible script. To generate old posix compatible script.
- Fish Shell: - Fish Shell (version `2.4.0` or above):
Create `~/.config/fish/conf.d/z.fish` with following code Create `~/.config/fish/conf.d/z.fish` with following code
source (lua /path/to/z.lua --init fish | psub) lua /path/to/z.lua --init fish | source
Fish version `2.4.0` or above is required. If you'd like `z.lua` to cooperate with fish's own [directory history](https://fishshell.com/docs/3.2/index.html#id34), you can put
lua /path/to/z.lua --init fish > ~/.config/fish/conf.d/z.fish set -gx _ZL_CD cd
This is another way to initialize z.lua in fish shell, but remember to regenerate z.fish if z.lua has been updated or moved. into the same file.
- Power Shell: - Power Shell:
put something like this in your `profile.ps1`: put something like this in your `profile.ps1`:
iex ($(lua /path/to/z.lua --init powershell) -join "`n") Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink): - Windows cmd (with clink):
- copy z.lua and z.cmd to clink's home directory - Copy z.lua and z.cmd to clink's home directory
- Add clink's home to `%PATH%` (z.cmd can be called anywhere) - Add clink's home to `%PATH%` (z.cmd can be called anywhere)
- Ensure that "lua" can be called in `%PATH%` - Ensure that "lua" can be called in `%PATH%`
- Windows cmder: - Windows cmder:
- copy z.lua and z.cmd to cmder/vendor - Copy z.lua and z.cmd to cmder/vendor
- Add cmder/vendor to `%PATH%` - Add cmder/vendor to `%PATH%`
- Ensure that "lua" can be called in `%PATH%` - Ensure that "lua" can be called in `%PATH%`
- Windows WSL-1:
Install `lua-filesystem` module before init z.lua:
sudo apt-get install lua-filesystem
This module is required due to a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
## Options ## Options
@@ -137,7 +153,7 @@ z -b foo # cd to the parent directory starting with foo
- set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude. - set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude.
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed. - 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_MAXAGE` to define a aging threshold (default is 5000).
- set `$_ZL_CD` to specify your own cd command. - set `$_ZL_CD` to specify your own cd command (default is `builtin cd` in Unix shells).
- 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_MATCH_MODE` to 1 to enable enhanced matching. - set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean - set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
@@ -252,7 +268,7 @@ To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can
````bash ````bash
eval "$(lua /path/to/z.lua --init bash once)" eval "$(lua /path/to/z.lua --init bash once)"
eval "$(lua /path/to/z.lua --init zsh once)" eval "$(lua /path/to/z.lua --init zsh once)"
source (lua /path/to/z.lua --init fish once | psub) lua /path/to/z.lua --init fish once | source
```` ````
With `add once` mode off (default), z.lua will consider the time you spent in the directory (like z.sh). When this mode is on, consider the times you accessed the directory (like autojump), and that could be much faster on slow hardware. With `add once` mode off (default), z.lua will consider the time you spent in the directory (like z.sh). When this mode is on, consider the times you accessed the directory (like autojump), and that could be much faster on slow hardware.

12
z.cmd
View File

@@ -106,13 +106,23 @@ if /i "%RunMode%"=="-n" (
pushd !NewPath! pushd !NewPath!
pushd !NewPath! pushd !NewPath!
endlocal endlocal
popd goto popdir
) )
) )
) else ( ) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %* call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
) )
goto end
:popdir
rem -- Exploits variable expansion and the pushd stack to set the current
rem -- directory without leaking a pushd.
popd
setlocal
set NewPath=%CD%
endlocal & popd & cd /d "%NewPath%"
:end :end
echo. echo.

23
z.lua
View File

@@ -1,10 +1,10 @@
#! /usr/bin/env lua #! /usr/bin/env lua
--===================================================================== --=====================================================================
-- --
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020 -- z.lua - a cd command that learns, by skywind 2018, 2019, 2020, 2021
-- Licensed under MIT license. -- Licensed under MIT license.
-- --
-- Version 1.8.10, Last Modified: 2020/12/23 16:37 -- Version 1.8.12, Last Modified: 2021/02/15 00:05
-- --
-- * 10x faster than fasd and autojump, 3x faster than z.sh -- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox -- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -49,9 +49,9 @@
-- source (lua /path/to/z.lua --init fish | psub) -- source (lua /path/to/z.lua --init fish | psub)
-- --
-- Power Shell Install: -- Power Shell Install:
--
-- * put something like this in your config file: -- * put something like this in your config file:
-- iex ($(lua /path/to/z.lua --init powershell) -join "`n") -- Invoke-Expression (& {
-- (lua /path/to/z.lua --init powershell) -join "`n" })
-- --
-- Windows Install (with Clink): -- Windows Install (with Clink):
-- * copy z.lua and z.cmd to clink's home directory -- * copy z.lua and z.cmd to clink's home directory
@@ -63,6 +63,10 @@
-- * Add cmder/vendor to %PATH% -- * Add cmder/vendor to %PATH%
-- * Ensure that "lua" can be called in %PATH% -- * Ensure that "lua" can be called in %PATH%
-- --
-- Windows WSL-1:
-- * Install lua-filesystem module before init z.lua:
-- sudo apt-get install lua-filesystem
--
-- Configure (optional): -- Configure (optional):
-- set $_ZL_CMD in .bashrc/.zshrc to change the command (default z). -- 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_DATA in .bashrc/.zshrc to change the datafile (default ~/.zlua).
@@ -576,7 +580,7 @@ function os.path.exists(name)
end end
local ok, err, code = os.rename(name, name) local ok, err, code = os.rename(name, name)
if not ok then if not ok then
if code == 13 then if code == 13 or code == 17 then
return true return true
elseif code == 30 then elseif code == 30 then
local f = io.open(name,"r") local f = io.open(name,"r")
@@ -2548,12 +2552,18 @@ if /i "%RunMode%"=="-n" (
pushd !NewPath! pushd !NewPath!
pushd !NewPath! pushd !NewPath!
endlocal endlocal
popd goto popdir
) )
) )
) else ( ) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %* call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
) )
goto end
:popdir
popd
setlocal
set "NewPath=%CD%"
endlocal & popd & cd /d "%NewPath%"
:end :end
]] ]]
@@ -2737,4 +2747,5 @@ if not pcall(debug.getlocal, 4, 1) then
end end
end end
-- vim: set ts=4 sw=4 tw=0 noet :