Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a8e92e0216 | ||
|
|
e2cce39ee4 | ||
|
|
3c88f8d8fa | ||
|
|
786225005c | ||
|
|
481c1774ed | ||
|
|
35e1199eff | ||
|
|
99dbe7b677 | ||
|
|
c88746629b | ||
|
|
336e95b05a | ||
|
|
a3d4f5db68 | ||
|
|
a991162428 | ||
|
|
8210c56414 | ||
|
|
a01b28a8d3 | ||
|
|
695533cee1 | ||
|
|
58425dad65 | ||
|
|
44a2489ba3 | ||
|
|
6e01d4ad52 | ||
|
|
c3c15a3ca9 | ||
|
|
cfad8f54ce | ||
|
|
501f619f94 |
@@ -65,7 +65,12 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
antigen bundle skywind3000/z.lua
|
||||
|
||||
就可以了(主要要放在 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:
|
||||
|
||||
@@ -83,7 +88,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
|
||||
在你 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):
|
||||
|
||||
44
README.md
@@ -35,7 +35,7 @@ From people using z.lua:
|
||||
- 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 and 5.3+
|
||||
- Compatible with Lua (5.1, 5.2, 5.3+) and luajit.
|
||||
- Self contained, distributed as a single `z.lua` script, no other dependence.
|
||||
|
||||
|
||||
@@ -69,13 +69,19 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
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 `fzf` tab completion use:
|
||||
For `fzf` tab completion use:
|
||||
|
||||
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:
|
||||
|
||||
@@ -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).
|
||||
|
||||
**NOTE**: for wsl-1 users, `lua-filesystem` must be installed.
|
||||
|
||||
- Posix Shells:
|
||||
|
||||
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.
|
||||
|
||||
- Fish Shell:
|
||||
- Fish Shell (version `2.4.0` or above):
|
||||
|
||||
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:
|
||||
|
||||
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):
|
||||
|
||||
- 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)
|
||||
- Ensure that "lua" can be called in `%PATH%`
|
||||
|
||||
- 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%`
|
||||
- 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
|
||||
|
||||
@@ -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_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_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_MATCH_MODE` to 1 to enable enhanced matching.
|
||||
- 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
|
||||
eval "$(lua /path/to/z.lua --init bash 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.
|
||||
|
||||
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 9.0 KiB |
BIN
images/fzf.png
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 8.5 KiB |
BIN
images/mru.png
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 10 KiB |
BIN
images/step1.png
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 7.5 KiB |
BIN
images/step2.png
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 5.7 KiB |
BIN
images/step3.png
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 3.6 KiB |
BIN
images/step4.png
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.4 KiB |
@@ -27,6 +27,8 @@ end
|
||||
if test -e $_zlua_dir/z.lua
|
||||
if type -q lua
|
||||
lua $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q luajit
|
||||
luajit $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q lua5.3
|
||||
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q lua5.2
|
||||
|
||||
8
z.cmd
@@ -120,8 +120,12 @@ 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%"
|
||||
set "NewPath=%CD%"
|
||||
set "CDCmd=cd /d"
|
||||
if /i not "%_ZL_CD%"=="" (
|
||||
set "CDCmd=%_ZL_CD%"
|
||||
)
|
||||
endlocal & popd & %CDCmd% "%NewPath%"
|
||||
|
||||
:end
|
||||
echo.
|
||||
|
||||
28
z.lua
@@ -1,10 +1,10 @@
|
||||
#! /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-2022
|
||||
-- Licensed under MIT license.
|
||||
--
|
||||
-- Version 1.8.11, Last Modified: 2020/12/31 02:05
|
||||
-- Version 1.8.15, Last Modified: 2022/03/27 21:38
|
||||
--
|
||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||
@@ -49,9 +49,9 @@
|
||||
-- source (lua /path/to/z.lua --init fish | psub)
|
||||
--
|
||||
-- Power Shell Install:
|
||||
--
|
||||
-- * 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):
|
||||
-- * copy z.lua and z.cmd to clink's home directory
|
||||
@@ -63,6 +63,10 @@
|
||||
-- * Add cmder/vendor to %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):
|
||||
-- set $_ZL_CMD in .bashrc/.zshrc to change the command (default z).
|
||||
-- set $_ZL_DATA in .bashrc/.zshrc to change the datafile (default ~/.zlua).
|
||||
@@ -523,13 +527,16 @@ function os.path.abspath(path)
|
||||
return test
|
||||
end
|
||||
end
|
||||
for _, python in pairs({'python', 'python2', 'python3'}) do
|
||||
for _, python in pairs({'python3', 'python2', 'python'}) do
|
||||
local s = 'sys.stdout.write(os.path.abspath(sys.argv[1]))'
|
||||
local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\''
|
||||
local s = python .. ' ' .. s
|
||||
local test = os.path.which(python)
|
||||
if test ~= nil and test ~= '' then
|
||||
return os.call(s)
|
||||
test = os.call(s)
|
||||
if test ~= nil and test ~= '' then
|
||||
return test
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -576,7 +583,7 @@ function os.path.exists(name)
|
||||
end
|
||||
local ok, err, code = os.rename(name, name)
|
||||
if not ok then
|
||||
if code == 13 then
|
||||
if code == 13 or code == 17 then
|
||||
return true
|
||||
elseif code == 30 then
|
||||
local f = io.open(name,"r")
|
||||
@@ -2559,7 +2566,11 @@ goto end
|
||||
popd
|
||||
setlocal
|
||||
set "NewPath=%CD%"
|
||||
endlocal & popd & cd /d "%NewPath%"
|
||||
set "CDCmd=cd /d"
|
||||
if /i not "%_ZL_CD%"=="" (
|
||||
set "CDCmd=%_ZL_CD%"
|
||||
)
|
||||
endlocal & popd & %CDCmd% "%NewPath%"
|
||||
:end
|
||||
]]
|
||||
|
||||
@@ -2743,4 +2754,5 @@ if not pcall(debug.getlocal, 4, 1) then
|
||||
end
|
||||
end
|
||||
|
||||
-- vim: set ts=4 sw=4 tw=0 noet :
|
||||
|
||||
|
||||
@@ -2,11 +2,14 @@
|
||||
|
||||
ZLUA_SCRIPT="${0:A:h}/z.lua"
|
||||
|
||||
[[ -n "$ZLUA_EXEC" ]] && [[ ! -x "$ZLUA_EXEC" ]] && ZLUA_EXEC=""
|
||||
if [[ -n "$ZLUA_EXEC" ]] && ! which "$ZLUA_EXEC" &>/dev/null; then
|
||||
echo "$ZLUA_EXEC not found"
|
||||
ZLUA_EXEC=""
|
||||
fi
|
||||
|
||||
# search lua executable
|
||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
for lua in lua lua5.3 lua5.2 lua5.1; do
|
||||
for lua in lua luajit lua5.4 lua5.3 lua5.2 lua5.1; do
|
||||
ZLUA_EXEC="$(command -v "$lua")"
|
||||
[[ -n "$ZLUA_EXEC" ]] && break
|
||||
done
|
||||
|
||||