mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-24 08:39:49 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c1c73af33 | ||
|
|
b63a38b11a | ||
|
|
c524e28851 | ||
|
|
c3a182c6c9 | ||
|
|
771c72de5f | ||
|
|
4bbd0f1e58 | ||
|
|
db1fb1f256 | ||
|
|
19cb43d1ac | ||
|
|
787da9512c |
@@ -123,7 +123,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
|||||||
- 设置 `$_ZL_NO_PROMPT_COMMAND` 为 1 来跳过钩子函数初始化(方便自己处理)。
|
- 设置 `$_ZL_NO_PROMPT_COMMAND` 为 1 来跳过钩子函数初始化(方便自己处理)。
|
||||||
- 设置 `$_ZL_EXCLUDE_DIRS` 逗号分隔的路径列表,列表内的路径不会被收集。
|
- 设置 `$_ZL_EXCLUDE_DIRS` 逗号分隔的路径列表,列表内的路径不会被收集。
|
||||||
- 设置 `$_ZL_ADD_ONCE` 为 '1' 时,仅在当前路径 `$PWD` 改变时才更新数据库。
|
- 设置 `$_ZL_ADD_ONCE` 为 '1' 时,仅在当前路径 `$PWD` 改变时才更新数据库。
|
||||||
- 设置 `$_ZL_MAXAGE` 来确定一个数据老化的阀值 (默认为 5000)。
|
- 设置 `$_ZL_MAXAGE` 来确定一个数据老化的阈值 (默认为 5000)。
|
||||||
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
||||||
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
||||||
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
||||||
@@ -212,7 +212,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
|||||||
|
|
||||||
cd foo
|
cd foo
|
||||||
|
|
||||||
因此,在增强匹配算法中,你总可以象 cd 命令一样使用 z 命令,而不必当心目标路径是否被记录过。
|
因此,在增强匹配算法中,你总可以像 cd 命令一样使用 z 命令,而不必当心目标路径是否被记录过。
|
||||||
|
|
||||||
- 忽略当前路径:
|
- 忽略当前路径:
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
|||||||
|
|
||||||
我当然可以每次使用`z env gems` 来精确指明,但是每当我输入 `z xxx` 我必然是想进行路径跳转的,而不是呆在原地,所以使用增强匹配模式,即便当前目录是最佳匹配,它也能懂得你想跳转的心思。
|
我当然可以每次使用`z env gems` 来精确指明,但是每当我输入 `z xxx` 我必然是想进行路径跳转的,而不是呆在原地,所以使用增强匹配模式,即便当前目录是最佳匹配,它也能懂得你想跳转的心思。
|
||||||
|
|
||||||
再我最初实现 z.lua 时,只有一个和 z.sh 类似的默认匹配算法,在网友的建议下,我陆续学习了来自 fasd / autojump 中的优秀理念,并加以完善改进,成为如今集三家之长的 “增强匹配算法” ,给它取个昵称,叫做 “更懂你的匹配算法”。
|
在我最初实现 z.lua 时,只有一个和 z.sh 类似的默认匹配算法,在网友的建议下,我陆续学习了来自 fasd / autojump 中的优秀理念,并加以完善改进,成为如今集三家之长的 “增强匹配算法” ,给它取个昵称,叫做 “更懂你的匹配算法”。
|
||||||
|
|
||||||
|
|
||||||
## Add once
|
## Add once
|
||||||
|
|||||||
@@ -58,15 +58,6 @@ z -b foo bar # replace foo with bar in cwd and cd there
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
- Fig (works with all shells)
|
|
||||||
|
|
||||||
[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
|
|
||||||
|
|
||||||
|
|
||||||
Install `z.lua` in just one click.
|
|
||||||
|
|
||||||
<a href="https://fig.io/plugins/other/z.lua" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
|
|
||||||
|
|
||||||
- Bash:
|
- Bash:
|
||||||
|
|
||||||
put something like this in your `.bashrc`:
|
put something like this in your `.bashrc`:
|
||||||
|
|||||||
4
z.cmd
4
z.cmd
@@ -89,7 +89,9 @@ if /i "%1"=="--purge" (
|
|||||||
:check
|
:check
|
||||||
|
|
||||||
if /i "%1"=="" (
|
if /i "%1"=="" (
|
||||||
set "RunMode=-l"
|
if /i "%InterMode%"=="" (
|
||||||
|
set "RunMode=-l"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
||||||
|
|||||||
52
z.lua
52
z.lua
@@ -4,7 +4,7 @@
|
|||||||
-- z.lua - a cd command that learns, by skywind 2018-2022
|
-- z.lua - a cd command that learns, by skywind 2018-2022
|
||||||
-- Licensed under MIT license.
|
-- Licensed under MIT license.
|
||||||
--
|
--
|
||||||
-- Version 1.8.18, Last Modified: 2024/04/30 17:11
|
-- Version 1.8.22, Last Modified: 2025/05/17 13:54:38
|
||||||
--
|
--
|
||||||
-- * 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
|
||||||
@@ -1612,21 +1612,23 @@ function z_cd(patterns)
|
|||||||
if patterns == nil then
|
if patterns == nil then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
if #patterns == 0 then
|
if Z_INTERACTIVE == 0 then
|
||||||
return nil
|
if #patterns == 0 then
|
||||||
end
|
return nil
|
||||||
local last = patterns[#patterns]
|
end
|
||||||
if last == '~' or last == '~/' then
|
local last = patterns[#patterns]
|
||||||
return os.path.expand('~')
|
if last == '~' or last == '~/' then
|
||||||
elseif windows and last == '~\\' then
|
return os.path.expand('~')
|
||||||
return os.path.expand('~')
|
elseif windows and last == '~\\' then
|
||||||
end
|
return os.path.expand('~')
|
||||||
if os.path.isabs(last) and os.path.isdir(last) then
|
end
|
||||||
local size = #patterns
|
if os.path.isabs(last) and os.path.isdir(last) then
|
||||||
if size <= 1 then
|
local size = #patterns
|
||||||
return os.path.norm(last)
|
if size <= 1 then
|
||||||
elseif last ~= '/' and last ~= '\\' then
|
return os.path.norm(last)
|
||||||
return os.path.norm(last)
|
elseif last ~= '/' and last ~= '\\' then
|
||||||
|
return os.path.norm(last)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local M = z_match(patterns, Z_METHOD, Z_SUBDIR)
|
local M = z_match(patterns, Z_METHOD, Z_SUBDIR)
|
||||||
@@ -1668,15 +1670,15 @@ function z_cd(patterns)
|
|||||||
local flag = os.environ('_ZL_FZF_FLAG', '')
|
local flag = os.environ('_ZL_FZF_FLAG', '')
|
||||||
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
||||||
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
|
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
|
||||||
|
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
||||||
|
if height ~= nil and height ~= '' and height ~= '0' then
|
||||||
|
cmd = cmd .. ' --height ' .. height
|
||||||
|
end
|
||||||
if not windows then
|
if not windows then
|
||||||
tmpname = os.tmpname()
|
tmpname = os.tmpname()
|
||||||
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
|
||||||
if height ~= nil and height ~= '' and height ~= '0' then
|
|
||||||
cmd = cmd .. ' --height ' .. height
|
|
||||||
end
|
|
||||||
cmd = cmd .. ' < "' .. tmpname .. '"'
|
cmd = cmd .. ' < "' .. tmpname .. '"'
|
||||||
else
|
else
|
||||||
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
|
tmpname = os.tmpname():gsub('[\\:]', ''):gsub('%.', '')
|
||||||
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
||||||
cmd = 'type "' .. tmpname .. '" | ' .. cmd
|
cmd = 'type "' .. tmpname .. '" | ' .. cmd
|
||||||
end
|
end
|
||||||
@@ -1873,7 +1875,7 @@ function cd_breadcrumbs(pwd, interactive)
|
|||||||
if not windows then
|
if not windows then
|
||||||
tmpname = os.tmpname()
|
tmpname = os.tmpname()
|
||||||
else
|
else
|
||||||
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
|
tmpname = os.tmpname():gsub('[\\:]', ''):gsub('%.', '')
|
||||||
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
||||||
end
|
end
|
||||||
fp = io.open(tmpname, 'w')
|
fp = io.open(tmpname, 'w')
|
||||||
@@ -1971,7 +1973,7 @@ function main(argv)
|
|||||||
end
|
end
|
||||||
elseif options['-'] then
|
elseif options['-'] then
|
||||||
path = cd_minus(args, options)
|
path = cd_minus(args, options)
|
||||||
elseif #args == 0 then
|
elseif #args == 0 and Z_INTERACTIVE == 0 then
|
||||||
path = nil
|
path = nil
|
||||||
else
|
else
|
||||||
path = z_cd(args)
|
path = z_cd(args)
|
||||||
@@ -2653,7 +2655,9 @@ if /i "%1"=="--purge" (
|
|||||||
)
|
)
|
||||||
:check
|
:check
|
||||||
if /i "%1"=="" (
|
if /i "%1"=="" (
|
||||||
set "RunMode=-l"
|
if /i "%InterMode%"=="" (
|
||||||
|
set "RunMode=-l"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
||||||
if /i "%RunMode%"=="-n" (
|
if /i "%RunMode%"=="-n" (
|
||||||
|
|||||||
Reference in New Issue
Block a user