Compare commits
150 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c1c73af33 | ||
|
|
b63a38b11a | ||
|
|
c524e28851 | ||
|
|
c3a182c6c9 | ||
|
|
771c72de5f | ||
|
|
4bbd0f1e58 | ||
|
|
db1fb1f256 | ||
|
|
19cb43d1ac | ||
|
|
787da9512c | ||
|
|
3875d774cb | ||
|
|
dff590adc1 | ||
|
|
20c0494d44 | ||
|
|
67405d57e8 | ||
|
|
6e67a32520 | ||
|
|
c334bc1ae5 | ||
|
|
0f6318ce4c | ||
|
|
3b55089ad8 | ||
|
|
c58d31ec1d | ||
|
|
7c890c3645 | ||
|
|
7af012cc35 | ||
|
|
019b2af475 | ||
|
|
ef9a49d73d | ||
|
|
7cd399b30d | ||
|
|
9112f0e9cc | ||
|
|
cb4c9d3c8f | ||
|
|
924f61a48b | ||
|
|
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 | ||
|
|
4c05e0d911 | ||
|
|
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 |
1
.gitignore
vendored
@@ -39,3 +39,4 @@ luac.out
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
/.vscode/*
|
||||
|
||||
75
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,29 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
|
||||
但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。
|
||||
|
||||
- Power Shell:
|
||||
|
||||
- Nushell:
|
||||
|
||||
在 `env.nu` 中加入如下代码:
|
||||
|
||||
lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nu
|
||||
|
||||
然后在 `config.nu` 中加入如下代码:
|
||||
|
||||
source ~/.cache/zlua.nu
|
||||
alias z = _zlua
|
||||
|
||||
- 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:
|
||||
@@ -107,10 +123,11 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
- 设置 `$_ZL_NO_PROMPT_COMMAND` 为 1 来跳过钩子函数初始化(方便自己处理)。
|
||||
- 设置 `$_ZL_EXCLUDE_DIRS` 逗号分隔的路径列表,列表内的路径不会被收集。
|
||||
- 设置 `$_ZL_ADD_ONCE` 为 '1' 时,仅在当前路径 `$PWD` 改变时才更新数据库。
|
||||
- 设置 `$_ZL_MAXAGE` 来确定一个数据老化的阀值 (默认为 5000)。
|
||||
- 设置 `$_ZL_MAXAGE` 来确定一个数据老化的阈值 (默认为 5000)。
|
||||
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
|
||||
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
|
||||
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
|
||||
- 设置 `$_ZL_HYPHEN` 为 1 可以允许关键字中包含横线 (横线默认是 lua 正则关键字,要转写成 `%-`)。
|
||||
|
||||
## Aging
|
||||
|
||||
@@ -161,7 +178,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
||||
|
||||
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
||||
|
||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
||||
|
||||
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
||||
@@ -175,14 +192,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 过去:
|
||||
@@ -195,7 +212,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
||||
|
||||
cd foo
|
||||
|
||||
因此,在增强匹配算法中,你总可以象 cd 命令一样使用 z 命令,而不必当心目标路径是否被记录过。
|
||||
因此,在增强匹配算法中,你总可以像 cd 命令一样使用 z 命令,而不必当心目标路径是否被记录过。
|
||||
|
||||
- 忽略当前路径:
|
||||
|
||||
@@ -208,7 +225,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
||||
|
||||
我当然可以每次使用`z env gems` 来精确指明,但是每当我输入 `z xxx` 我必然是想进行路径跳转的,而不是呆在原地,所以使用增强匹配模式,即便当前目录是最佳匹配,它也能懂得你想跳转的心思。
|
||||
|
||||
再我最初实现 z.lua 时,只有一个和 z.sh 类似的默认匹配算法,在网友的建议下,我陆续学习了来自 fasd / autojump 中的优秀理念,并加以完善改进,成为如今集三家之长的 “增强匹配算法” ,给它取个昵称,叫做 “更懂你的匹配算法”。
|
||||
在我最初实现 z.lua 时,只有一个和 z.sh 类似的默认匹配算法,在网友的建议下,我陆续学习了来自 fasd / autojump 中的优秀理念,并加以完善改进,成为如今集三家之长的 “增强匹配算法” ,给它取个昵称,叫做 “更懂你的匹配算法”。
|
||||
|
||||
|
||||
## Add once
|
||||
@@ -265,7 +282,7 @@ PS:你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路
|
||||
|
||||
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
||||
|
||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
||||
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
||||
|
||||
@@ -302,6 +319,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 +336,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,就能把匹配的路径列出来:
|
||||
|
||||

|
||||
|
||||
@@ -430,15 +455,13 @@ sys 0m0.030s
|
||||
|
||||
描述力强,可以更好的实现核心功能,同时速度更快,纯 shell 开发的话,太多语句是通过子进程 shell 的模式运行,所以性能很差,而 Python 开发的话启动速度又太慢,我在 Cygwin/msys 下用 z.sh 都觉得很卡,autojump/fasd 卡到不能用。
|
||||
|
||||
最关键的一点,Lua 速度很快 200 KB 的可执行程序,启动速度是 python 的 3倍,perl 的 2 倍,很多命令行工具 go/rust 写成,动不动就 2MB / 3MB,他们都还没有完成加载,lua 脚本可能都运行完了。
|
||||
最关键的一点,Lua 速度很快 200 KB 的可执行程序,启动速度是 python 的 3 倍,perl 的 2 倍,很多命令行工具 go/rust 写成,动不动就 2MB / 3MB,他们都还没有完成加载,lua 脚本可能都运行完了。
|
||||
|
||||
|
||||
## Credit
|
||||
|
||||
Releated projects:
|
||||
|
||||
- [rupa/z](https://github.com/rupa/z): origin z.sh implementation
|
||||
- [JannesMeyer/z.ps](https://github.com/JannesMeyer/z.ps): z for powershell
|
||||
我的推特:https://x.com/skywind3000
|
||||
个人博客: https://skywind.me/blog
|
||||
|
||||
|
||||
## License
|
||||
|
||||
161
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,58 @@ 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.
|
||||
|
||||
- Nushell
|
||||
|
||||
Put something like this in your `env.nu`:
|
||||
|
||||
lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nu
|
||||
|
||||
Then put something like this in your `config.nu`:
|
||||
|
||||
source ~/.cache/zlua.nu
|
||||
alias z = _zlua
|
||||
|
||||
- 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 +167,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 +193,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 +208,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 +247,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 +292,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.
|
||||
@@ -289,6 +341,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 +361,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 +380,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 +396,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 +454,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 +519,30 @@ 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).
|
||||
@@ -512,6 +597,8 @@ 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.
|
||||
- Thanks to [@brglng](https://github.com/brglng) for nushell porting.
|
||||
|
||||
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
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 7.5 KiB |
BIN
images/step2.png
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 5.7 KiB |
BIN
images/step3.png
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 3.6 KiB |
BIN
images/step4.png
|
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 3.4 KiB |
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
|
||||
|
||||
@@ -2,41 +2,45 @@ import time, sys, os
|
||||
import ranger.api
|
||||
import subprocess
|
||||
|
||||
old_hook_init = ranger.api.hook_init
|
||||
# $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')
|
||||
|
||||
PATH_LUA = os.environ.get('RANGER_LUA')
|
||||
PATH_ZLUA = os.environ.get('RANGER_ZLUA')
|
||||
|
||||
if not PATH_LUA:
|
||||
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):
|
||||
PATH_LUA = test
|
||||
ZLUA_LUAEXE = test
|
||||
break
|
||||
|
||||
if not PATH_LUA:
|
||||
sys.stderr.write('Please install lua or set $RANGER_LUA.\n')
|
||||
sys.exit()
|
||||
def _report_error(msg):
|
||||
sys.stderr.write('ranger_zlua: ' + msg)
|
||||
raise RuntimeError(msg)
|
||||
|
||||
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()
|
||||
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([PATH_LUA, PATH_ZLUA, "--add", signal.new.path])
|
||||
p = subprocess.Popen([ZLUA_LUAEXE, ZLUA_SCRIPT, "--add", signal.new.path])
|
||||
p.wait()
|
||||
if PATH_ZLUA and PATH_LUA and os.path.exists(PATH_ZLUA):
|
||||
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
|
||||
@@ -52,13 +56,13 @@ class z(ranger.api.commands.Command):
|
||||
elif arg[:1] != '-':
|
||||
break
|
||||
if mode:
|
||||
cmd = '"%s" "%s" '%(PATH_LUA, PATH_ZLUA)
|
||||
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([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
||||
path = subprocess.check_output([ZLUA_LUAEXE, ZLUA_SCRIPT, '--cd'] + args)
|
||||
path = path.decode("utf-8", "ignore")
|
||||
path = path.rstrip('\n')
|
||||
self.fm.notify(path)
|
||||
@@ -69,18 +73,14 @@ class z(ranger.api.commands.Command):
|
||||
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
|
||||
stdout, stderr = p.communicate()
|
||||
else:
|
||||
if mode == '-I':
|
||||
os.environ['_ZL_FZF_HEIGHT'] = '0'
|
||||
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
||||
self.fm.execute_console('redraw_window')
|
||||
else:
|
||||
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
path = stdout.rstrip('\n')
|
||||
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 = 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):
|
||||
|
||||
30
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
|
||||
@@ -85,7 +89,9 @@ if /i "%1"=="--purge" (
|
||||
:check
|
||||
|
||||
if /i "%1"=="" (
|
||||
set "RunMode=-l"
|
||||
if /i "%InterMode%"=="" (
|
||||
set "RunMode=-l"
|
||||
)
|
||||
)
|
||||
|
||||
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
||||
@@ -100,13 +106,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 "$(command which lua)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua)"
|
||||
elif [[ -x "$(command which lua5.3)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua5.3)"
|
||||
elif [[ -x "$(command which lua5.2)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua5.2)"
|
||||
elif [[ -x "$(command which lua5.1)" ]]; then
|
||||
ZLUA_EXEC="$(command 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 fzf)"
|
||||
else
|
||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
||||
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
|
||||
|
||||