mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-22 15:49:47 +00:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
35
README.cn.md
35
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 (可选),可以用来做可视化选择或者参数补全。
|
- 集成 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 初始化
|
||||||
@@ -79,8 +79,8 @@ 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")
|
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
|
||||||
@@ -90,7 +90,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
|||||||
|
|
||||||
- 将 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 +111,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 +162,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语
|
|||||||
|
|
||||||
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功:
|
||||||
|
|
||||||
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。
|
||||||
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
2. 最后一个关键字可以和路径名的最后一段相匹配。
|
||||||
|
|
||||||
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。
|
||||||
@@ -175,14 +176,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 过去:
|
||||||
@@ -265,7 +266,7 @@ PS:你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路
|
|||||||
|
|
||||||
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
`"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。
|
||||||
|
|
||||||
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。
|
||||||
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
- **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。
|
||||||
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
- **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。
|
||||||
|
|
||||||
@@ -302,6 +303,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`。
|
||||||
|
|
||||||
|
|
||||||
## 补全功能
|
## 补全功能
|
||||||
|
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -131,6 +131,7 @@ z -b foo # cd to the parent directory starting with foo
|
|||||||
- 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.
|
||||||
|
|
||||||
## Aging
|
## Aging
|
||||||
|
|
||||||
@@ -195,7 +196,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.
|
||||||
|
|
||||||
@@ -322,6 +323,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
|
||||||
|
|
||||||
@@ -458,6 +460,16 @@ As you see, z.lua is the fastest one and requires less resource.
|
|||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
|
- 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.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.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.7 (2019-02-21): rename `$_ZL_FZF_SORT` to `$_ZL_INT_SORT` it will affect both `-i` and `-I`.
|
||||||
@@ -492,6 +504,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.
|
||||||
@@ -505,6 +518,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.
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,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
|
||||||
|
|||||||
91
ranger_zlua.py
Normal file
91
ranger_zlua.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
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:
|
||||||
|
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')
|
||||||
|
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
|
||||||
|
|
||||||
319
z.lua
319
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, 2019, 2020
|
||||||
-- Licensed under MIT license.
|
-- Licensed under MIT license.
|
||||||
--
|
--
|
||||||
-- Version 1.5.9, Last Modified: 2019/02/25 23:17
|
-- Version 1.8.4, Last Modified: 2020/02/10 19:22
|
||||||
--
|
--
|
||||||
-- * 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
|
||||||
@@ -74,6 +74,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 +122,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')
|
||||||
|
|
||||||
@@ -302,10 +305,107 @@ 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);
|
||||||
|
]]
|
||||||
|
local kernel32 = ffi.load('kernel32.dll')
|
||||||
|
local buffer = ffi.new('char[?]', 300)
|
||||||
|
local INVALID_FILE_ATTRIBUTES = 0xffffffff
|
||||||
|
local FILE_ATTRIBUTE_DIRECTORY = 0x10
|
||||||
|
os.native.kernel32 = kernel32
|
||||||
|
function os.native.GetFullPathName(name)
|
||||||
|
local hr = kernel32.GetFullPathNameA(name, 290, 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.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(299, 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
|
||||||
@@ -372,6 +472,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)
|
||||||
@@ -427,13 +531,17 @@ function os.path.isdir(pathname)
|
|||||||
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
|
||||||
|
if os.native and os.native.isdir then
|
||||||
|
return os.native.isdir(pathname)
|
||||||
|
end
|
||||||
|
if clink and os.isdir then
|
||||||
|
return os.isdir(pathname)
|
||||||
|
end
|
||||||
local name = pathname
|
local name = pathname
|
||||||
if (not name:endswith('/')) and (not name:endswith('\\')) then
|
if (not name:endswith('/')) and (not name:endswith('\\')) then
|
||||||
name = name .. '/'
|
name = name .. os.path.sep
|
||||||
end
|
end
|
||||||
return os.path.exists(name)
|
return os.path.exists(name)
|
||||||
end
|
end
|
||||||
@@ -443,6 +551,9 @@ 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
|
||||||
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 then
|
||||||
@@ -453,6 +564,12 @@ function os.path.exists(name)
|
|||||||
io.close(f)
|
io.close(f)
|
||||||
return true
|
return true
|
||||||
end
|
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
|
||||||
@@ -867,6 +984,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))
|
||||||
@@ -956,15 +1076,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
|
||||||
@@ -977,7 +1111,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
|
||||||
@@ -1128,6 +1269,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
|
||||||
@@ -1441,7 +1585,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)
|
||||||
@@ -1623,6 +1767,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 --inline-info --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
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
@@ -1657,7 +1886,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
|
||||||
@@ -1729,16 +1962,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
|
||||||
@@ -1784,6 +2015,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
|
||||||
|
|
||||||
|
|
||||||
@@ -1878,14 +2115,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
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -1897,7 +2134,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
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -1924,7 +2161,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
|
||||||
}
|
}
|
||||||
@@ -1934,7 +2171,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
|
||||||
}
|
}
|
||||||
@@ -2174,7 +2411,7 @@ function z_fish_init(opts)
|
|||||||
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')
|
||||||
@@ -2407,7 +2644,33 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
-- testing case
|
-- LFS optimize
|
||||||
|
-----------------------------------------------------------------------
|
||||||
|
os.lfs = {}
|
||||||
|
os.lfs.enable = os.getenv('_ZL_USE_LFS')
|
||||||
|
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
|
||||||
|
|||||||
@@ -20,15 +20,17 @@ if [[ -z "$ZLUA_EXEC" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export _ZL_FZF_FLAG="-e"
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user