Compare commits
149 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
632f722ee4 | ||
|
|
9b9c0b82e6 | ||
|
|
08510fe6c6 | ||
|
|
1ead694395 | ||
|
|
ee6aa2c5ce | ||
|
|
a8e92e0216 | ||
|
|
e2cce39ee4 | ||
|
|
3c88f8d8fa | ||
|
|
786225005c | ||
|
|
481c1774ed | ||
|
|
35e1199eff | ||
|
|
99dbe7b677 | ||
|
|
c88746629b | ||
|
|
336e95b05a | ||
|
|
a3d4f5db68 | ||
|
|
a991162428 | ||
|
|
8210c56414 | ||
|
|
a01b28a8d3 | ||
|
|
695533cee1 | ||
|
|
58425dad65 | ||
|
|
44a2489ba3 | ||
|
|
6e01d4ad52 | ||
|
|
c3c15a3ca9 | ||
|
|
cfad8f54ce | ||
|
|
501f619f94 | ||
|
|
7a8acd469d | ||
|
|
52e066aae7 | ||
|
|
e1a44ee9a5 | ||
|
|
9c0eb6cfbc | ||
|
|
e646d5baa5 | ||
|
|
be90b1a528 | ||
|
|
bda94435fc | ||
|
|
831d617cef | ||
|
|
97fa941ac3 | ||
|
|
c0ff299d67 | ||
|
|
3deb8c7b5c | ||
|
|
222b28571f | ||
|
|
48a77adf35 | ||
|
|
72c3676344 | ||
|
|
9dc5875fa3 | ||
|
|
c90279b677 | ||
|
|
9fb8cadda3 | ||
|
|
edd92d935d | ||
|
|
7848a0a2f3 | ||
|
|
515da0a3d1 | ||
|
|
aebd18cec4 | ||
|
|
90223cf10b | ||
|
|
d666c93ed9 | ||
|
|
805e5c24f3 | ||
|
|
65bfbf8dfb | ||
|
|
1b9630e72d | ||
|
|
c98d2d783e | ||
|
|
057e4f77f3 | ||
|
|
8a90ca6df4 | ||
|
|
a4c51d8103 | ||
|
|
b40df870a6 | ||
|
|
a55bb87e1b | ||
|
|
c4512b47d2 | ||
|
|
6c567b60b3 | ||
|
|
8fff9e6471 | ||
|
|
f7a9104983 | ||
|
|
7b43a0afd6 | ||
|
|
788c0f4b77 | ||
|
|
47aa86b0f9 | ||
|
|
a1498c8672 | ||
|
|
4c34e29e08 | ||
|
|
3d188ab6d9 | ||
|
|
a5f4cb692c | ||
|
|
77a917d116 | ||
|
|
93e9715e7d | ||
|
|
b7c3fbc4ee | ||
|
|
ebda4aa061 | ||
|
|
168ec49849 | ||
|
|
ec123de01a | ||
|
|
a0d4750431 | ||
|
|
d615051a10 | ||
|
|
f448f2ab1f | ||
|
|
8ed3422670 | ||
|
|
3edbda89a0 | ||
|
|
c9b50b3c50 | ||
|
|
228addbc49 | ||
|
|
bca25eba12 | ||
|
|
097ca07ecd | ||
|
|
4ee783956d | ||
|
|
0effba4021 | ||
|
|
cada42e5ea | ||
|
|
b8b6d1afd6 | ||
|
|
4abe97f989 | ||
|
|
756d13d8fa | ||
|
|
4900651af3 | ||
|
|
836efd3973 | ||
|
|
3b8b4c1fbb | ||
|
|
8eaebca04a | ||
|
|
fdd037acf8 | ||
|
|
a817cf6ed2 | ||
|
|
5c36d55698 | ||
|
|
bdab27db1b | ||
|
|
e08f5beca4 | ||
|
|
a245db0d93 | ||
|
|
dd721703c3 | ||
|
|
7920d56c89 | ||
|
|
645818ccc8 | ||
|
|
b98911a227 | ||
|
|
671830059b | ||
|
|
0fad96124b | ||
|
|
465f2b8e62 | ||
|
|
ff9d874ef4 | ||
|
|
86120d206e | ||
|
|
1e0e3523b0 | ||
|
|
7eee4e4b13 | ||
|
|
edd71f7a6e | ||
|
|
f63a832921 | ||
|
|
f92ad79e2c | ||
|
|
38c1741f4f | ||
|
|
fdff5c5e1e | ||
|
|
b691d537f2 | ||
|
|
472925ac92 | ||
|
|
5ba0e50894 | ||
|
|
c769dba4dd | ||
|
|
bbca83c9a5 | ||
|
|
53c127a4a2 | ||
|
|
5f7fa928b6 | ||
|
|
68de23ecef | ||
|
|
5ea08c5dac | ||
|
|
9dd0fec7ed | ||
|
|
fe11dd30c5 | ||
|
|
db92fa0a1c | ||
|
|
b1702839d2 | ||
|
|
1a0428f54e | ||
|
|
31e9d42d08 | ||
|
|
14b942634c | ||
|
|
6cfe2150e9 | ||
|
|
a4c589a724 | ||
|
|
cb8021599c | ||
|
|
91a4d75e62 | ||
|
|
4d4dc8802b | ||
|
|
761b3ebf31 | ||
|
|
4e7ecde314 | ||
|
|
e5c78e3087 | ||
|
|
1fb4f25744 | ||
|
|
6057644adb | ||
|
|
dc02feb424 | ||
|
|
2e658dd379 | ||
|
|
f638730d5f | ||
|
|
b9e8501b71 | ||
|
|
31fd92f2da | ||
|
|
7af0290e11 | ||
|
|
8334b1adb7 | ||
|
|
f068e8597f |
86
README.cn.md
@@ -14,11 +14,11 @@ z.lua 是一个快速路径切换工具,它会跟踪你在 shell 下访问过
|
|||||||
|
|
||||||
- 性能比 **z.sh** 快三倍,比 **fasd** / **autojump** 快十倍以上。
|
- 性能比 **z.sh** 快三倍,比 **fasd** / **autojump** 快十倍以上。
|
||||||
- 支持 Posix Shell:bash, zsh, dash, sh, ash, busybox 等等。
|
- 支持 Posix Shell:bash, zsh, dash, sh, ash, busybox 等等。
|
||||||
- 支持 Fish Shell,Power Shell 和 Windows cmd。
|
- 支持 Fish Shell,Power Shell 和 Windows cmd。
|
||||||
- 使用增强匹配算法,更准确的带你去到你想去的地方。
|
- 使用增强匹配算法,更准确的带你去到你想去的地方。
|
||||||
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。
|
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。
|
||||||
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
|
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
|
||||||
- 集成 fzf (可选),可以用来做可视化选择或者 bash 参数补全。
|
- 集成 fzf (可选),可以用来做可视化选择或者参数补全。
|
||||||
- 快速跳转到父目录,或者项目根目录,代替反复 “cd ../../.." 。
|
- 快速跳转到父目录,或者项目根目录,代替反复 “cd ../../.." 。
|
||||||
- 兼容 lua 5.1, 5.2 和 5.3 以上版本。
|
- 兼容 lua 5.1, 5.2 和 5.3 以上版本。
|
||||||
- 自包含且无额外依赖,单个 `z.lua` 文件完成所有工作。
|
- 自包含且无额外依赖,单个 `z.lua` 文件完成所有工作。
|
||||||
@@ -42,10 +42,10 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
|||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等):
|
- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等):
|
||||||
|
|
||||||
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
|
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
|
||||||
|
|
||||||
eval "$(lua /path/to/z.lua --init bash)" # BASH 初始化
|
eval "$(lua /path/to/z.lua --init bash)" # BASH 初始化
|
||||||
eval "$(lua /path/to/z.lua --init zsh)" # ZSH 初始化
|
eval "$(lua /path/to/z.lua --init zsh)" # ZSH 初始化
|
||||||
eval "$(lua /path/to/z.lua --init posix)" # Posix shell 初始化
|
eval "$(lua /path/to/z.lua --init posix)" # Posix shell 初始化
|
||||||
@@ -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:
|
||||||
|
|
||||||
@@ -79,18 +84,18 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
|||||||
|
|
||||||
但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。
|
但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。
|
||||||
|
|
||||||
- Power Shell:
|
- Power Shell:
|
||||||
|
|
||||||
在你 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):
|
||||||
|
|
||||||
- 将 z.lua 和 z.cmd 拷贝到 clink 的安装目录。
|
- 将 z.lua 和 z.cmd 拷贝到 clink 的安装目录。
|
||||||
- 将 clink 的安装目录添加到 `%PATH%` (z.cmd 可以被任意位置调用到)。
|
- 将 clink 的安装目录添加到 `%PATH%` (z.cmd 可以被任意位置调用到)。
|
||||||
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
|
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
|
||||||
|
|
||||||
|
|
||||||
- Windows cmder:
|
- Windows cmder:
|
||||||
@@ -111,6 +116,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
|||||||
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
||||||
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
||||||
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
||||||
|
- 设置 `$_ZL_HYPHEN` 为 1 可以允许关键字中包含横线 (横线默认是 lua 正则关键字,要转写成 `%-`)。
|
||||||
|
|
||||||
## Aging
|
## Aging
|
||||||
|
|
||||||
@@ -161,7 +167,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
|||||||
|
|
||||||
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
||||||
|
|
||||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||||
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
||||||
|
|
||||||
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
||||||
@@ -175,14 +181,14 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
|||||||
30 /home/user/workspace/project2
|
30 /home/user/workspace/project2
|
||||||
40 /home/user/workspace/project3
|
40 /home/user/workspace/project3
|
||||||
|
|
||||||
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/work` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
|
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/workspace` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
|
||||||
|
|
||||||
因为最后一级目录名称总是最容易记住的,所以给到它比较高的优先级。在默认匹配算法中,你同样可以用 `"z space$"` 来达到相同的目的,但是 `"z wo"` 可以打更少的字。
|
因为最后一级目录名称总是最容易记住的,所以给到它比较高的优先级。在默认匹配算法中,你同样可以用 `"z space$"` 来达到相同的目的,但是 `"z wo"` 可以打更少的字。
|
||||||
|
|
||||||
小技巧:
|
小技巧:
|
||||||
|
|
||||||
- 如果你在增强匹配算法下,想让最后一个关键字不当匹配最后一段路径名,还可以像默认匹配算法中一样匹配路径的其他部分的话,你可以在最后加一个独立的 '$' 参数,比如:`"z wo $"`
|
- 如果你在增强匹配算法下,想让最后一个关键字不当匹配最后一段路径名,还可以像默认匹配算法中一样匹配路径的其他部分的话,你可以在最后加一个独立的 '$' 参数,比如:`"z wo $"`
|
||||||
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
|
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
|
||||||
|
|
||||||
|
|
||||||
- 如果没法匹配,同时又存在一条路径名和关键字相同,那么 cd 过去:
|
- 如果没法匹配,同时又存在一条路径名和关键字相同,那么 cd 过去:
|
||||||
@@ -250,7 +256,9 @@ PS:如果你使用 Fish shell,需要 2.7.0 以上才支持该功能。
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
当你使用 `"z -I vim"` 时,12 条路径被筛选出来,并按照 frecent 排序,他们都包含 "vim" 关键字,在实际 cd 改变路径前,z.lua 会调用 fzf 来让你更方便的选择你想去的地方,每条记录包含左边的 frecent 权重和右边的路径名,权重越高的排在越前面,你可以按回车选择,或者 ESC 退出。
|
当你使用 `"z -I vim"` 时,12 条路径被筛选出来,并按照 frecent 排序,他们都包含 "vim" 关键字,在实际 cd 改变路径前,z.lua 会调用 fzf 来让你更方便的选择你想去的地方,每条记录包含左边的 frecent 权重和右边的路径名,权重越高的排在越前面。
|
||||||
|
|
||||||
|
你可以在 fzf 里输入一些**空格分隔**的关键字(不需要先后顺序),或者按 `CTRL+J` / `CTRL+K` (方向键的上下也可以)进行选择,`ESC` 或者 `CTRL`+`D`/`G` 放弃。
|
||||||
|
|
||||||
你仍然可以用老方法,通过在 `z` 命令后面添加更多关键词来精确的匹配你想去的地方,这个特性给了你一个可视化的方式来做这件事情。为了方便起见,通常把 `z -I` alias 成 `zf` (z + fuzzy finder)。如果搜索结果只有一项,那么 z.lua 会直接跳转过去,不需要启动 fzf 再选择一遍,只有多项结果要选择时,才会启动 fzf。
|
你仍然可以用老方法,通过在 `z` 命令后面添加更多关键词来精确的匹配你想去的地方,这个特性给了你一个可视化的方式来做这件事情。为了方便起见,通常把 `z -I` alias 成 `zf` (z + fuzzy finder)。如果搜索结果只有一项,那么 z.lua 会直接跳转过去,不需要启动 fzf 再选择一遍,只有多项结果要选择时,才会启动 fzf。
|
||||||
|
|
||||||
@@ -263,11 +271,11 @@ PS:你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路
|
|||||||
|
|
||||||
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
||||||
|
|
||||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到父目录中包含 (.git/.svn/.hg) 的地方。
|
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||||
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
||||||
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
||||||
|
|
||||||
为了使用简便,我们继续将 `z -b` 取个别名成 `zb`:
|
先将 `z -b` 别名成 `zb`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 一直向上退到项目根目录(就是里面有一个 .git 目录的地方)
|
# 一直向上退到项目根目录(就是里面有一个 .git 目录的地方)
|
||||||
@@ -300,6 +308,8 @@ export _ZL_ROOT_MARKERS=".git,.svn,.hg,.root,package.json"
|
|||||||
|
|
||||||
**Bonus**:`zb ..` 相当于 `cd ..`,`zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。
|
**Bonus**:`zb ..` 相当于 `cd ..`,`zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。
|
||||||
|
|
||||||
|
**Bonus**: 试试 `z -b -i` 以及 `z -b -I`,推荐把他们取个别名成 `zbi` 和 `zbf`。
|
||||||
|
|
||||||
|
|
||||||
## 补全功能
|
## 补全功能
|
||||||
|
|
||||||
@@ -321,27 +331,14 @@ eval "$(lua /path/to/z.lua --init bash enhanced once echo fzf)"
|
|||||||
|
|
||||||
有了 fzf 的帮助,bash 下补全也非常方便了。注意看左边的权重,fzf 搜索过滤的顺序是有讲究的,Frecent 权重越高的越靠前,不是乱排序的,更不是简单的按字符串字母排序。这里完全保证权重越高的路径越靠前。
|
有了 fzf 的帮助,bash 下补全也非常方便了。注意看左边的权重,fzf 搜索过滤的顺序是有讲究的,Frecent 权重越高的越靠前,不是乱排序的,更不是简单的按字符串字母排序。这里完全保证权重越高的路径越靠前。
|
||||||
|
|
||||||
|
`z.lua` 可以同 [fz](https://github.com/changyuheng/fz) 协作以提供**更好的补全结果**,详细见 [FAQ](https://github.com/skywind3000/z.lua/wiki/FAQ#fzsh-for-better-completion)。
|
||||||
|
|
||||||
注意:该功能在初始化 z.lua 之前,会检测 $PATH 中是否有 fzf 这个程序,有的话才启用。
|
注意:该功能在初始化 z.lua 之前,会检测 $PATH 中是否有 fzf 这个程序,有的话才启用。
|
||||||
|
|
||||||
|
|
||||||
## MRU
|
## MRU
|
||||||
|
|
||||||
以往我们经常使用 `cd -` 命令来回到刚才访问过的目录,而有了 fzf 的帮助,我们可以更高效的来完成这件事情:
|
`z.lua` 提供 `dirstack` 让你更便捷的访问最近刚刚去过的目录,而不需要输入任何关键字。这个方法叫做 `dirstack`,它记录着最近你刚刚去过的 10 条最新路径,然后是用 `z -`,`z --` 和 `z -{num}` 来操作:
|
||||||
|
|
||||||
|
|
||||||
```bash
|
|
||||||
alias zh='z -I -t .'
|
|
||||||
```
|
|
||||||
|
|
||||||
首先定义个新的别名 `zh`(回到历史路径的意思),我们使用了 `-t` 参数来告诉 `z.lua` 按照时间戳作为权重进行排序,同时 `-I` 启用 fzf 进行搜索,最后的句号代表任意路径。
|
|
||||||
|
|
||||||
那么当我们在命令行敲入 zh 时,就可以用 fzf 选择最近呆过的路径了:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
第一列数据代表该路径多少秒以前访问过,第二列是路径名称。此时,你可以试着敲几个字母,用 fzf 的字符串模糊匹配进行定位,或者用光标键的上和下(CTRL+J/K 也可以)来上下移动,最后按回车 cd 过去,或者 ESC 放弃。
|
|
||||||
|
|
||||||
版本 `v1.5.1` 引入了模拟 `dirstack` 可以通过: `z -`,`z --` 和 `z -{num}` 来操作:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 显示当前的 dir stack
|
# 显示当前的 dir stack
|
||||||
@@ -361,9 +358,22 @@ $ z -
|
|||||||
=> cd -
|
=> cd -
|
||||||
```
|
```
|
||||||
|
|
||||||
这个 `dirstack` 是根据 z.lua 的路径历史数据库计算的出来的,所以和具体的 shell 或者操作系统都没有关系。你退出再登陆不会丢失这些路径历史,不同的 shell 之间也可以共享同一份历史数据。
|
这个 `dirstack` 是根据 z.lua 的路径历史数据库计算的出来的,和具体的 shell 或者操作系统无关。你退出再登陆不会丢失这些记录,不同的 shell 之间也可以共享同一份记录。
|
||||||
|
|
||||||
|
此外,还能通过前面提到的 `-I` 和 `-t` 参数组和,使用 fzf 选择最近去过的目录:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
alias zh='z -I -t .'
|
||||||
|
```
|
||||||
|
|
||||||
|
方便起见,定义个新的别名 `zh`(回到历史路径的意思),我们用 `-t` 参数来告诉 `z.lua` 按时间戳为权重排序,同时 `-I` 启用 fzf 搜索,最后句号代表任意路径。
|
||||||
|
|
||||||
|
那么当我们在命令行敲入 zh 时,就可以用 fzf 进行历史路径操作了:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
第一列上次访问距今多少秒,第二列是目录名。你可以试着敲几个字母,用 fzf 的字符串模糊匹配进行定位,或者用光标键的上和下(CTRL+J/K 也可以)来上下移动,最后按回车 cd 过去,或者 ESC 放弃。
|
||||||
|
|
||||||
注意:最好把增强匹配模式打开,这样查看历史路径时可以把当前路径过滤掉。
|
|
||||||
|
|
||||||
|
|
||||||
## Tips
|
## Tips
|
||||||
@@ -391,7 +401,7 @@ FN="$HOME/.local/share/autojump/autojump.txt"
|
|||||||
awk -F '\t' '{print $2 "|" $1 "|" 0}' $FN >> ~/.zlua
|
awk -F '\t' '{print $2 "|" $1 "|" 0}' $FN >> ~/.zlua
|
||||||
```
|
```
|
||||||
|
|
||||||
|
要更好的使用 `z.lua`,别忘记阅读:[Frequently Asked Questions](https://github.com/skywind3000/z.lua/wiki/FAQ)。
|
||||||
|
|
||||||
|
|
||||||
## Benchmark
|
## Benchmark
|
||||||
|
|||||||
140
README.md
@@ -13,19 +13,29 @@ z.lua is a faster way to navigate your filesystem. It tracks your most used dire
|
|||||||
|
|
||||||
For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`.
|
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
|
## Features
|
||||||
|
|
||||||
- **10x** times faster than **fasd** and **autojump**, **3x** times faster than **z.sh**.
|
- **10x** times faster than **fasd** and **autojump**, **3x** times faster than **z.sh**.
|
||||||
|
- Gain the ultimate speed with an optional [native module](https://github.com/skywind3000/czmod) written in C.
|
||||||
- Available for **posix shells**: bash, zsh, dash, sh, ash, ksh, busybox and etc.
|
- Available for **posix shells**: bash, zsh, dash, sh, ash, ksh, busybox and etc.
|
||||||
- Available for Fish Shell, Power Shell and Windows cmd.
|
- Available for Fish Shell, Power Shell and Windows cmd.
|
||||||
- Enhanced matching mode takes you to where ever you want precisely.
|
- [Enhanced matching algorithm](#enhanced-matching) takes you to where ever you want precisely.
|
||||||
- Allow updating database only if `$PWD` changed with "$_ZL_ADD_ONCE" set to 1.
|
- Allow updating database only if `$PWD` changed with "$_ZL_ADD_ONCE" set to 1.
|
||||||
- Interactive selection enables you to choose where to go before cd.
|
- Interactive selection enables you to choose where to go before cd.
|
||||||
- Intergrated with FZF (optional) for interactive selection and bash completion.
|
- Integrated with FZF (optional) for interactive selection and completion.
|
||||||
- Quickly go back to a parent directory instead of typing "cd ../../..".
|
- Quickly go back to a parent directory instead of typing "cd ../../..".
|
||||||
- Corresponding experience in different shells and operating systems.
|
- 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.
|
- Self contained, distributed as a single `z.lua` script, no other dependence.
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +44,7 @@ For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`.
|
|||||||
```bash
|
```bash
|
||||||
z foo # cd to most frecent dir matching foo
|
z foo # cd to most frecent dir matching foo
|
||||||
z foo bar # cd to most frecent dir matching foo and bar
|
z foo bar # cd to most frecent dir matching foo and bar
|
||||||
z -r foo # cd to highest ranked dir matching foo
|
z -r foo # cd to the highest ranked dir matching foo
|
||||||
z -t foo # cd to most recently accessed dir matching foo
|
z -t foo # cd to most recently accessed dir matching foo
|
||||||
z -l foo # list matches instead of cd
|
z -l foo # list matches instead of cd
|
||||||
z -c foo # restrict matches to subdirs of $PWD
|
z -c foo # restrict matches to subdirs of $PWD
|
||||||
@@ -59,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:
|
||||||
|
|
||||||
@@ -75,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`:
|
||||||
@@ -87,37 +105,47 @@ 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:
|
||||||
|
|
||||||
|
> ⚠️ **WARNING**: users of [Starship Prompt](https://starship.rs/) should add the following command *after* `starship init`.
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@@ -127,10 +155,12 @@ 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
|
||||||
|
- set `$_ZL_HYPHEN` to 1 to treat hyphon (-) as a normal character not a lua regexp keyword.
|
||||||
|
- set `$_ZL_CLINK_PROMPT_PRIORITY` change clink prompt register priority (default 99).
|
||||||
|
|
||||||
## Aging
|
## Aging
|
||||||
|
|
||||||
@@ -195,7 +225,7 @@ If no match is found, it will fall back to default matching method.
|
|||||||
30 /home/user/workspace/project2
|
30 /home/user/workspace/project2
|
||||||
40 /home/user/workspace/project3
|
40 /home/user/workspace/project3
|
||||||
|
|
||||||
If you use `"z wo"` in enhanced matching mode, only the `/home/user/work` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`.
|
If you use `"z wo"` in enhanced matching mode, only the `/home/user/workspace` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`.
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
@@ -219,14 +249,14 @@ If no match is found, it will fall back to default matching method.
|
|||||||
|
|
||||||
- Skip the current directory:
|
- Skip the current directory:
|
||||||
|
|
||||||
when you are calling `z xxx` but the best match is the current directory, z.lua will choose the 2nd best match result for you. Assuming the database:
|
When you are calling `z xxx` but the best match is the current directory, z.lua will choose the 2nd best match result for you. Assuming the database:
|
||||||
|
|
||||||
10 /Users/Great_Wall/.rbenv/versions/2.4.1/lib/ruby/gems
|
10 /Users/Great_Wall/.rbenv/versions/2.4.1/lib/ruby/gems
|
||||||
20 /Library/Ruby/Gems/2.0.0/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.
|
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.
|
||||||
|
|
||||||
The default matching method is designed to be compatible with original z.sh, but the enhanced matching method is much more handy and exclusive to z.lua.
|
The default matching method is designed to be compatible with original z.sh, but the enhanced matching method is much more handy and exclusive to z.lua.
|
||||||
|
|
||||||
@@ -235,15 +265,16 @@ The default matching method is designed to be compatible with original z.sh, but
|
|||||||
|
|
||||||
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:
|
To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can initialize z.lua on linux like this:
|
||||||
|
|
||||||
````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
|
||||||
````
|
````
|
||||||
|
|
||||||
It could be much faster on slow hardware or Cygwin/MSYS.
|
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.
|
||||||
|
|
||||||
|
|
||||||
## Interactive Selection
|
## Interactive Selection
|
||||||
|
|
||||||
@@ -261,19 +292,22 @@ And then you can input the number and choose where to go before actual cd. eg. i
|
|||||||
|
|
||||||
NOTE: for fish shell, this feature requires fish 2.7.0 or above.
|
NOTE: for fish shell, this feature requires fish 2.7.0 or above.
|
||||||
|
|
||||||
|
|
||||||
## FZF Supports
|
## FZF Supports
|
||||||
|
|
||||||
From version 1.1.0, a new option `"-I"` will allow you to use fzf to select when there are multiple matches.
|
From version 1.1.0, a new option `"-I"` will allow you to use fzf to select when there are multiple matches.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
When we use `"z -I vim"`,12 paths contains keyword "vim" has been matched and ordered by their frecent value, the higher frecent comes with the higher rank. Then without cd to the highest ranked path, z.lua passes all the candidates to fzf. And you can use fzf to select where you want to go, or ESC to quit.
|
When we use `"z -I vim"`,12 paths contains keyword "vim" has been matched and ordered by their frecent value, the higher frecent comes with the higher rank. Then without cd to the highest ranked path, z.lua passes all the candidates to fzf.
|
||||||
|
|
||||||
|
Now you can input some space separated keywords (no order required) or use `CTRL+J`/`CTRL+K` (same as `UP`/`DOWN`) to select where you want to go, or `ESC` / `CTRL`+`D`/`G` to give up.
|
||||||
|
|
||||||
Of course, you can always give more keywords to `z` command to match your destination precisely. `"z -I"` is similar to `"z -i"`, but use fzf. Both `"-i"` and `"-I"` provide you another way for path navigation.
|
Of course, you can always give more keywords to `z` command to match your destination precisely. `"z -I"` is similar to `"z -i"`, but use fzf. Both `"-i"` and `"-I"` provide you another way for path navigation.
|
||||||
|
|
||||||
Usually, `z -I` can be aliased to `zf` (z + fuzzy finder) for convenience. If there are only one path matched, `z -I` will jump to it directly, fzf will only be invoked for multiple matches.
|
Usually, `z -I` can be aliased to `zf` (z + fuzzy finder) for convenience. If there are only one path matched, `z -I` will jump to it directly, fzf will only be invoked for multiple matches. `"z -I ."` or `"zf ."` can be used to use fzf select from entire database.
|
||||||
|
|
||||||
`"z -I ."` or `"zf ."` can be used to use fzf select from entire database.
|
For more information about this, please visit [wiki - effective with fzf](https://github.com/skywind3000/z.lua/wiki/Effective-with-fzf).
|
||||||
|
|
||||||
NOTE: For fish shell, this feature requires fish 2.7.0 or above. You can specify fzf executable in `$_ZL_FZF` environment variable, `"fzf"` will be called by default.
|
NOTE: For fish shell, this feature requires fish 2.7.0 or above. You can specify fzf executable in `$_ZL_FZF` environment variable, `"fzf"` will be called by default.
|
||||||
|
|
||||||
@@ -282,8 +316,8 @@ NOTE: For fish shell, this feature requires fish 2.7.0 or above. You can specify
|
|||||||
|
|
||||||
New option `"-b"` can quickly go back to a specific parent directory in bash instead of typing "cd ../../.." redundantly.
|
New option `"-b"` can quickly go back to a specific parent directory in bash instead of typing "cd ../../.." redundantly.
|
||||||
|
|
||||||
- **(No argument)**: `cd` into the project root, the project root is one of the parent directory with `.git`/`.hg`/`.svn` in it
|
- **(No argument)**: `cd` into the project root, the project root the nearest parent directory with `.git`/`.hg`/`.svn` in it.
|
||||||
- **(One argument)**: `cd` into the closest parent starting with keyword, if not find, goto the parent containing keyword.
|
- **(One argument)**: `cd` into the closest parent starting with keyword, if not find, go to the parent containing keyword.
|
||||||
- **(Two arguments)**: replace the first value with the second one (in the current path).
|
- **(Two arguments)**: replace the first value with the second one (in the current path).
|
||||||
|
|
||||||
Let's start by aliasing `z -b` to `zb`:
|
Let's start by aliasing `z -b` to `zb`:
|
||||||
@@ -318,6 +352,7 @@ If you want `zb` jump back to a parent directory contains a `.root` or `package.
|
|||||||
|
|
||||||
**Bonus**: `zb ..` equals to `cd ..`, `zb ...` equals to `cd ../..` and `zb ....` equals to `cd ../../..`, and so on. Finally, `zb ..20` equals to `cd (..)x20`.
|
**Bonus**: `zb ..` equals to `cd ..`, `zb ...` equals to `cd ../..` and `zb ....` equals to `cd ../../..`, and so on. Finally, `zb ..20` equals to `cd (..)x20`.
|
||||||
|
|
||||||
|
**Bonus**: try `z -b -i` and `z -b -I` and you can alias them to `zbi` and `zbf`.
|
||||||
|
|
||||||
## Completion
|
## Completion
|
||||||
|
|
||||||
@@ -337,10 +372,13 @@ Then press `<tab>` after `z xxx`:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
With the help of fzf, completion in bash is much easier now.
|
With the help of fzf, completion in bash is much easier now.
|
||||||
|
|
||||||
|
`z.lua` can cooperate with [fz](https://github.com/changyuheng/fz) for **better completion** result in both bash and zsh, for more information see [FAQ](https://github.com/skywind3000/z.lua/wiki/FAQ#fzsh-for-better-completion).
|
||||||
|
|
||||||
NOTE: To enable this, command `fzf` must be found in `$PATH` before initialization.
|
NOTE: To enable this, command `fzf` must be found in `$PATH` before initialization.
|
||||||
|
|
||||||
|
|
||||||
## Most Recently Accessed Path
|
## Most Recently Accessed Path
|
||||||
|
|
||||||
`z.lua` provides a fast way to visit MRU directories without typing any keyword. That is `dirstack`, which records recently visited paths and can be manipulated by `z -`, `z --` and `z -{num}`:
|
`z.lua` provides a fast way to visit MRU directories without typing any keyword. That is `dirstack`, which records recently visited paths and can be manipulated by `z -`, `z --` and `z -{num}`:
|
||||||
@@ -371,7 +409,7 @@ There is another way to access MRU directories interactively by utilizing parame
|
|||||||
alias zh='z -I -t .'
|
alias zh='z -I -t .'
|
||||||
```
|
```
|
||||||
|
|
||||||
The new alias `zh` (jump to history) uses a parameter `-t` to sort the result by time and `-I` to use `fzf` for selection. the result is:
|
The new alias `zh` (jump to history) is very easy to input:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -388,8 +426,8 @@ Remember to enable the [enhanced matching](#enhanced-matching) algorithm, the cu
|
|||||||
Recommended aliases you may find useful:
|
Recommended aliases you may find useful:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
alias zc='z -c' # restrict matches to subdirs of $PWD
|
alias zz='z -c' # restrict matches to subdirs of $PWD
|
||||||
alias zz='z -i' # cd with interactive selection
|
alias zi='z -i' # cd with interactive selection
|
||||||
alias zf='z -I' # use fzf to select in multiple matches
|
alias zf='z -I' # use fzf to select in multiple matches
|
||||||
alias zb='z -b' # quickly cd to the parent directory
|
alias zb='z -b' # quickly cd to the parent directory
|
||||||
```
|
```
|
||||||
@@ -408,11 +446,12 @@ FN="$HOME/.local/share/autojump/autojump.txt"
|
|||||||
awk -F '\t' '{print $2 "|" $1 "|" 0}' $FN >> ~/.zlua
|
awk -F '\t' '{print $2 "|" $1 "|" 0}' $FN >> ~/.zlua
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Don't forget to read the [Frequently Asked Questions](https://github.com/skywind3000/z.lua/wiki/FAQ).
|
||||||
|
|
||||||
|
|
||||||
## Benchmark
|
## Benchmark
|
||||||
|
|
||||||
The slowest part is adding path to history data file. It will run every time when you press enter (installed in $PROMPT_COMMAND). so I profile it on my nas:
|
The slowest part is adding path to history data file. It will run every time when you press enter (installed in $PROMPT_COMMAND). So I profile it on my NAS:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ time autojump --add /tmp
|
$ time autojump --add /tmp
|
||||||
@@ -438,18 +477,43 @@ sys 0m0.030s
|
|||||||
|
|
||||||
As you see, z.lua is the fastest one and requires less resource.
|
As you see, z.lua is the fastest one and requires less resource.
|
||||||
|
|
||||||
|
## Native Module
|
||||||
|
|
||||||
|
z.lua is fast enough for most case, the path tracking action will be triggered each time when you change your current directory.
|
||||||
|
|
||||||
## Reputation
|
So I still recommend the pure lua script for portability and flexibility, but for someone who really care about `10ms` or `1ms` things, this module can help them to gain the ultimate speed.
|
||||||
|
|
||||||
|
- [czmod](https://github.com/skywind3000/czmod): native module to boost `z.lua`.
|
||||||
|
|
||||||
|
Average performance:
|
||||||
|
|
||||||
|
| Name | czmod | z.lua |
|
||||||
|
|-|-|-|
|
||||||
|
| **Update Time** | 1.6ms | 13.2ms |
|
||||||
|
| **Query Time** | 1.5ms | 9.8ms |
|
||||||
|
|
||||||
- "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."
|
|
||||||
|
|
||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
|
- 1.8.7 (2020-06-29): use lfs or luajit's cffi if possible.
|
||||||
|
- 1.8.4 (2020-02-10): fish shell: set `$_ZL_ECHO` to global scope.
|
||||||
|
- 1.8.3 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
|
||||||
|
- 1.7.4 (2019-12-29): new: `$_ZL_HYPHEN` to treat hyphen as a normal character, see [here](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-input-a-hyphen---in-the-keyword-).
|
||||||
|
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
|
||||||
|
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik).
|
||||||
|
- 1.7.1 (2019-06-07): Fixed: `$_ZL_DATA` failure on Linux sometimes.
|
||||||
|
- 1.7.0 (2019-03-09): Support [ranger](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-integrate-zlua-to-ranger-), fix ReplaceFile issue in luajit (windows).
|
||||||
|
- 1.6.0 (2019-03-04): optimize with ffi module (luajit builtin module).
|
||||||
|
- 1.5.11 (2019-03-02): fixed: os.path.isdir doesn't work for symbol link folders.
|
||||||
|
- 1.5.10 (2019-03-01): Prevent writing file racing.
|
||||||
|
- 1.5.9 (2019-02-25): `z -b` should not match current directory (close #56).
|
||||||
|
- 1.5.8 (2019-02-21): new `$_ZL_FZF_HEIGHT` to control `--height` parameter in fzf.
|
||||||
|
- 1.5.7 (2019-02-21): rename `$_ZL_FZF_SORT` to `$_ZL_INT_SORT` it will affect both `-i` and `-I`.
|
||||||
|
- 1.5.6 (2019-02-20): set `$_ZL_FZF_SORT` to 1 to sort directories by alphabet in fzf.
|
||||||
|
- 1.5.5 (2019-02-20): `$_ZL_FZF_FLAG` can be used to override fzf flags, default to "+s -e".
|
||||||
|
- 1.5.4 (2019-02-19): fixed: file/path existence detection fails on read-only fs (closed [#49](https://github.com/skywind3000/z.lua/issues/49) by [@contrun](https://github.com/contrun)).
|
||||||
|
- 1.5.3 (2019-02-17): new `$_ZL_FZF_FLAG` for passing additional flags to fzf, add `-e` argument to fzf.
|
||||||
- 1.5.2 (2019-02-16): be aware of all arguments in fzf completion.
|
- 1.5.2 (2019-02-16): be aware of all arguments in fzf completion.
|
||||||
- 1.5.1 (2019-02-15): new: simulated dir stack by `z -`, `z --` and `z -{num}`.
|
- 1.5.1 (2019-02-15): new: simulated dir stack by `z -`, `z --` and `z -{num}`.
|
||||||
- 1.5.0 (2019-02-14): fixed minor issues in backward jumping.
|
- 1.5.0 (2019-02-14): fixed minor issues in backward jumping.
|
||||||
@@ -477,6 +541,7 @@ As you see, z.lua is the fastest one and requires less resource.
|
|||||||
|
|
||||||
This project needs help for the tasks below:
|
This project needs help for the tasks below:
|
||||||
|
|
||||||
|
- [ ] Support csh/tcsh.
|
||||||
- [ ] Completion: Actually I got little knowledge in completion, and need help to improve it.
|
- [ ] Completion: Actually I got little knowledge in completion, and need help to improve it.
|
||||||
- [ ] Completion: Implement completion for Power Shell.
|
- [ ] Completion: Implement completion for Power Shell.
|
||||||
- [ ] Completion: Implement completion for different arguments.
|
- [ ] Completion: Implement completion for different arguments.
|
||||||
@@ -490,6 +555,7 @@ This project needs help for the tasks below:
|
|||||||
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting.
|
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting.
|
||||||
- Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting.
|
- Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting.
|
||||||
- Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash.
|
- Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash.
|
||||||
|
- Thanks to [@barlik](https://github.com/barlik) for many improvements.
|
||||||
|
|
||||||
And many others.
|
And many others.
|
||||||
|
|
||||||
|
|||||||
|
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
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
images/step2.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
images/step3.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
images/step4.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
11
init.fish
@@ -17,11 +17,18 @@ end
|
|||||||
|
|
||||||
set -x _ZL_DATA "$_ZL_DATA"
|
set -x _ZL_DATA "$_ZL_DATA"
|
||||||
|
|
||||||
set _zlua_dir (dirname (status --current-filename))
|
set -q XDG_DATA_HOME; or set XDG_DATA_HOME ~/.local/share
|
||||||
|
if functions -q fisher
|
||||||
|
set _zlua_dir $XDG_DATA_HOME/fisher/github.com/skywind3000/z.lua
|
||||||
|
else
|
||||||
|
set _zlua_dir (dirname (status --current-filename))
|
||||||
|
end
|
||||||
|
|
||||||
if test -e $_zlua_dir/z.lua
|
if test -e $_zlua_dir/z.lua
|
||||||
if type -q lua
|
if type -q lua
|
||||||
lua $_zlua_dir/z.lua --init fish enhanced once echo | source
|
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
|
else if type -q lua5.3
|
||||||
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
|
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||||
else if type -q lua5.2
|
else if type -q lua5.2
|
||||||
@@ -35,6 +42,8 @@ if test -e $_zlua_dir/z.lua
|
|||||||
alias zz='z -i' # cd with interactive selection
|
alias zz='z -i' # cd with interactive selection
|
||||||
alias zf='z -I' # use fzf to select in multiple matches
|
alias zf='z -I' # use fzf to select in multiple matches
|
||||||
alias zb='z -b' # quickly cd to the parent directory
|
alias zb='z -b' # quickly cd to the parent directory
|
||||||
|
alias zbi='z -b -i' # interactive jump backward
|
||||||
|
alias zbf='z -b -I' # interactive jump backward with fzf
|
||||||
set -U ZLUA_SCRIPT "$ZLUA_SCRIPT" 2> /dev/null
|
set -U ZLUA_SCRIPT "$ZLUA_SCRIPT" 2> /dev/null
|
||||||
set -U ZLUA_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null
|
set -U ZLUA_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null
|
||||||
end
|
end
|
||||||
|
|||||||
87
ranger_zlua.py
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import time, sys, os
|
||||||
|
import ranger.api
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
old_hook_init = ranger.api.hook_init
|
||||||
|
|
||||||
|
PATH_LUA = os.environ.get('RANGER_LUA')
|
||||||
|
PATH_ZLUA = os.environ.get('RANGER_ZLUA')
|
||||||
|
|
||||||
|
if not PATH_LUA:
|
||||||
|
for path in os.environ.get('PATH', '').split(os.path.pathsep):
|
||||||
|
for name in ('lua', 'luajit', 'lua5.3', 'lua5.2', 'lua5.1'):
|
||||||
|
test = os.path.join(path, name)
|
||||||
|
test = test + (sys.platform[:3] == 'win' and ".exe" or "")
|
||||||
|
if os.path.exists(test):
|
||||||
|
PATH_LUA = test
|
||||||
|
break
|
||||||
|
|
||||||
|
if not PATH_LUA:
|
||||||
|
sys.stderr.write('Please install lua or set $RANGER_LUA.\n')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if (not PATH_ZLUA) or (not os.path.exists(PATH_ZLUA)):
|
||||||
|
sys.stderr.write('Not find z.lua, please set $RANGER_ZLUA to absolute path of z.lua.\n')
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def hook_init(fm):
|
||||||
|
def update_zlua(signal):
|
||||||
|
import os, random
|
||||||
|
os.environ['_ZL_RANDOM'] = str(random.randint(0, 0x7fffffff))
|
||||||
|
p = subprocess.Popen([PATH_LUA, PATH_ZLUA, "--add", signal.new.path])
|
||||||
|
p.wait()
|
||||||
|
if PATH_ZLUA and PATH_LUA and os.path.exists(PATH_ZLUA):
|
||||||
|
fm.signal_bind('cd', update_zlua)
|
||||||
|
return old_hook_init(fm)
|
||||||
|
|
||||||
|
ranger.api.hook_init = hook_init
|
||||||
|
|
||||||
|
class z(ranger.api.commands.Command):
|
||||||
|
def execute (self):
|
||||||
|
import sys, os, time
|
||||||
|
args = self.args[1:]
|
||||||
|
if args:
|
||||||
|
mode = ''
|
||||||
|
for arg in args:
|
||||||
|
if arg in ('-l', '-e', '-x', '-h', '--help', '--'):
|
||||||
|
mode = arg
|
||||||
|
break
|
||||||
|
elif arg in ('-I', '-i'):
|
||||||
|
mode = arg
|
||||||
|
elif arg[:1] != '-':
|
||||||
|
break
|
||||||
|
if mode:
|
||||||
|
cmd = '"%s" "%s" '%(PATH_LUA, PATH_ZLUA)
|
||||||
|
if mode in ('-I', '-i', '--'):
|
||||||
|
cmd += ' --cd'
|
||||||
|
for arg in args:
|
||||||
|
cmd += ' "%s"'%arg
|
||||||
|
if mode in ('-e', '-x'):
|
||||||
|
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
||||||
|
path = path.decode("utf-8", "ignore")
|
||||||
|
path = path.rstrip('\n')
|
||||||
|
self.fm.notify(path)
|
||||||
|
elif mode in ('-h', '-l', '--help'):
|
||||||
|
p = self.fm.execute_command(cmd + '| less +G', universal_newlines=True)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
elif mode == '--':
|
||||||
|
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
else:
|
||||||
|
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
path = stdout.rstrip('\n')
|
||||||
|
self.fm.execute_console('redraw_window')
|
||||||
|
if path and os.path.exists(path):
|
||||||
|
self.fm.cd(path)
|
||||||
|
else:
|
||||||
|
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
||||||
|
path = path.decode("utf-8", "ignore")
|
||||||
|
path = path.rstrip('\n')
|
||||||
|
if path and os.path.exists(path):
|
||||||
|
self.fm.cd(path)
|
||||||
|
else:
|
||||||
|
self.fm.notify('No matching found', bad = True)
|
||||||
|
return True
|
||||||
|
|
||||||
22
z.cmd
@@ -54,6 +54,12 @@ if /i "%1"=="-x" (
|
|||||||
goto parse
|
goto parse
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if /i "%1"=="--add" (
|
||||||
|
set "RunMode=--add"
|
||||||
|
shift /1
|
||||||
|
goto parse
|
||||||
|
)
|
||||||
|
|
||||||
if "%1"=="-i" (
|
if "%1"=="-i" (
|
||||||
set "InterMode=-i"
|
set "InterMode=-i"
|
||||||
shift /1
|
shift /1
|
||||||
@@ -100,13 +106,27 @@ 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%"
|
||||||
|
set "CDCmd=cd /d"
|
||||||
|
if /i not "%_ZL_CD%"=="" (
|
||||||
|
set "CDCmd=%_ZL_CD%"
|
||||||
|
)
|
||||||
|
endlocal & popd & %CDCmd% "%NewPath%"
|
||||||
|
|
||||||
:end
|
:end
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
|
|||||||
528
z.lua
@@ -1,10 +1,10 @@
|
|||||||
#! /usr/bin/env lua
|
#! /usr/bin/env lua
|
||||||
--=====================================================================
|
--=====================================================================
|
||||||
--
|
--
|
||||||
-- z.lua - a cd command that learns, by skywind 2018, 2019
|
-- z.lua - a cd command that learns, by skywind 2018-2022
|
||||||
-- Licensed under MIT license.
|
-- Licensed under MIT license.
|
||||||
--
|
--
|
||||||
-- Version 1.5.2, Last Modified: 2019/02/16 14:25
|
-- Version 1.8.16, Last Modified: 2022/07/21 22:12
|
||||||
--
|
--
|
||||||
-- * 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).
|
||||||
@@ -74,6 +78,8 @@
|
|||||||
-- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
|
-- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
|
||||||
-- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
|
-- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
|
||||||
-- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear.
|
-- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear.
|
||||||
|
-- set $_ZL_USE_LFS to 1 to use lua-filesystem package
|
||||||
|
-- set $_ZL_HYPHEN to 1 to stop treating hyphen as a regexp keyword
|
||||||
--
|
--
|
||||||
--=====================================================================
|
--=====================================================================
|
||||||
|
|
||||||
@@ -120,6 +126,7 @@ Z_CMD = 'z'
|
|||||||
Z_MATCHMODE = 0
|
Z_MATCHMODE = 0
|
||||||
Z_MATCHNAME = false
|
Z_MATCHNAME = false
|
||||||
Z_SKIPPWD = false
|
Z_SKIPPWD = false
|
||||||
|
Z_HYPHEN = false
|
||||||
|
|
||||||
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
|
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
|
||||||
|
|
||||||
@@ -158,6 +165,10 @@ function string:startswith(text)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function string:endswith(text)
|
||||||
|
return text == "" or self:sub(-#text) == text
|
||||||
|
end
|
||||||
|
|
||||||
function string:lstrip()
|
function string:lstrip()
|
||||||
if self == nil then return nil end
|
if self == nil then return nil end
|
||||||
local s = self:gsub('^%s+', '')
|
local s = self:gsub('^%s+', '')
|
||||||
@@ -298,10 +309,124 @@ function os.log(text)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
-- ffi optimize (luajit has builtin ffi module)
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
os.native = {}
|
||||||
|
os.native.status, os.native.ffi = pcall(require, "ffi")
|
||||||
|
if os.native.status then
|
||||||
|
local ffi = os.native.ffi
|
||||||
|
if windows then
|
||||||
|
ffi.cdef[[
|
||||||
|
int GetFullPathNameA(const char *name, uint32_t size, char *out, char **name);
|
||||||
|
int ReplaceFileA(const char *dstname, const char *srcname, void *, uint32_t, void *, void *);
|
||||||
|
uint32_t GetTickCount(void);
|
||||||
|
uint32_t GetFileAttributesA(const char *name);
|
||||||
|
uint32_t GetCurrentDirectoryA(uint32_t size, char *ptr);
|
||||||
|
uint32_t GetShortPathNameA(const char *longname, char *shortname, uint32_t size);
|
||||||
|
uint32_t GetLongPathNameA(const char *shortname, char *longname, uint32_t size);
|
||||||
|
]]
|
||||||
|
local kernel32 = ffi.load('kernel32.dll')
|
||||||
|
local buffer = ffi.new('char[?]', 4100)
|
||||||
|
local INVALID_FILE_ATTRIBUTES = 0xffffffff
|
||||||
|
local FILE_ATTRIBUTE_DIRECTORY = 0x10
|
||||||
|
os.native.kernel32 = kernel32
|
||||||
|
function os.native.GetFullPathName(name)
|
||||||
|
local hr = kernel32.GetFullPathNameA(name, 4096, buffer, nil)
|
||||||
|
return (hr > 0) and ffi.string(buffer, hr) or nil
|
||||||
|
end
|
||||||
|
function os.native.ReplaceFile(replaced, replacement)
|
||||||
|
local hr = kernel32.ReplaceFileA(replaced, replacement, nil, 2, nil, nil)
|
||||||
|
return (hr ~= 0) and true or false
|
||||||
|
end
|
||||||
|
function os.native.GetTickCount()
|
||||||
|
return kernel32.GetTickCount()
|
||||||
|
end
|
||||||
|
function os.native.GetFileAttributes(name)
|
||||||
|
return kernel32.GetFileAttributesA(name)
|
||||||
|
end
|
||||||
|
function os.native.GetLongPathName(name)
|
||||||
|
local hr = kernel32.GetLongPathNameA(name, buffer, 4096)
|
||||||
|
return (hr ~= 0) and ffi.string(buffer, hr) or nil
|
||||||
|
end
|
||||||
|
function os.native.GetShortPathName(name)
|
||||||
|
local hr = kernel32.GetShortPathNameA(name, buffer, 4096)
|
||||||
|
return (hr ~= 0) and ffi.string(buffer, hr) or nil
|
||||||
|
end
|
||||||
|
function os.native.GetRealPathName(name)
|
||||||
|
local short = os.native.GetShortPathName(name)
|
||||||
|
if short then
|
||||||
|
return os.native.GetLongPathName(short)
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
function os.native.exists(name)
|
||||||
|
local attr = os.native.GetFileAttributes(name)
|
||||||
|
return attr ~= INVALID_FILE_ATTRIBUTES
|
||||||
|
end
|
||||||
|
function os.native.isdir(name)
|
||||||
|
local attr = os.native.GetFileAttributes(name)
|
||||||
|
local isdir = FILE_ATTRIBUTE_DIRECTORY
|
||||||
|
if attr == INVALID_FILE_ATTRIBUTES then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return (attr % (2 * isdir)) >= isdir
|
||||||
|
end
|
||||||
|
function os.native.getcwd()
|
||||||
|
local hr = kernel32.GetCurrentDirectoryA(4096, buffer)
|
||||||
|
if hr <= 0 then return nil end
|
||||||
|
return ffi.string(buffer, hr)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ffi.cdef[[
|
||||||
|
typedef struct { long tv_sec; long tv_usec; } timeval;
|
||||||
|
int gettimeofday(timeval *tv, void *tz);
|
||||||
|
int access(const char *name, int mode);
|
||||||
|
char *realpath(const char *path, char *resolve);
|
||||||
|
char *getcwd(char *buf, size_t size);
|
||||||
|
]]
|
||||||
|
local timeval = ffi.new('timeval[?]', 1)
|
||||||
|
local buffer = ffi.new('char[?]', 4100)
|
||||||
|
function os.native.gettimeofday()
|
||||||
|
local hr = ffi.C.gettimeofday(timeval, nil)
|
||||||
|
local sec = tonumber(timeval[0].tv_sec)
|
||||||
|
local usec = tonumber(timeval[0].tv_usec)
|
||||||
|
return sec + (usec * 0.000001)
|
||||||
|
end
|
||||||
|
function os.native.access(name, mode)
|
||||||
|
return ffi.C.access(name, mode)
|
||||||
|
end
|
||||||
|
function os.native.realpath(name)
|
||||||
|
local path = ffi.C.realpath(name, buffer)
|
||||||
|
return (path ~= nil) and ffi.string(buffer) or nil
|
||||||
|
end
|
||||||
|
function os.native.getcwd()
|
||||||
|
local hr = ffi.C.getcwd(buffer, 4099)
|
||||||
|
return hr ~= nil and ffi.string(buffer) or nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function os.native.tickcount()
|
||||||
|
if windows then
|
||||||
|
return os.native.GetTickCount()
|
||||||
|
else
|
||||||
|
return math.floor(os.native.gettimeofday() * 1000)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
os.native.init = true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- get current path
|
-- get current path
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function os.pwd()
|
function os.pwd()
|
||||||
|
if os.native and os.native.getcwd then
|
||||||
|
local hr = os.native.getcwd()
|
||||||
|
if hr then return hr end
|
||||||
|
end
|
||||||
|
if os.getcwd then
|
||||||
|
return os.getcwd()
|
||||||
|
end
|
||||||
if windows then
|
if windows then
|
||||||
local fp = io.popen('cd')
|
local fp = io.popen('cd')
|
||||||
if fp == nil then
|
if fp == nil then
|
||||||
@@ -368,6 +493,10 @@ end
|
|||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function os.path.abspath(path)
|
function os.path.abspath(path)
|
||||||
if path == '' then path = '.' end
|
if path == '' then path = '.' end
|
||||||
|
if os.native and os.native.GetFullPathName then
|
||||||
|
local test = os.native.GetFullPathName(path)
|
||||||
|
if test then return test end
|
||||||
|
end
|
||||||
if windows then
|
if windows then
|
||||||
local script = 'FOR /f "delims=" %%i IN ("%s") DO @echo %%~fi'
|
local script = 'FOR /f "delims=" %%i IN ("%s") DO @echo %%~fi'
|
||||||
local script = string.format(script, path)
|
local script = string.format(script, path)
|
||||||
@@ -398,13 +527,16 @@ function os.path.abspath(path)
|
|||||||
return test
|
return test
|
||||||
end
|
end
|
||||||
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 = 'sys.stdout.write(os.path.abspath(sys.argv[1]))'
|
||||||
local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\''
|
local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\''
|
||||||
local s = python .. ' ' .. s
|
local s = python .. ' ' .. s
|
||||||
local test = os.path.which(python)
|
local test = os.path.which(python)
|
||||||
if test ~= nil and test ~= '' then
|
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
|
end
|
||||||
end
|
end
|
||||||
@@ -418,22 +550,24 @@ end
|
|||||||
function os.path.isdir(pathname)
|
function os.path.isdir(pathname)
|
||||||
if pathname == '/' then
|
if pathname == '/' then
|
||||||
return true
|
return true
|
||||||
|
elseif pathname == '' then
|
||||||
|
return false
|
||||||
elseif windows then
|
elseif windows then
|
||||||
if pathname == '\\' then
|
if pathname == '\\' then
|
||||||
return true
|
return true
|
||||||
elseif pathname:match('^%a:[/\\]$') then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local name = pathname .. '/'
|
if os.native and os.native.isdir then
|
||||||
local ok, err, code = os.rename(name, name)
|
return os.native.isdir(pathname)
|
||||||
if not ok then
|
|
||||||
if code == 13 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
return true
|
if clink and os.isdir then
|
||||||
|
return os.isdir(pathname)
|
||||||
|
end
|
||||||
|
local name = pathname
|
||||||
|
if (not name:endswith('/')) and (not name:endswith('\\')) then
|
||||||
|
name = name .. os.path.sep
|
||||||
|
end
|
||||||
|
return os.path.exists(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -441,10 +575,28 @@ end
|
|||||||
-- file or path exists
|
-- file or path exists
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function os.path.exists(name)
|
function os.path.exists(name)
|
||||||
|
if name == '/' then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if os.native and os.native.exists then
|
||||||
|
return os.native.exists(name)
|
||||||
|
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
|
||||||
|
local f = io.open(name,"r")
|
||||||
|
if f ~= nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif name:sub(-1) == '/' and code == 20 and (not windows) then
|
||||||
|
local test = name .. '.'
|
||||||
|
ok, err, code = os.rename(test, test)
|
||||||
|
if code == 16 or code == 13 or code == 22 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -757,6 +909,41 @@ function os.scriptname()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
-- get environ
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
function os.environ(name, default)
|
||||||
|
local value = os.getenv(name)
|
||||||
|
if os.envmap ~= nil and type(os.envmap) == 'table' then
|
||||||
|
local t = os.envmap[name]
|
||||||
|
value = (t ~= nil and type(t) == 'string') and t or value
|
||||||
|
end
|
||||||
|
if value == nil then
|
||||||
|
return default
|
||||||
|
elseif type(default) == 'boolean' then
|
||||||
|
value = value:lower()
|
||||||
|
if value == '0' or value == '' or value == 'no' then
|
||||||
|
return false
|
||||||
|
elseif value == 'false' or value == 'n' or value == 'f' then
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif type(default) == 'number' then
|
||||||
|
value = tonumber(value)
|
||||||
|
if value == nil then
|
||||||
|
return default
|
||||||
|
else
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
elseif type(default) == 'string' then
|
||||||
|
return value
|
||||||
|
elseif type(default) == 'table' then
|
||||||
|
return value:sep(',')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- parse option
|
-- parse option
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
@@ -824,6 +1011,9 @@ function math.random_init()
|
|||||||
seed = seed .. rnd
|
seed = seed .. rnd
|
||||||
end
|
end
|
||||||
seed = seed .. tostring(os.clock() * 10000000)
|
seed = seed .. tostring(os.clock() * 10000000)
|
||||||
|
if os.native and os.native.tickcount then
|
||||||
|
seed = seed .. tostring(os.native.tickcount())
|
||||||
|
end
|
||||||
local number = 0
|
local number = 0
|
||||||
for i = 1, seed:len() do
|
for i = 1, seed:len() do
|
||||||
local k = string.byte(seed:sub(i, i))
|
local k = string.byte(seed:sub(i, i))
|
||||||
@@ -913,15 +1103,29 @@ function data_save(filename, M)
|
|||||||
local tmpname = nil
|
local tmpname = nil
|
||||||
local i
|
local i
|
||||||
filename = os.path.expand(filename)
|
filename = os.path.expand(filename)
|
||||||
if windows then
|
math.random_init()
|
||||||
fp = io.open(filename, 'w')
|
while true do
|
||||||
else
|
|
||||||
math.random_init()
|
|
||||||
tmpname = filename .. '.' .. tostring(os.time())
|
tmpname = filename .. '.' .. tostring(os.time())
|
||||||
tmpname = tmpname .. math.random_string(8)
|
if os.native and os.native.tickcount then
|
||||||
local rnd = os.getenv('_ZL_RANDOM')
|
local key = os.native.tickcount() % 1000
|
||||||
tmpname = tmpname .. '' .. (rnd and rnd or '')
|
tmpname = tmpname .. string.format('%03d', key)
|
||||||
-- print('tmpname: '..tmpname)
|
tmpname = tmpname .. math.random_string(5)
|
||||||
|
else
|
||||||
|
tmpname = tmpname .. math.random_string(8)
|
||||||
|
end
|
||||||
|
if not os.path.exists(tmpname) then
|
||||||
|
-- print('tmpname: '..tmpname)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if windows then
|
||||||
|
if os.native and os.native.ReplaceFile then
|
||||||
|
fp = io.open(tmpname, 'w')
|
||||||
|
else
|
||||||
|
fp = io.open(filename, 'w')
|
||||||
|
tmpname = nil
|
||||||
|
end
|
||||||
|
else
|
||||||
fp = io.open(tmpname, 'w')
|
fp = io.open(tmpname, 'w')
|
||||||
end
|
end
|
||||||
if fp == nil then
|
if fp == nil then
|
||||||
@@ -934,7 +1138,14 @@ function data_save(filename, M)
|
|||||||
end
|
end
|
||||||
fp:close()
|
fp:close()
|
||||||
if tmpname ~= nil then
|
if tmpname ~= nil then
|
||||||
os.rename(tmpname, filename)
|
if windows then
|
||||||
|
local ok, err, code = os.rename(tmpname, filename)
|
||||||
|
if not ok then
|
||||||
|
os.native.ReplaceFile(filename, tmpname)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
os.rename(tmpname, filename)
|
||||||
|
end
|
||||||
os.remove(tmpname)
|
os.remove(tmpname)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
@@ -1085,6 +1296,9 @@ function data_select(M, patterns, matchlast)
|
|||||||
local pats = {}
|
local pats = {}
|
||||||
for i = 1, #patterns do
|
for i = 1, #patterns do
|
||||||
local p = patterns[i]
|
local p = patterns[i]
|
||||||
|
if Z_HYPHEN then
|
||||||
|
p = p:gsub('-', '%%-')
|
||||||
|
end
|
||||||
table.insert(pats, case_insensitive_pattern(p))
|
table.insert(pats, case_insensitive_pattern(p))
|
||||||
end
|
end
|
||||||
for i = 1, #M do
|
for i = 1, #M do
|
||||||
@@ -1170,6 +1384,14 @@ function z_add(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not skip then
|
if not skip then
|
||||||
|
if windows then
|
||||||
|
if os.native and os.native.GetRealPathName then
|
||||||
|
local ts = os.native.GetRealPathName(path)
|
||||||
|
if ts then
|
||||||
|
path = ts
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
M = data_insert(M, path)
|
M = data_insert(M, path)
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
@@ -1235,13 +1457,14 @@ function z_match(patterns, method, subdir)
|
|||||||
subdir = subdir ~= nil and subdir or false
|
subdir = subdir ~= nil and subdir or false
|
||||||
local M = data_load(DATA_FILE)
|
local M = data_load(DATA_FILE)
|
||||||
M = data_select(M, patterns, false)
|
M = data_select(M, patterns, false)
|
||||||
|
M = data_filter(M)
|
||||||
if Z_MATCHNAME then
|
if Z_MATCHNAME then
|
||||||
local N = data_select(M, patterns, true)
|
local N = data_select(M, patterns, true)
|
||||||
|
N = data_filter(N)
|
||||||
if #N > 0 then
|
if #N > 0 then
|
||||||
M = N
|
M = N
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
M = data_filter(M)
|
|
||||||
M = data_update_frecent(M)
|
M = data_update_frecent(M)
|
||||||
if method == 'time' then
|
if method == 'time' then
|
||||||
current = os.time()
|
current = os.time()
|
||||||
@@ -1294,7 +1517,7 @@ end
|
|||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function z_print(M, weight, number)
|
function z_print(M, weight, number)
|
||||||
local N = {}
|
local N = {}
|
||||||
local maxsize = 10
|
local maxsize = 9
|
||||||
local numsize = string.len(tostring(#M))
|
local numsize = string.len(tostring(#M))
|
||||||
for _, item in pairs(M) do
|
for _, item in pairs(M) do
|
||||||
local record = {}
|
local record = {}
|
||||||
@@ -1387,6 +1610,9 @@ function z_cd(patterns)
|
|||||||
elseif Z_INTERACTIVE == 0 then
|
elseif Z_INTERACTIVE == 0 then
|
||||||
return M[1].name
|
return M[1].name
|
||||||
end
|
end
|
||||||
|
if os.environ('_ZL_INT_SORT', false) then
|
||||||
|
table.sort(M, function (a, b) return a.name < b.name end)
|
||||||
|
end
|
||||||
local retval = nil
|
local retval = nil
|
||||||
if Z_INTERACTIVE == 1 then
|
if Z_INTERACTIVE == 1 then
|
||||||
PRINT_MODE = '<stderr>'
|
PRINT_MODE = '<stderr>'
|
||||||
@@ -1394,7 +1620,7 @@ function z_cd(patterns)
|
|||||||
io.stderr:write('> ')
|
io.stderr:write('> ')
|
||||||
io.stderr:flush()
|
io.stderr:flush()
|
||||||
local input = io.read('*l')
|
local input = io.read('*l')
|
||||||
if input == nil then
|
if input == nil or input == '' then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local index = tonumber(input)
|
local index = tonumber(input)
|
||||||
@@ -1406,19 +1632,22 @@ function z_cd(patterns)
|
|||||||
end
|
end
|
||||||
retval = M[index].name
|
retval = M[index].name
|
||||||
elseif Z_INTERACTIVE == 2 then
|
elseif Z_INTERACTIVE == 2 then
|
||||||
local fzf = os.getenv('_ZL_FZF')
|
local fzf = os.environ('_ZL_FZF', 'fzf')
|
||||||
local tmpname = '/tmp/zlua.txt'
|
local tmpname = '/tmp/zlua.txt'
|
||||||
local cmd = '--nth 2.. --reverse --inline-info +s --tac'
|
local cmd = '--nth 2.. --reverse --info=inline --tac '
|
||||||
local cmd = ((not fzf) and 'fzf' or fzf) .. ' ' .. cmd
|
local flag = os.environ('_ZL_FZF_FLAG', '')
|
||||||
|
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
||||||
|
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
|
||||||
if not windows then
|
if not windows then
|
||||||
tmpname = os.tmpname()
|
tmpname = os.tmpname()
|
||||||
if not os.getenv('_ZL_FZF_FULLSCR') then
|
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
||||||
cmd = cmd .. ' --height 35%'
|
if height ~= nil and height ~= '' and height ~= '0' then
|
||||||
|
cmd = cmd .. ' --height ' .. height
|
||||||
end
|
end
|
||||||
cmd = cmd .. ' < "' .. tmpname .. '"'
|
cmd = cmd .. ' < "' .. tmpname .. '"'
|
||||||
else
|
else
|
||||||
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
|
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
|
||||||
tmpname = os.getenv('TMP') .. '\\zlua_' .. tmpname .. '.txt'
|
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
||||||
cmd = 'type "' .. tmpname .. '" | ' .. cmd
|
cmd = 'type "' .. tmpname .. '" | ' .. cmd
|
||||||
end
|
end
|
||||||
PRINT_MODE = tmpname
|
PRINT_MODE = tmpname
|
||||||
@@ -1505,6 +1734,7 @@ function cd_backward(args, options, pwd)
|
|||||||
end
|
end
|
||||||
return os.path.normpath(path)
|
return os.path.normpath(path)
|
||||||
else
|
else
|
||||||
|
pwd = os.path.split(pwd)
|
||||||
local test = windows and pwd:gsub('\\', '/') or pwd
|
local test = windows and pwd:gsub('\\', '/') or pwd
|
||||||
local key = windows and args[1]:lower() or args[1]
|
local key = windows and args[1]:lower() or args[1]
|
||||||
if not key:match('%u') then
|
if not key:match('%u') then
|
||||||
@@ -1572,6 +1802,91 @@ function cd_minus(args, options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
-- cd breadcrumbs: z -b -i, z -b -I
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
function cd_breadcrumbs(pwd, interactive)
|
||||||
|
local pwd = (pwd == nil or pwd == '') and os.pwd() or pwd
|
||||||
|
local pwd = os.path.normpath(pwd)
|
||||||
|
local path, _ = os.path.split(pwd)
|
||||||
|
local elements = {}
|
||||||
|
local interactive = interactive and interactive or 1
|
||||||
|
local fullname = os.environ('_ZL_FULL_PATH', false)
|
||||||
|
while true do
|
||||||
|
local head, name = os.path.split(path)
|
||||||
|
if head == path then -- reached root
|
||||||
|
table.insert(elements, {head, head})
|
||||||
|
break
|
||||||
|
elseif name ~= '' then
|
||||||
|
table.insert(elements, {name, path})
|
||||||
|
else
|
||||||
|
break
|
||||||
|
end
|
||||||
|
path = head
|
||||||
|
end
|
||||||
|
local tmpname = '/tmp/zlua.txt'
|
||||||
|
local fp = io.stderr
|
||||||
|
if interactive == 2 then
|
||||||
|
if not windows then
|
||||||
|
tmpname = os.tmpname()
|
||||||
|
else
|
||||||
|
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
|
||||||
|
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
|
||||||
|
end
|
||||||
|
fp = io.open(tmpname, 'w')
|
||||||
|
end
|
||||||
|
-- print table
|
||||||
|
local maxsize = string.len(tostring(#elements))
|
||||||
|
for i = #elements, 1, -1 do
|
||||||
|
local item = elements[i]
|
||||||
|
local name = item[1]
|
||||||
|
local text = string.rep(' ', maxsize - string.len(i)) .. tostring(i)
|
||||||
|
text = text .. ': ' .. (fullname and item[2] or item[1])
|
||||||
|
fp:write(text .. '\n')
|
||||||
|
end
|
||||||
|
if fp ~= io.stderr then
|
||||||
|
fp:close()
|
||||||
|
end
|
||||||
|
local retval = ''
|
||||||
|
-- select from stdin or fzf
|
||||||
|
if interactive == 1 then
|
||||||
|
io.stderr:write('> ')
|
||||||
|
io.stderr:flush()
|
||||||
|
retval = io.read('*l')
|
||||||
|
elseif interactive == 2 then
|
||||||
|
local fzf = os.environ('_ZL_FZF', 'fzf')
|
||||||
|
local cmd = '--reverse --info=inline --tac '
|
||||||
|
local flag = os.environ('_ZL_FZF_FLAG', '')
|
||||||
|
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
||||||
|
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
|
||||||
|
if not windows then
|
||||||
|
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 .. '"'
|
||||||
|
else
|
||||||
|
cmd = 'type "' .. tmpname .. '" | ' .. cmd
|
||||||
|
end
|
||||||
|
retval = os.call(cmd)
|
||||||
|
os.remove(tmpname)
|
||||||
|
if retval == '' or retval == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local pos = retval:find(':')
|
||||||
|
if not pos then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
retval = retval:sub(1, pos - 1):gsub('^%s*', '')
|
||||||
|
end
|
||||||
|
local index = tonumber(retval)
|
||||||
|
if index == nil or index < 1 or index > #elements then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
return elements[index][2]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- main entry
|
-- main entry
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
@@ -1606,7 +1921,11 @@ function main(argv)
|
|||||||
if options['--cd'] or options['-e'] then
|
if options['--cd'] or options['-e'] then
|
||||||
local path = ''
|
local path = ''
|
||||||
if options['-b'] then
|
if options['-b'] then
|
||||||
path = cd_backward(args, options)
|
if Z_INTERACTIVE == 0 then
|
||||||
|
path = cd_backward(args, options)
|
||||||
|
else
|
||||||
|
path = cd_breadcrumbs('', Z_INTERACTIVE)
|
||||||
|
end
|
||||||
elseif options['-'] then
|
elseif options['-'] then
|
||||||
path = cd_minus(args, options)
|
path = cd_minus(args, options)
|
||||||
elseif #args == 0 then
|
elseif #args == 0 then
|
||||||
@@ -1643,6 +1962,8 @@ function main(argv)
|
|||||||
z_windows_init(opts)
|
z_windows_init(opts)
|
||||||
elseif opts.fish then
|
elseif opts.fish then
|
||||||
z_fish_init(opts)
|
z_fish_init(opts)
|
||||||
|
elseif opts.powershell then
|
||||||
|
z_windows_init(opts)
|
||||||
else
|
else
|
||||||
z_shell_init(opts)
|
z_shell_init(opts)
|
||||||
end
|
end
|
||||||
@@ -1678,16 +1999,14 @@ function z_init()
|
|||||||
local _zl_matchname = os.getenv('_ZL_MATCH_NAME')
|
local _zl_matchname = os.getenv('_ZL_MATCH_NAME')
|
||||||
local _zl_skippwd = os.getenv('_ZL_SKIP_PWD')
|
local _zl_skippwd = os.getenv('_ZL_SKIP_PWD')
|
||||||
local _zl_matchmode = os.getenv('_ZL_MATCH_MODE')
|
local _zl_matchmode = os.getenv('_ZL_MATCH_MODE')
|
||||||
|
local _zl_hyphen = os.getenv('_ZL_HYPHEN')
|
||||||
if _zl_data ~= nil and _zl_data ~= "" then
|
if _zl_data ~= nil and _zl_data ~= "" then
|
||||||
if windows then
|
if windows then
|
||||||
DATA_FILE = _zl_data
|
DATA_FILE = _zl_data
|
||||||
else
|
else
|
||||||
-- avoid windows environments affect cygwin & msys
|
-- avoid windows environments affect cygwin & msys
|
||||||
if _zl_data:sub(2, 2) ~= ':' then
|
if not string.match(_zl_data, '^%a:[/\\]') then
|
||||||
local t = _zl_data:sub(3, 3)
|
DATA_FILE = _zl_data
|
||||||
if t ~= '/' and t ~= "\\" then
|
|
||||||
DATA_FILE = _zl_data
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1710,7 +2029,7 @@ function z_init()
|
|||||||
table.insert(Z_EXCLUDE, name)
|
table.insert(Z_EXCLUDE, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if _zl_cmd ~= nil then
|
if _zl_cmd ~= nil and _zl_cmd ~= '' then
|
||||||
Z_CMD = _zl_cmd
|
Z_CMD = _zl_cmd
|
||||||
end
|
end
|
||||||
if _zl_matchname ~= nil then
|
if _zl_matchname ~= nil then
|
||||||
@@ -1733,6 +2052,12 @@ function z_init()
|
|||||||
Z_SKIPPWD = true
|
Z_SKIPPWD = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if _zl_hyphen ~= nil then
|
||||||
|
local m = string.lower(_zl_hyphen)
|
||||||
|
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
|
||||||
|
Z_HYPHEN = true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -1740,7 +2065,8 @@ end
|
|||||||
-- initialize clink hooks
|
-- initialize clink hooks
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function z_clink_init()
|
function z_clink_init()
|
||||||
local once = os.getenv("_ZL_ADD_ONCE")
|
local once = os.environ("_ZL_ADD_ONCE", false)
|
||||||
|
local _zl_clink_prompt_priority = os.environ('_ZL_CLINK_PROMPT_PRIORITY', 99)
|
||||||
local previous = ''
|
local previous = ''
|
||||||
function z_add_to_database()
|
function z_add_to_database()
|
||||||
pwd = clink.get_cwd()
|
pwd = clink.get_cwd()
|
||||||
@@ -1752,7 +2078,7 @@ function z_clink_init()
|
|||||||
end
|
end
|
||||||
z_add(clink.get_cwd())
|
z_add(clink.get_cwd())
|
||||||
end
|
end
|
||||||
clink.prompt.register_filter(z_add_to_database, 99)
|
clink.prompt.register_filter(z_add_to_database, _zl_clink_prompt_priority)
|
||||||
function z_match_completion(word)
|
function z_match_completion(word)
|
||||||
local M = z_match({word}, Z_METHOD, Z_SUBDIR)
|
local M = z_match({word}, Z_METHOD, Z_SUBDIR)
|
||||||
for _, item in pairs(M) do
|
for _, item in pairs(M) do
|
||||||
@@ -1762,6 +2088,8 @@ function z_clink_init()
|
|||||||
end
|
end
|
||||||
local z_parser = clink.arg.new_parser()
|
local z_parser = clink.arg.new_parser()
|
||||||
z_parser:set_arguments({ z_match_completion })
|
z_parser:set_arguments({ z_match_completion })
|
||||||
|
z_parser:set_flags("-c", "-r", "-i", "--cd", "-e", "-b", "--add", "-x", "--purge",
|
||||||
|
"--init", "-l", "-s", "--complete", "--help", "-h")
|
||||||
clink.arg.register_parser("z", z_parser)
|
clink.arg.register_parser("z", z_parser)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1827,14 +2155,14 @@ alias ${_ZL_CMD:-z}='_zlua'
|
|||||||
local script_init_bash = [[
|
local script_init_bash = [[
|
||||||
case "$PROMPT_COMMAND" in
|
case "$PROMPT_COMMAND" in
|
||||||
*_zlua?--add*) ;;
|
*_zlua?--add*) ;;
|
||||||
*) PROMPT_COMMAND="(_zlua --add \"\$(command pwd 2>/dev/null)\" &);$PROMPT_COMMAND" ;;
|
*) PROMPT_COMMAND="(_zlua --add \"\$(command pwd 2>/dev/null)\" &)${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||||
esac
|
esac
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local script_init_bash_fast = [[
|
local script_init_bash_fast = [[
|
||||||
case "$PROMPT_COMMAND" in
|
case "$PROMPT_COMMAND" in
|
||||||
*_zlua?--add*) ;;
|
*_zlua?--add*) ;;
|
||||||
*) PROMPT_COMMAND="(_zlua --add \"\$PWD\" &);$PROMPT_COMMAND" ;;
|
*) PROMPT_COMMAND="(_zlua --add \"\$PWD\" &)${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||||
esac
|
esac
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -1846,7 +2174,7 @@ _zlua_precmd() {
|
|||||||
}
|
}
|
||||||
case "$PROMPT_COMMAND" in
|
case "$PROMPT_COMMAND" in
|
||||||
*_zlua_precmd*) ;;
|
*_zlua_precmd*) ;;
|
||||||
*) PROMPT_COMMAND="_zlua_precmd;$PROMPT_COMMAND" ;;
|
*) PROMPT_COMMAND="_zlua_precmd${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||||
esac
|
esac
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -1873,7 +2201,7 @@ local script_init_zsh = [[
|
|||||||
_zlua_precmd() {
|
_zlua_precmd() {
|
||||||
(_zlua --add "${PWD:a}" &)
|
(_zlua --add "${PWD:a}" &)
|
||||||
}
|
}
|
||||||
typeset -gaU precmd_functions
|
typeset -ga precmd_functions
|
||||||
[ -n "${precmd_functions[(r)_zlua_precmd]}" ] || {
|
[ -n "${precmd_functions[(r)_zlua_precmd]}" ] || {
|
||||||
precmd_functions[$(($#precmd_functions+1))]=_zlua_precmd
|
precmd_functions[$(($#precmd_functions+1))]=_zlua_precmd
|
||||||
}
|
}
|
||||||
@@ -1883,7 +2211,7 @@ local script_init_zsh_once = [[
|
|||||||
_zlua_precmd() {
|
_zlua_precmd() {
|
||||||
(_zlua --add "${PWD:a}" &)
|
(_zlua --add "${PWD:a}" &)
|
||||||
}
|
}
|
||||||
typeset -gaU chpwd_functions
|
typeset -ga chpwd_functions
|
||||||
[ -n "${chpwd_functions[(r)_zlua_precmd]}" ] || {
|
[ -n "${chpwd_functions[(r)_zlua_precmd]}" ] || {
|
||||||
chpwd_functions[$(($#chpwd_functions+1))]=_zlua_precmd
|
chpwd_functions[$(($#chpwd_functions+1))]=_zlua_precmd
|
||||||
}
|
}
|
||||||
@@ -1913,16 +2241,16 @@ fi
|
|||||||
local script_complete_zsh = [[
|
local script_complete_zsh = [[
|
||||||
_zlua_zsh_tab_completion() {
|
_zlua_zsh_tab_completion() {
|
||||||
# tab completion
|
# tab completion
|
||||||
local compl
|
|
||||||
read -l compl
|
|
||||||
(( $+compstate )) && compstate[insert]=menu # no expand
|
(( $+compstate )) && compstate[insert]=menu # no expand
|
||||||
reply=(${(f)"$(_zlua --complete "$compl")"})
|
local -a tmp=(${(f)"$(_zlua --complete "${words/_zlua/z}")"})
|
||||||
|
_describe "directory" tmp -U
|
||||||
}
|
}
|
||||||
compctl -U -K _zlua_zsh_tab_completion _zlua
|
if [ "${+functions[compdef]}" -ne 0 ]; then
|
||||||
|
compdef _zlua_zsh_tab_completion _zlua 2> /dev/null
|
||||||
|
fi
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- initialize bash/zsh
|
-- initialize bash/zsh
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
@@ -1940,12 +2268,16 @@ function z_shell_init(opts)
|
|||||||
print(script)
|
print(script)
|
||||||
end
|
end
|
||||||
|
|
||||||
local prompt_hook = (os.getenv("_ZL_NO_PROMPT_COMMAND") == nil)
|
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
|
||||||
local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil
|
local once = os.environ("_ZL_ADD_ONCE", false) or opts.once ~= nil
|
||||||
|
|
||||||
|
if opts.clean ~= nil then
|
||||||
|
prompt_hook = false
|
||||||
|
end
|
||||||
|
|
||||||
if opts.bash ~= nil then
|
if opts.bash ~= nil then
|
||||||
if prompt_hook then
|
if prompt_hook then
|
||||||
if opts.once then
|
if once then
|
||||||
print(script_init_bash_once)
|
print(script_init_bash_once)
|
||||||
elseif opts.fast then
|
elseif opts.fast then
|
||||||
print(script_init_bash_fast)
|
print(script_init_bash_fast)
|
||||||
@@ -1955,10 +2287,14 @@ function z_shell_init(opts)
|
|||||||
end
|
end
|
||||||
print(script_complete_bash)
|
print(script_complete_bash)
|
||||||
if opts.fzf ~= nil then
|
if opts.fzf ~= nil then
|
||||||
fzf_cmd = "fzf --nth 2 --reverse --inline-info +s --tac"
|
fzf_cmd = "fzf --nth 2.. --reverse --info=inline --tac "
|
||||||
if not os.getenv('_ZL_FZF_FULLSCR') then
|
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
||||||
fzf_cmd = fzf_cmd .. ' --height 35%'
|
if height ~= nil and height ~= '' and height ~= '0' then
|
||||||
|
fzf_cmd = fzf_cmd .. ' --height ' .. height .. ' '
|
||||||
end
|
end
|
||||||
|
local flag = os.environ('_ZL_FZF_FLAG', '')
|
||||||
|
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
||||||
|
fzf_cmd = fzf_cmd .. ' ' .. flag .. ' '
|
||||||
print('zlua_fzf="' .. fzf_cmd .. '"')
|
print('zlua_fzf="' .. fzf_cmd .. '"')
|
||||||
print(script_fzf_complete_bash)
|
print(script_fzf_complete_bash)
|
||||||
end
|
end
|
||||||
@@ -2108,18 +2444,24 @@ function z_fish_init(opts)
|
|||||||
print('set -x ZLUA_SCRIPT "' .. os.scriptname() .. '"')
|
print('set -x ZLUA_SCRIPT "' .. os.scriptname() .. '"')
|
||||||
print('set -x ZLUA_LUAEXE "' .. os.interpreter() .. '"')
|
print('set -x ZLUA_LUAEXE "' .. os.interpreter() .. '"')
|
||||||
local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil
|
local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil
|
||||||
|
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
|
||||||
|
if opts.clean ~= nil then
|
||||||
|
prompt_hook = false
|
||||||
|
end
|
||||||
print(script_zlua_fish)
|
print(script_zlua_fish)
|
||||||
if once then
|
if prompt_hook then
|
||||||
print(script_init_fish_once)
|
if once then
|
||||||
else
|
print(script_init_fish_once)
|
||||||
print(script_init_fish)
|
else
|
||||||
|
print(script_init_fish)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
print(script_complete_fish)
|
print(script_complete_fish)
|
||||||
if opts.enhanced ~= nil then
|
if opts.enhanced ~= nil then
|
||||||
print('set -x _ZL_MATCH_MODE 1')
|
print('set -x _ZL_MATCH_MODE 1')
|
||||||
end
|
end
|
||||||
if opts.echo then
|
if opts.echo then
|
||||||
print('set _ZL_ECHO 1')
|
print('set -g _ZL_ECHO 1')
|
||||||
end
|
end
|
||||||
if opts.nc then
|
if opts.nc then
|
||||||
print('set -x _ZL_NO_CHECK 1')
|
print('set -x _ZL_NO_CHECK 1')
|
||||||
@@ -2170,6 +2512,11 @@ if /i "%1"=="-x" (
|
|||||||
shift /1
|
shift /1
|
||||||
goto parse
|
goto parse
|
||||||
)
|
)
|
||||||
|
if /i "%1"=="--add" (
|
||||||
|
set "RunMode=--add"
|
||||||
|
shift /1
|
||||||
|
goto parse
|
||||||
|
)
|
||||||
if "%1"=="-i" (
|
if "%1"=="-i" (
|
||||||
set "InterMode=-i"
|
set "InterMode=-i"
|
||||||
shift /1
|
shift /1
|
||||||
@@ -2208,12 +2555,22 @@ 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%"
|
||||||
|
set "CDCmd=cd /d"
|
||||||
|
if /i not "%_ZL_CD%"=="" (
|
||||||
|
set "CDCmd=%_ZL_CD%"
|
||||||
|
)
|
||||||
|
endlocal & popd & %CDCmd% "%NewPath%"
|
||||||
:end
|
:end
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -2302,6 +2659,10 @@ if (!$env:_ZL_NO_PROMPT_COMMAND -and (!$global:_zlua_inited)) {
|
|||||||
-- initialize cmd/powershell
|
-- initialize cmd/powershell
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function z_windows_init(opts)
|
function z_windows_init(opts)
|
||||||
|
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
|
||||||
|
if opts.clean ~= nil then
|
||||||
|
prompt_hook = false
|
||||||
|
end
|
||||||
if opts.powershell ~= nil then
|
if opts.powershell ~= nil then
|
||||||
print('$script:ZLUA_LUAEXE = "' .. os.interpreter() .. '"')
|
print('$script:ZLUA_LUAEXE = "' .. os.interpreter() .. '"')
|
||||||
print('$script:ZLUA_SCRIPT = "' .. os.scriptname() .. '"')
|
print('$script:ZLUA_SCRIPT = "' .. os.scriptname() .. '"')
|
||||||
@@ -2318,7 +2679,9 @@ function z_windows_init(opts)
|
|||||||
if opts.nc ~= nil then
|
if opts.nc ~= nil then
|
||||||
print('$env:_ZL_NO_CHECK = 1')
|
print('$env:_ZL_NO_CHECK = 1')
|
||||||
end
|
end
|
||||||
print(script_init_powershell)
|
if prompt_hook then
|
||||||
|
print(script_init_powershell)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
print('@echo off')
|
print('@echo off')
|
||||||
print('setlocal EnableDelayedExpansion')
|
print('setlocal EnableDelayedExpansion')
|
||||||
@@ -2352,7 +2715,34 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- testing case
|
-- LFS optimize
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
os.lfs = {}
|
||||||
|
os.lfs.enable = os.getenv('_ZL_USE_LFS')
|
||||||
|
os.lfs.enable = '1'
|
||||||
|
if os.lfs.enable ~= nil then
|
||||||
|
local m = string.lower(os.lfs.enable)
|
||||||
|
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
|
||||||
|
os.lfs.status, os.lfs.pkg = pcall(require, 'lfs')
|
||||||
|
if os.lfs.status then
|
||||||
|
local lfs = os.lfs.pkg
|
||||||
|
os.path.exists = function (name)
|
||||||
|
return lfs.attributes(name) and true or false
|
||||||
|
end
|
||||||
|
os.path.isdir = function (name)
|
||||||
|
local mode = lfs.attributes(name)
|
||||||
|
if not mode then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return (mode.mode == 'directory') and true or false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
-- program entry
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
if not pcall(debug.getlocal, 4, 1) then
|
if not pcall(debug.getlocal, 4, 1) then
|
||||||
-- main script
|
-- main script
|
||||||
@@ -2364,5 +2754,5 @@ if not pcall(debug.getlocal, 4, 1) then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- vim: set ts=4 sw=4 tw=0 noet :
|
||||||
|
|
||||||
|
|||||||
@@ -2,32 +2,34 @@
|
|||||||
|
|
||||||
ZLUA_SCRIPT="${0:A:h}/z.lua"
|
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
|
# search lua executable
|
||||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||||
if [[ -x "$(which lua)" ]]; then
|
for lua in lua luajit lua5.4 lua5.3 lua5.2 lua5.1; do
|
||||||
ZLUA_EXEC="$(which lua)"
|
ZLUA_EXEC="$(command -v "$lua")"
|
||||||
elif [[ -x "$(which lua5.3)" ]]; then
|
[[ -n "$ZLUA_EXEC" ]] && break
|
||||||
ZLUA_EXEC="$(which lua5.3)"
|
done
|
||||||
elif [[ -x "$(which lua5.2)" ]]; then
|
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||||
ZLUA_EXEC="$(which lua5.2)"
|
|
||||||
elif [[ -x "$(which lua5.1)" ]]; then
|
|
||||||
ZLUA_EXEC="$(which lua5.1)"
|
|
||||||
else
|
|
||||||
echo "Not find lua in your $PATH, please install it."
|
echo "Not find lua in your $PATH, please install it."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export _ZL_FZF_FLAG=${_ZL_FZF_FLAG:-"-e"}
|
||||||
|
|
||||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
||||||
|
|
||||||
|
if [[ -z "$_ZL_NO_ALIASES" ]]; then
|
||||||
alias zz='z -i'
|
alias zz='z -i'
|
||||||
alias zc='z -c'
|
alias zc='z -c'
|
||||||
alias zf='z -I'
|
alias zf='z -I'
|
||||||
alias zb='z -b'
|
alias zb='z -b'
|
||||||
alias zh='z -I -t .'
|
alias zbi='z -b -i'
|
||||||
alias zzc='zz -c'
|
alias zbf='z -b -I'
|
||||||
|
alias zh='z -I -t .'
|
||||||
|
alias zzc='zz -c'
|
||||||
|
fi
|
||||||
|
|||||||