Compare commits
157 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30220996ca | ||
|
|
d3ba781d4d | ||
|
|
9a24fef334 | ||
|
|
a9e034cb5c | ||
|
|
992134061a | ||
|
|
b62784b66d | ||
|
|
7f2bfcbfc1 | ||
|
|
86cb43af67 | ||
|
|
71bae7fc0b | ||
|
|
4d89b55363 | ||
|
|
db1a863d40 | ||
|
|
dff016528c | ||
|
|
6fe677aae4 | ||
|
|
ba83bf67b2 | ||
|
|
0992ebf9f1 | ||
|
|
83dfec0843 | ||
|
|
3703c5a0ea | ||
|
|
3894a6b936 | ||
|
|
0905165889 | ||
|
|
3009e33176 | ||
|
|
32786a0592 | ||
|
|
47468a8588 | ||
|
|
f347eaf1c8 | ||
|
|
e11d2e2017 | ||
|
|
3ecc14747f | ||
|
|
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 |
63
README.cn.md
@@ -14,11 +14,11 @@ z.lua 是一个快速路径切换工具,它会跟踪你在 shell 下访问过
|
||||
|
||||
- 性能比 **z.sh** 快三倍,比 **fasd** / **autojump** 快十倍以上。
|
||||
- 支持 Posix Shell:bash, zsh, dash, sh, ash, busybox 等等。
|
||||
- 支持 Fish Shell,Power Shell 和 Windows cmd。
|
||||
- 使用增强匹配算法,更准确的带你去到你想去的地方。
|
||||
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。
|
||||
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
|
||||
- 集成 fzf (可选),可以用来做可视化选择或者参数补全。
|
||||
- 支持 Fish Shell,Power Shell 和 Windows cmd。
|
||||
- 使用增强匹配算法,更准确的带你去到你想去的地方。
|
||||
- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。
|
||||
- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。
|
||||
- 集成 fzf (可选),可以用来做可视化选择或者参数补全。
|
||||
- 快速跳转到父目录,或者项目根目录,代替反复 “cd ../../.." 。
|
||||
- 兼容 lua 5.1, 5.2 和 5.3 以上版本。
|
||||
- 自包含且无额外依赖,单个 `z.lua` 文件完成所有工作。
|
||||
@@ -42,10 +42,10 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
|
||||
## Install
|
||||
|
||||
- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等):
|
||||
|
||||
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
|
||||
|
||||
- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等):
|
||||
|
||||
在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句:
|
||||
|
||||
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 posix)" # Posix shell 初始化
|
||||
@@ -65,7 +65,12 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
antigen bundle skywind3000/z.lua
|
||||
|
||||
就可以了(主要要放在 antigen apply 语句之前)。
|
||||
|
||||
**注意**:使用 WSL-1 的用户,需要安装 `lua-filesystem` 包:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
这是由于 wsl-1 的 [bug](https://github.com/microsoft/WSL/issues/5505) 引起的,使用 lua-filesystem 可以避免该问题。
|
||||
|
||||
- Fish Shell:
|
||||
|
||||
@@ -79,18 +84,18 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
|
||||
但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。
|
||||
|
||||
- Power Shell:
|
||||
|
||||
- Power Shell:
|
||||
|
||||
在你 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):
|
||||
|
||||
- 将 z.lua 和 z.cmd 拷贝到 clink 的安装目录。
|
||||
- 将 clink 的安装目录添加到 `%PATH%` (z.cmd 可以被任意位置调用到)。
|
||||
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
|
||||
- 保证 lua 命令在你的 `%PATH%` 环境变量中。
|
||||
|
||||
|
||||
- Windows cmder:
|
||||
@@ -111,6 +116,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
||||
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
||||
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
||||
- 设置 `$_ZL_HYPHEN` 为 1 可以允许关键字中包含横线 (横线默认是 lua 正则关键字,要转写成 `%-`)。
|
||||
|
||||
## Aging
|
||||
|
||||
@@ -161,7 +167,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
||||
|
||||
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
||||
|
||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
||||
|
||||
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
||||
@@ -175,14 +181,14 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
||||
30 /home/user/workspace/project2
|
||||
40 /home/user/workspace/project3
|
||||
|
||||
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/work` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
|
||||
在增强模式下使用 `"z wo"` 的话,只有 `/home/user/workspace` 满足匹配,因为按照第二条规则,这是唯一一条最有一段名称匹配 `wo` 的路径。
|
||||
|
||||
因为最后一级目录名称总是最容易记住的,所以给到它比较高的优先级。在默认匹配算法中,你同样可以用 `"z space$"` 来达到相同的目的,但是 `"z wo"` 可以打更少的字。
|
||||
|
||||
小技巧:
|
||||
|
||||
- 如果你在增强匹配算法下,想让最后一个关键字不当匹配最后一段路径名,还可以像默认匹配算法中一样匹配路径的其他部分的话,你可以在最后加一个独立的 '$' 参数,比如:`"z wo $"`
|
||||
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
|
||||
- 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。
|
||||
|
||||
|
||||
- 如果没法匹配,同时又存在一条路径名和关键字相同,那么 cd 过去:
|
||||
@@ -265,11 +271,11 @@ PS:你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路
|
||||
|
||||
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
||||
|
||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
||||
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
||||
|
||||
为了使用简便,我们继续将 `z -b` 取个别名成 `zb`:
|
||||
先将 `z -b` 别名成 `zb`:
|
||||
|
||||
```bash
|
||||
# 一直向上退到项目根目录(就是里面有一个 .git 目录的地方)
|
||||
@@ -302,6 +308,8 @@ export _ZL_ROOT_MARKERS=".git,.svn,.hg,.root,package.json"
|
||||
|
||||
**Bonus**:`zb ..` 相当于 `cd ..`,`zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。
|
||||
|
||||
**Bonus**: 试试 `z -b -i` 以及 `z -b -I`,推荐把他们取个别名成 `zbi` 和 `zbf`。
|
||||
|
||||
|
||||
## 补全功能
|
||||
|
||||
@@ -317,7 +325,13 @@ zsh/fish 的补全系统是比较完善的,使用 `z foo<tab>` 就能触发补
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once echo fzf)"
|
||||
```
|
||||
|
||||
然后你在 bash 中,输入部分关键字后按 tab,就能把匹配的路径列出来:
|
||||
如果你想在 zsh 中使用 fzf 补全,初始化时在 `--init` 后追加 `fzf` 关键字:
|
||||
|
||||
```zsh
|
||||
eval "$(lua /path/to/z.lua --init zsh enhanced once echo fzf)"
|
||||
```
|
||||
|
||||
然后你在 bash/zsh 中,输入部分关键字后按 tab,就能把匹配的路径列出来:
|
||||
|
||||

|
||||
|
||||
@@ -350,23 +364,22 @@ $ z -
|
||||
=> cd -
|
||||
```
|
||||
|
||||
这个 `dirstack` 是根据 z.lua 的路径历史数据库计算的出来的,所以和具体的 shell 或者操作系统都没有关系。你退出再登陆不会丢失这些路径历史,不同的 shell 之间也可以共享同一份历史数据。
|
||||
这个 `dirstack` 是根据 z.lua 的路径历史数据库计算的出来的,和具体的 shell 或者操作系统无关。你退出再登陆不会丢失这些记录,不同的 shell 之间也可以共享同一份记录。
|
||||
|
||||
此外,还有另外一种方法,通过使用前面提到的 `-I` 和 `-t` 参数组和,可以使用 fzf 进行交互式选择:
|
||||
此外,还能通过前面提到的 `-I` 和 `-t` 参数组和,使用 fzf 选择最近去过的目录:
|
||||
|
||||
```bash
|
||||
alias zh='z -I -t .'
|
||||
```
|
||||
|
||||
首先定义个新的别名 `zh`(回到历史路径的意思),我们使用了 `-t` 参数来告诉 `z.lua` 按照时间戳作为权重进行排序,同时 `-I` 启用 fzf 进行搜索,最后的句号代表任意路径。
|
||||
方便起见,定义个新的别名 `zh`(回到历史路径的意思),我们用 `-t` 参数来告诉 `z.lua` 按时间戳为权重排序,同时 `-I` 启用 fzf 搜索,最后句号代表任意路径。
|
||||
|
||||
那么当我们在命令行敲入 zh 时,就可以用 fzf 选择最近呆过的路径了:
|
||||
那么当我们在命令行敲入 zh 时,就可以用 fzf 进行历史路径操作了:
|
||||
|
||||

|
||||
|
||||
第一列数据代表该路径多少秒以前访问过,第二列是路径名称。此时,你可以试着敲几个字母,用 fzf 的字符串模糊匹配进行定位,或者用光标键的上和下(CTRL+J/K 也可以)来上下移动,最后按回车 cd 过去,或者 ESC 放弃。
|
||||
第一列上次访问距今多少秒,第二列是目录名。你可以试着敲几个字母,用 fzf 的字符串模糊匹配进行定位,或者用光标键的上和下(CTRL+J/K 也可以)来上下移动,最后按回车 cd 过去,或者 ESC 放弃。
|
||||
|
||||
注意:最好把增强匹配模式打开,这样查看历史路径时可以把当前路径过滤掉。
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
164
README.md
@@ -13,35 +13,46 @@ 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`.
|
||||
|
||||
## 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
|
||||
|
||||
- **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 Fish Shell, Power Shell and Windows cmd.
|
||||
- [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.
|
||||
- Interactive selection enables you to choose where to go before cd.
|
||||
- Intergrated with FZF (optional) for interactive selection and completion.
|
||||
- Integrated with FZF (optional) for interactive selection and completion.
|
||||
- Quickly go back to a parent directory instead of typing "cd ../../..".
|
||||
- Corresponding experience in different shells and operating systems.
|
||||
- Compatible with Lua 5.1, 5.2 and 5.3+
|
||||
- Compatible with Lua (5.1, 5.2, 5.3+) and luajit.
|
||||
- Self contained, distributed as a single `z.lua` script, no other dependence.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
```bash
|
||||
z foo # cd to most frecent dir matching foo
|
||||
z foo bar # cd to most frecent dir matching foo and bar
|
||||
z -r foo # cd to the highest ranked dir matching foo
|
||||
z -t foo # cd to most recently accessed dir matching foo
|
||||
z -l foo # list matches instead of cd
|
||||
z -c foo # restrict matches to subdirs of $PWD
|
||||
z -e foo # echo the best match, don't cd
|
||||
z -i foo # cd with interactive selection
|
||||
z -I foo # cd with interactive selection using fzf
|
||||
z -b foo # cd to the parent directory starting with foo
|
||||
z foo # cd to most frecent dir matching foo
|
||||
z foo bar # cd to most frecent dir matching foo and bar
|
||||
z -r foo # cd to the highest ranked dir matching foo
|
||||
z -t foo # cd to most recently accessed dir matching foo
|
||||
z -l foo # list matches instead of cd
|
||||
z -c foo # restrict matches to subdirs of $PWD
|
||||
z -e foo # echo the best match, don't cd
|
||||
z -i foo # cd with interactive selection
|
||||
z -I foo # cd with interactive selection using fzf
|
||||
z -b foo # cd to the parent directory starting with foo
|
||||
z -b foo bar # replace foo with bar in cwd and cd there
|
||||
```
|
||||
|
||||
|
||||
@@ -59,13 +70,19 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
and perhaps this:
|
||||
|
||||
export _ZL_ECHO=1
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once echo)"
|
||||
|
||||
if you want `z.lua` print the new directory after cd.
|
||||
|
||||
If you want `fzf` tab completion use:
|
||||
For `fzf` tab completion use:
|
||||
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"
|
||||
|
||||
**NOTE**: For wsl-1 users, `lua-filesystem` must be installed:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
To avoid a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
|
||||
|
||||
- Zsh:
|
||||
|
||||
@@ -73,7 +90,9 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
eval "$(lua /path/to/z.lua --init 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).
|
||||
Options like "enhanced", "once" and "fzf" 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:
|
||||
|
||||
@@ -87,37 +106,47 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
To generate old posix compatible script.
|
||||
|
||||
- Fish Shell:
|
||||
- Fish Shell (version `2.4.0` or above):
|
||||
|
||||
Create `~/.config/fish/conf.d/z.fish` with following code
|
||||
|
||||
source (lua /path/to/z.lua --init fish | psub)
|
||||
lua /path/to/z.lua --init fish | source
|
||||
|
||||
Fish version `2.4.0` or above is required.
|
||||
If you'd like `z.lua` to cooperate with fish's own [directory history](https://fishshell.com/docs/3.2/index.html#id34), you can put
|
||||
|
||||
lua /path/to/z.lua --init fish > ~/.config/fish/conf.d/z.fish
|
||||
set -gx _ZL_CD cd
|
||||
|
||||
This is another way to initialize z.lua in fish shell, but remember to regenerate z.fish if z.lua has been updated or moved.
|
||||
into the same file.
|
||||
|
||||
- Power Shell:
|
||||
|
||||
> ⚠️ **WARNING**: users of [Starship Prompt](https://starship.rs/) should add the following command *after* `starship init`.
|
||||
|
||||
put something like this in your `profile.ps1`:
|
||||
|
||||
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
|
||||
|
||||
Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
|
||||
|
||||
- Windows cmd (with clink):
|
||||
|
||||
- copy z.lua and z.cmd to clink's home directory
|
||||
- Copy z.lua and z.cmd to clink's home directory
|
||||
- Add clink's home to `%PATH%` (z.cmd can be called anywhere)
|
||||
- Ensure that "lua" can be called in `%PATH%`
|
||||
|
||||
- Windows cmder:
|
||||
|
||||
- copy z.lua and z.cmd to cmder/vendor
|
||||
- Copy z.lua and z.cmd to cmder/vendor
|
||||
- Add cmder/vendor to `%PATH%`
|
||||
- Ensure that "lua" can be called in `%PATH%`
|
||||
|
||||
- Windows WSL-1:
|
||||
|
||||
Install `lua-filesystem` module before init z.lua:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
This module is required due to a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
|
||||
|
||||
|
||||
|
||||
## Options
|
||||
|
||||
@@ -127,10 +156,17 @@ z -b foo # cd to the parent directory starting with foo
|
||||
- set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude.
|
||||
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed.
|
||||
- set `$_ZL_MAXAGE` to define a aging threshold (default is 5000).
|
||||
- set `$_ZL_CD` to specify your own cd command.
|
||||
- set `$_ZL_CD` to specify your own cd command (default is `builtin cd` in Unix shells).
|
||||
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
|
||||
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
|
||||
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
|
||||
- set `$_ZL_HYPHEN` to 0 to treat a hyphen (`-`) as a
|
||||
[lua regexp special character](https://www.lua.org/pil/20.2.html),
|
||||
set `$_ZL_HYPHEN` to 1 to treat a hyphen as a normal character.
|
||||
If `$_ZL_HYPHEN` is not set or if it is set to `auto`, z.lua tries to treat `-`
|
||||
as a lua regexp special character first. If there are no matches, z.lua tries
|
||||
again, this time treating `-` as a normal character.
|
||||
- set `$_ZL_CLINK_PROMPT_PRIORITY` change clink prompt register priority (default 99).
|
||||
|
||||
## Aging
|
||||
|
||||
@@ -146,16 +182,12 @@ To z.lua, a directory that has low ranking but has been accessed recently will q
|
||||
|
||||
## Default Matching
|
||||
|
||||
By default, z.lua uses default matching algorithm similar to the original z.sh. Paths must be match all of the regexes in order.
|
||||
By default, `z.lua` uses default matching algorithm similar to the original `z.sh`. Paths must be match all of the regexes in order.
|
||||
|
||||
- cd to a directory contains foo:
|
||||
|
||||
z foo
|
||||
|
||||
- cd to a directory ends with foo:
|
||||
|
||||
z foo$
|
||||
|
||||
- use multiple arguments:
|
||||
|
||||
Assuming the following database:
|
||||
@@ -165,6 +197,15 @@ By default, z.lua uses default matching algorithm similar to the original z.sh.
|
||||
|
||||
`"z in"` would cd into `/home/user/mail/inbox` as the higher weighted entry. However you can pass multiple arguments to z.lua to prefer a different entry. In the above example, `"z w in"` would then change directory to `/home/user/work/inbox`.
|
||||
|
||||
- use regexes:
|
||||
|
||||
```bash
|
||||
z foo$ # cd to a directory ends with foo
|
||||
z %d # cd to a directory that contains a digit
|
||||
```
|
||||
|
||||
Unlike `z.sh`, `z.lua` uses the [Lua regular expression syntax](https://www.lua.org/pil/20.2.html).
|
||||
|
||||
## Enhanced Matching
|
||||
|
||||
Enhanced matching can be enabled by exporting the environment:
|
||||
@@ -195,7 +236,7 @@ If no match is found, it will fall back to default matching method.
|
||||
30 /home/user/workspace/project2
|
||||
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.
|
||||
|
||||
@@ -240,7 +281,7 @@ To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can
|
||||
````bash
|
||||
eval "$(lua /path/to/z.lua --init bash once)"
|
||||
eval "$(lua /path/to/z.lua --init zsh once)"
|
||||
source (lua /path/to/z.lua --init fish once | psub)
|
||||
lua /path/to/z.lua --init fish once | source
|
||||
````
|
||||
|
||||
With `add once` mode off (default), z.lua will consider the time you spent in the directory (like z.sh). When this mode is on, consider the times you accessed the directory (like autojump), and that could be much faster on slow hardware.
|
||||
@@ -275,9 +316,9 @@ Now you can input some space separated keywords (no order required) or use `CTRL
|
||||
|
||||
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. Environment variable `_ZL_FZF_FLAG` is for passing additional arguments to fzf.
|
||||
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.
|
||||
|
||||
@@ -289,6 +330,7 @@ New option `"-b"` can quickly go back to a specific parent directory in bash ins
|
||||
- **(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, go to the parent containing keyword.
|
||||
- **(Two arguments)**: replace the first value with the second one (in the current path).
|
||||
If simple substitution does not work, falls back to fuzzily replacing path components.
|
||||
|
||||
Let's start by aliasing `z -b` to `zb`:
|
||||
|
||||
@@ -308,6 +350,11 @@ Let's start by aliasing `z -b` to `zb`:
|
||||
# substitute jekyll with ghost
|
||||
~/github/jekyll/test$ zb jekyll ghost
|
||||
=> cd ~/github/ghost/test
|
||||
|
||||
# same as above, but fuzzy
|
||||
~/github/jekyll/test$ zb jek gh
|
||||
=> z ~/github/ gh /test
|
||||
=> cd ~/github/ghost/test # Assuming that's the most frecent match
|
||||
```
|
||||
|
||||
Backward jumping can also be used with `$_ZL_ECHO` option (echo $PWD after cd), which makes it possible to combine them with other tools without actually changing the working directory (eg. ``ls `zb git` ``).
|
||||
@@ -322,6 +369,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**: try `z -b -i` and `z -b -I` and you can alias them to `zbi` and `zbf`.
|
||||
|
||||
## Completion
|
||||
|
||||
@@ -337,6 +385,12 @@ Bash is not as powerful as zsh/fish, so we introduced fzf-completion for bash, i
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once echo fzf)"
|
||||
```
|
||||
|
||||
If you want use fzf completion in zsh, initalize your z.lua and append `fzf` keyword after `--init`:
|
||||
|
||||
```zsh
|
||||
eval "$(lua /path/to/z.lua --init zsh enhanced once echo fzf)"
|
||||
```
|
||||
|
||||
Then press `<tab>` after `z xxx`:
|
||||
|
||||

|
||||
@@ -389,6 +443,14 @@ At last, press `<enter>` to accept or `<ESC>` to give up.
|
||||
Remember to enable the [enhanced matching](#enhanced-matching) algorithm, the current working directory can be skipped with it.
|
||||
|
||||
|
||||
## Ranger integration
|
||||
To add a `:z` command to the [`ranger` file manager], copy the `ranger_zlua.py` file to `~/.config/ranger/plugins/`.
|
||||
You can then use `:z foo`, `:z -b foo`, etc. from ranger. Use `:z -h` for help.
|
||||
|
||||
[`ranger` file manager]: https://github.com/ranger/ranger
|
||||
|
||||
To define additional commands (`:zb` for example) in ranger, you can put `alias zb z -b` into `~/.config/ranger/rc.conf`.
|
||||
|
||||
|
||||
## Tips
|
||||
|
||||
@@ -446,18 +508,40 @@ sys 0m0.030s
|
||||
|
||||
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
|
||||
|
||||
- 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.
|
||||
@@ -488,6 +572,7 @@ As you see, z.lua is the fastest one and requires less resource.
|
||||
|
||||
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: Implement completion for Power Shell.
|
||||
- [ ] Completion: Implement completion for different arguments.
|
||||
@@ -501,6 +586,7 @@ This project needs help for the tasks below:
|
||||
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish 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 [@barlik](https://github.com/barlik) for many improvements.
|
||||
|
||||
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 _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 type -q lua
|
||||
lua $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q luajit
|
||||
luajit $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q lua5.3
|
||||
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
|
||||
else if type -q lua5.2
|
||||
@@ -35,6 +42,8 @@ if test -e $_zlua_dir/z.lua
|
||||
alias zz='z -i' # cd with interactive selection
|
||||
alias zf='z -I' # use fzf to select in multiple matches
|
||||
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_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null
|
||||
end
|
||||
|
||||
91
ranger_zlua.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import time, sys, os
|
||||
import ranger.api
|
||||
import subprocess
|
||||
|
||||
# $RANGER_LUA and $RANGER_ZLUA variables are deprecated, do not use them.
|
||||
ZLUA_LUAEXE = os.environ.get('RANGER_LUA') or os.environ.get('ZLUA_LUAEXE')
|
||||
ZLUA_SCRIPT = os.environ.get('RANGER_ZLUA') or os.environ.get('ZLUA_SCRIPT')
|
||||
|
||||
if not ZLUA_LUAEXE:
|
||||
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):
|
||||
ZLUA_LUAEXE = test
|
||||
break
|
||||
|
||||
def _report_error(msg):
|
||||
sys.stderr.write('ranger_zlua: ' + msg)
|
||||
raise RuntimeError(msg)
|
||||
|
||||
if not ZLUA_LUAEXE:
|
||||
_report_error('Please install lua in $PATH or make sure $ZLUA_LUAEXE points to a lua executable.\n')
|
||||
if (not ZLUA_SCRIPT) or (not os.path.exists(ZLUA_SCRIPT)):
|
||||
_report_error('Could not find z.lua, please make sure $ZLUA_SCRIPT is set to absolute path of z.lua.\n')
|
||||
|
||||
|
||||
# Inform z.lua about directories the user browses to inside ranger
|
||||
old_hook_init = ranger.api.hook_init
|
||||
|
||||
def hook_init(fm):
|
||||
def update_zlua(signal):
|
||||
import os, random
|
||||
os.environ['_ZL_RANDOM'] = str(random.randint(0, 0x7fffffff))
|
||||
p = subprocess.Popen([ZLUA_LUAEXE, ZLUA_SCRIPT, "--add", signal.new.path])
|
||||
p.wait()
|
||||
if ZLUA_SCRIPT and ZLUA_LUAEXE and os.path.exists(ZLUA_SCRIPT):
|
||||
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" '%(ZLUA_LUAEXE, ZLUA_SCRIPT)
|
||||
if mode in ('-I', '-i', '--'):
|
||||
cmd += ' --cd'
|
||||
for arg in args:
|
||||
cmd += ' "%s"'%arg
|
||||
if mode in ('-e', '-x'):
|
||||
path = subprocess.check_output([ZLUA_LUAEXE, ZLUA_SCRIPT, '--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([ZLUA_LUAEXE, ZLUA_SCRIPT, '--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
|
||||
|
||||
26
z.cmd
@@ -1,10 +1,8 @@
|
||||
@echo off
|
||||
setlocal EnableDelayedExpansion
|
||||
|
||||
set "HomeDir=%~dp0"
|
||||
set "PathSave=%PATH%"
|
||||
set "LuaExe=lua"
|
||||
set "LuaScript=%HomeDir%z.lua"
|
||||
set "LuaScript=%~dp0z.lua"
|
||||
set "MatchType=-n"
|
||||
set "StrictSub=-n"
|
||||
set "RunMode=-n"
|
||||
@@ -54,6 +52,12 @@ if /i "%1"=="-x" (
|
||||
goto parse
|
||||
)
|
||||
|
||||
if /i "%1"=="--add" (
|
||||
set "RunMode=--add"
|
||||
shift /1
|
||||
goto parse
|
||||
)
|
||||
|
||||
if "%1"=="-i" (
|
||||
set "InterMode=-i"
|
||||
shift /1
|
||||
@@ -100,13 +104,27 @@ if /i "%RunMode%"=="-n" (
|
||||
pushd !NewPath!
|
||||
pushd !NewPath!
|
||||
endlocal
|
||||
popd
|
||||
goto popdir
|
||||
)
|
||||
)
|
||||
) else (
|
||||
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
|
||||
echo.
|
||||
|
||||
|
||||
@@ -2,33 +2,38 @@
|
||||
|
||||
ZLUA_SCRIPT="${0:A:h}/z.lua"
|
||||
|
||||
[[ -n "$ZLUA_EXEC" ]] && [[ ! -x "$ZLUA_EXEC" ]] && ZLUA_EXEC=""
|
||||
if [[ -n "$ZLUA_EXEC" ]] && ! which "$ZLUA_EXEC" &>/dev/null; then
|
||||
echo "$ZLUA_EXEC not found"
|
||||
ZLUA_EXEC=""
|
||||
fi
|
||||
|
||||
# search lua executable
|
||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
if [[ -x "$(which lua)" ]]; then
|
||||
ZLUA_EXEC="$(which lua)"
|
||||
elif [[ -x "$(which lua5.3)" ]]; then
|
||||
ZLUA_EXEC="$(which lua5.3)"
|
||||
elif [[ -x "$(which lua5.2)" ]]; then
|
||||
ZLUA_EXEC="$(which lua5.2)"
|
||||
elif [[ -x "$(which lua5.1)" ]]; then
|
||||
ZLUA_EXEC="$(which lua5.1)"
|
||||
else
|
||||
for lua in lua luajit lua5.4 lua5.3 lua5.2 lua5.1; do
|
||||
ZLUA_EXEC="$(command -v "$lua")"
|
||||
[[ -n "$ZLUA_EXEC" ]] && break
|
||||
done
|
||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
echo "Not find lua in your $PATH, please install it."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
export _ZL_FZF_FLAG="-e"
|
||||
export _ZL_FZF_FLAG=${_ZL_FZF_FLAG:-"-e"}
|
||||
|
||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
||||
|
||||
|
||||
alias zz='z -i'
|
||||
alias zc='z -c'
|
||||
alias zf='z -I'
|
||||
alias zb='z -b'
|
||||
alias zh='z -I -t .'
|
||||
alias zzc='zz -c'
|
||||
if [[ -z "$_ZL_ZSH_NO_FZF" ]]; then
|
||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
||||
else
|
||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced fzf)"
|
||||
fi
|
||||
|
||||
if [[ -z "$_ZL_NO_ALIASES" ]]; then
|
||||
alias zz='z -i'
|
||||
alias zc='z -c'
|
||||
alias zf='z -I'
|
||||
alias zb='z -b'
|
||||
alias zbi='z -b -i'
|
||||
alias zbf='z -b -I'
|
||||
alias zh='z -I -t .'
|
||||
alias zzc='zz -c'
|
||||
fi
|
||||
|
||||