1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-22 07:39:48 +00:00

98 Commits

Author SHA1 Message Date
skywind3000
632f722ee4 bloat version number 2022-07-21 22:12:50 +08:00
Linwei
9b9c0b82e6 Merge pull request #163 from jpcirrus/patch-1
Update fzf --inline-info option to --info=inline
2022-07-21 22:11:56 +08:00
John Purnell
08510fe6c6 Update fzf --inline-info option to --info=inline
fzf changed the option `--inline-info` to the equivalent `--info=inline` in release 0.19.0 with commit junegunn/fzf@d2fa470165 on 2019-11-14.
2022-07-21 15:30:21 +02:00
Linwei
1ead694395 Merge pull request #157 from wtfzambo/patch-1
docs: added warning for powershell users
2022-06-14 20:35:45 +08:00
wtfzambo
ee6aa2c5ce docs: added warning for powershell users
`.zlua` file doesn't get created for Powershell users that use [Starship Prompt](https://starship.rs/) and place z.lua init command before starship init command in their `profile.ps1`.

Couldn't reproduce the bug in zsh. Didn't test other shells.
2022-06-14 06:16:58 -04:00
skywind3000
a8e92e0216 fix Monterey initialization issues 2022-03-27 21:51:29 +08:00
skywind3000
e2cce39ee4 bloat version to 1.8.14 2022-01-30 21:54:08 +08:00
skywind3000
3c88f8d8fa recognize %_ZL_CD% in cmd.exe 2022-01-30 10:55:40 +08:00
Linwei
786225005c Merge pull request #148 from phanirithvij/imgbot
[ImgBot] Optimize images
2022-01-29 18:37:34 +08:00
ImgBotApp
481c1774ed [ImgBot] Optimize images
*Total -- 161.14kb -> 53.31kb (66.92%)

/images/step1.png -- 27.95kb -> 7.53kb (73.06%)
/images/mru.png -- 38.12kb -> 10.42kb (72.68%)
/images/fzf.png -- 29.02kb -> 8.47kb (70.81%)
/images/complete-2.png -- 28.69kb -> 9.05kb (68.46%)
/images/complete-1.png -- 12.35kb -> 5.12kb (58.53%)
/images/step2.png -- 12.63kb -> 5.66kb (55.16%)
/images/step3.png -- 7.56kb -> 3.63kb (52.03%)
/images/step4.png -- 4.83kb -> 3.44kb (28.77%)

Signed-off-by: ImgBotApp <ImgBotHelp@gmail.com>
2022-01-29 07:03:13 +00:00
Linwei
35e1199eff Merge pull request #145 from doubleloop/zluaexec
Try luajit in zsh and fish, fix ZLUA_EXEC check
2021-11-14 01:40:55 +08:00
Jakub Łuczyński
99dbe7b677 Mention support for luajit in README 2021-11-13 11:29:00 +01:00
Jakub Łuczyński
c88746629b zsh plugin: fix ZLUA_EXEC check
Previous check required full path (even if value was available in PATH)
2021-11-13 10:33:41 +01:00
Jakub Łuczyński
336e95b05a Try luajit in zsh and fish 2021-11-13 10:32:59 +01:00
Linwei
a3d4f5db68 Merge pull request #138 from FlTr/path-exists-17
path valid if error code 17 by os.rename
2021-05-05 16:41:06 +08:00
TRF2SGM
a991162428 #136 path valid if error code 17 by os.rename 2021-05-03 12:13:34 +02:00
Linwei
8210c56414 Merge pull request #132 from ilyagr/patch-1
Improve Fish installation instructions
2021-03-08 23:16:40 +08:00
Ilya Grigoriev
a01b28a8d3 Fixup #2 2021-03-08 01:26:22 -08:00
Ilya Grigoriev
695533cee1 Fixup 2021-03-08 01:17:50 -08:00
Ilya Grigoriev
58425dad65 Improve Fish installation instructions
Most notably, this adds instructions of changing $_Z_CD.  I think many
`fish` users would find them useful.
See https://github.com/skywind3000/z.lua/pull/131 for more background.

This makes the installation instructions more conventional (`|source` 
instead of `psub`). This also deletes the second (equivalent) set of instructions.
If the warning in that sentence is important, we could add it back, but
it would apply to all the shells, wouldn't it?

Finally, some wording is improved.
2021-03-08 01:15:26 -08:00
Linwei
44a2489ba3 Merge pull request #131 from ilyagr/add_builtin_cd_doc
Add default to docs for $_ZL_CD
2021-03-04 22:28:18 +08:00
Ilya Grigoriev
6e01d4ad52 Add default to docs for $_ZL_CD
I don't know if the default of `builtin cd` is a good one, as opposed to simple `cd`. It took me quite a bit of debugging before I figured out why, on my `fish` shell, changing directories with `z.lua` messed up the `cdh` (cd history) command.

I think the best thing would be to change the default. However, if you have a good reason to stick with it, I thought that documenting this potentially unexpected behavior might help.
2021-03-04 00:56:51 -08:00
skywind3000
c3c15a3ca9 remove redundant comments 2021-02-15 05:13:24 +08:00
skywind3000
cfad8f54ce update doc 2021-02-15 00:06:38 +08:00
skywind3000
501f619f94 improve powershell 7 compatibility 2021-02-15 00:02:23 +08:00
skywind3000
7a8acd469d update z.lua to 1.8.11 2020-12-31 02:11:09 +08:00
skywind3000
52e066aae7 commit new z.lua 2020-12-31 02:05:46 +08:00
skywind3000
e1a44ee9a5 fix: pushd leak in windows cmd 2020-12-31 01:47:18 +08:00
Linwei
9c0eb6cfbc Merge pull request #127 from chrisant996/fixpushd
Fix leaked pushd
2020-12-30 23:01:17 +08:00
Chris Antos
e646d5baa5 A better fix for the final blank line. 2020-12-30 05:00:26 -08:00
Chris Antos
be90b1a528 Match original output.
Originally `z foo` printed a blank line after the command.  My recent
change accidentally changed how CMD interpreted the end of the file such
that CMD stopped printing the blank line.  This change adjusts the end
of the file to once again cause CMD to print a blank line on finish.
2020-12-30 04:50:29 -08:00
Chris Antos
bda94435fc Fix leaked pushd.
`z somedir` uses double `pushd` to tunnel the new path out past the
endlocal that restores the environment state.  But it ended up leaving
a pushd on the dir stack.

This change exploits normal variable expansion to restore the dir stack
to its initial state while still successfully tunneling the new path out
past the endlocal.
2020-12-30 04:42:05 -08:00
skywind3000
831d617cef improve clink 1.1 compatibility 2020-12-24 15:27:48 +08:00
Linwei
97fa941ac3 Merge pull request #126 from chrisant996/master
Add flags to the `z` arg matcher for Clink.
2020-12-24 10:36:57 +08:00
Chris Antos
c0ff299d67 Add flags to the z arg matcher for Clink. 2020-12-23 14:48:48 -08:00
skywind3000
3deb8c7b5c advance version number 2020-12-23 16:37:56 +08:00
Linwei
222b28571f Merge pull request #125 from fcying/master
add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority.
2020-12-23 16:36:16 +08:00
fcying
48a77adf35 add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority. 2020-12-23 14:41:27 +08:00
Linwei
72c3676344 Merge pull request #123 from kankaristo/patch-1
Fix `z -I` in ranger_zlua.py
2020-11-25 22:12:30 +08:00
Sami Kankaristo
9dc5875fa3 Fix z -I in ranger_zlua.py
`z -I` had 2 issues:
- it used  `subprocess.check_output()`, but didn't UTF-8 decode the string (like the `if mode` statement's `else` branch does on row 80)
- it wasn't actually interactive, like `-I` is supposed to be (subprocess.check_output()` is not interactive)

I'm not sure why `-I` mode was originally treated differently from e.g. `-i` mode, but the same code works for both.

I took the `redraw_window` console command from the original `-I` mode code, because without it the screen updates a bit slower, causing an ugly "flash".
2020-11-25 14:19:08 +02:00
skywind3000
c90279b677 expose '--add' in cmd.exe 2020-10-31 18:59:03 +08:00
Linwei
9fb8cadda3 Merge pull request #120 from azuwis/master
Use `command -v` to reduce zsh startup time
2020-10-22 11:50:19 +08:00
Zhong Jianxin
edd92d935d Use command -v to reduce zsh startup time 2020-10-22 10:55:23 +08:00
Linwei
7848a0a2f3 Merge pull request #114 from ayalhw/patch-1
Update Fisher compatibility
2020-08-09 14:59:25 +08:00
Coelacanthus
515da0a3d1 Update Fisher compatibility
更新 fisher 路径
https://github.com/jorgebucaran/fisher/pull/571
2020-08-09 13:14:07 +08:00
Linwei
aebd18cec4 Merge pull request #113 from 3usi9/master
Add Powershell support
2020-08-04 17:48:34 +08:00
3usi9
90223cf10b Add Powershell support 2020-08-04 17:37:46 +08:00
Linwei
d666c93ed9 Merge pull request #111 from stigkj/patch-1
Fix benchmark table markdown formatting
2020-08-01 02:45:46 +08:00
Stig Kleppe-Jørgensen
805e5c24f3 Fix benchmark table markdown formatting 2020-07-31 17:31:16 +02:00
skywind3000
65bfbf8dfb update lfs detection 2020-06-29 19:40:55 +08:00
skywind3000
1b9630e72d Merge branch 'master' of https://github.com/skywind3000/z.lua 2020-06-29 18:11:32 +08:00
skywind3000
c98d2d783e use lfs module or cffi in luajit if possible 2020-06-29 18:11:23 +08:00
Linwei
057e4f77f3 Merge pull request #108 from exic/patch-1
Update README.md
2020-05-29 17:34:37 +08:00
Jonas
8a90ca6df4 Update README.md
Fix typo
2020-05-29 11:14:38 +02:00
skywind3000
a4c51d8103 update doc 2020-03-28 19:48:20 +08:00
skywind3000
b40df870a6 update doc 2020-03-18 22:47:05 +08:00
skywind3000
a55bb87e1b update docs 2020-03-18 22:38:46 +08:00
skywind3000
c4512b47d2 update doc 2020-03-18 22:36:35 +08:00
skywind3000
6c567b60b3 update doc 2020-03-17 23:12:08 +08:00
skywind3000
8fff9e6471 update doc 2020-03-17 23:11:13 +08:00
skywind3000
f7a9104983 update z.lua 2020-03-17 16:38:30 +08:00
skywind3000
7b43a0afd6 Merge branch 'master' of https://github.com/skywind3000/z.lua 2020-03-17 16:37:48 +08:00
skywind3000
788c0f4b77 new --init option clean to skip hooks 2020-03-17 16:37:21 +08:00
skywind3000
47aa86b0f9 remove files 2020-03-17 11:37:04 +08:00
skywind3000
a1498c8672 update 2020-03-17 02:35:21 +08:00
skywind3000
4c34e29e08 update 2020-03-17 02:26:49 +08:00
skywind3000
3d188ab6d9 update 2020-03-17 02:05:41 +08:00
skywind3000
a5f4cb692c update 2020-03-17 00:50:27 +08:00
skywind3000
77a917d116 update czmod.z 2020-03-17 00:20:06 +08:00
skywind3000
93e9715e7d commit new iposix.c/.h 2020-03-16 23:11:09 +08:00
skywind3000
b7c3fbc4ee update new imembase.c 2020-03-16 22:44:24 +08:00
skywind3000
ebda4aa061 update module 2020-03-16 22:30:50 +08:00
skywind3000
168ec49849 update 2020-03-16 18:48:26 +08:00
skywind3000
ec123de01a update 2020-03-12 18:35:03 +08:00
skywind3000
a0d4750431 commit czmod 2020-03-11 16:23:14 +08:00
skywind3000
d615051a10 improve compinit handling 2020-03-08 00:14:04 +08:00
skywind3000
f448f2ab1f suppress compdef error message if compinit hasn't been invoked. 2020-03-05 18:09:21 +08:00
Linwei
8ed3422670 Merge pull request #93 from Aloxaf/no_compctl
Improve zsh's completion
2020-02-28 17:26:27 +08:00
Aloxaf
3edbda89a0 Improve zsh's completion 2020-02-28 15:32:30 +08:00
Linwei
c9b50b3c50 Merge pull request #92 from kidonng/add-fisher-compatibility
添加 Fisher 支持
2020-02-23 17:28:34 +08:00
Kid
228addbc49 Add Fisher compatibility 2020-02-23 13:48:37 +08:00
skywind3000
bca25eba12 fish shell: set $_ZL_ECHO in global scope 2020-02-10 19:26:22 +08:00
skywind3000
097ca07ecd update fish script 2020-02-10 18:24:20 +08:00
skywind3000
4ee783956d update doc 2020-02-10 10:52:03 +08:00
skywind3000
0effba4021 polish: 1.8.3 2020-02-10 00:14:09 +08:00
skywind3000
cada42e5ea z.lua 1.8.3: polish interactive mode in z -b -i 2020-02-10 00:09:08 +08:00
skywind3000
b8b6d1afd6 z.lua 1.8.2 2020-02-09 23:46:35 +08:00
skywind3000
4abe97f989 jump backwards 2020-02-09 23:39:36 +08:00
skywind3000
756d13d8fa zlua 1.8.1: new -b -i and -b -I for interactive backwards cd 2020-02-09 23:34:37 +08:00
skywind3000
4900651af3 Merge branch 'master' of https://github.com/skywind3000/z.lua 2019-12-29 04:59:20 +08:00
skywind3000
836efd3973 1.7.4: new $_ZL_HYPHEN option 2019-12-29 04:59:08 +08:00
Linwei
3b8b4c1fbb Merge pull request #87 from davidosomething/no-aliases
Introduce _ZL_NO_ALIASES to skip creating aliases
2019-12-26 00:35:12 +08:00
David O'Trakoun
8eaebca04a Introduce _ZL_NO_ALIASES to skip creating aliases 2019-12-25 00:16:44 -05:00
Linwei
fdd037acf8 Merge pull request #85 from rongmu/_zl_fzf_flag-fix
[zsh plugin] allow the user to customize _ZL_FZF_FLAG beforehand
2019-12-10 17:45:04 +08:00
Shaoyun Yu
a817cf6ed2 allow the user to custom _ZL_FZF_FLAG beforehand
increase flexibility: allow the user to custom _ZL_FZF_FLAG before the zsh plugin is loaded
2019-12-10 10:50:55 +09:00
skywind3000
5c36d55698 use lua-filesystem package if possible when $_ZL_USE_LFS is 1 2019-09-07 01:02:48 +08:00
skywind3000
bdab27db1b fixed wrong return value from os.path.exists 2019-09-06 01:21:28 +08:00
skywind3000
e08f5beca4 update doc 2019-08-01 20:06:05 +08:00
15 changed files with 377 additions and 96 deletions

View File

@@ -66,6 +66,11 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
就可以了(主要要放在 antigen apply 语句之前)。 就可以了(主要要放在 antigen apply 语句之前)。
**注意**:使用 WSL-1 的用户,需要安装 `lua-filesystem` 包:
sudo apt-get install lua-filesystem
这是由于 wsl-1 的 [bug](https://github.com/microsoft/WSL/issues/5505) 引起的,使用 lua-filesystem 可以避免该问题。
- Fish Shell: - Fish Shell:
@@ -83,7 +88,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句: 在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句:
iex ($(lua /path/to/z.lua --init powershell) -join "`n") Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink): - Windows cmd (with clink):
@@ -111,6 +116,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
- 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。 - 设置 `$_ZL_CD` 用来指定你想用的 cd 命令,比如有人用 cd_func 。
- 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。 - 设置 `$_ZL_ECHO` 为 1 可以在跳转后显示目标路径名称。
- 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。 - 设置 `$_ZL_MATCH_MODE` 为 1 可以打开 “增强匹配模式”。
- 设置 `$_ZL_HYPHEN` 为 1 可以允许关键字中包含横线 (横线默认是 lua 正则关键字,要转写成 `%-`)。
## Aging ## Aging
@@ -175,7 +181,7 @@ 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"` 可以打更少的字。
@@ -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**`zb ..` 相当于 `cd ..``zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。
**Bonus**: 试试 `z -b -i` 以及 `z -b -I`,推荐把他们取个别名成 `zbi` 和 `zbf`。
## 补全功能 ## 补全功能

View File

@@ -13,19 +13,29 @@ z.lua is a faster way to navigate your filesystem. It tracks your most used dire
For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`. For example, `z foo bar` would match `/foo/bar` but not `/bar/foo`.
## Reputation
From people using z.lua:
- I like this in principal. Im pretty damn predictable at the command line and far too lazy to make shortcuts
- It feels far more intuitive and it's so incredibly convenient to be able to jump between folders I'm working in without having to traverse an entire tree. The shell used to feel so constraining for me, but tools like this are making me enjoy it so much more.
- I can finally have autojump-like functionality on my Raspberry Pi 1 without waiting 30 seconds every time I open a new shell. Thanks z.lua devs.
- Anyway, z.lua is a promising project. If you only need directory jumping, it may be the best choice.
## Features ## Features
- **10x** times faster than **fasd** and **autojump**, **3x** times faster than **z.sh**. - **10x** times faster than **fasd** and **autojump**, **3x** times faster than **z.sh**.
- Gain the ultimate speed with an optional [native module](https://github.com/skywind3000/czmod) written in C.
- Available for **posix shells**: bash, zsh, dash, sh, ash, ksh, busybox and etc. - Available for **posix shells**: bash, zsh, dash, sh, ash, ksh, busybox and etc.
- Available for Fish Shell, Power Shell and Windows cmd. - Available for Fish Shell, Power Shell and Windows cmd.
- [Enhanced matching algorithm](#enhanced-matching) takes you to where ever you want precisely. - [Enhanced matching algorithm](#enhanced-matching) takes you to where ever you want precisely.
- Allow updating database only if `$PWD` changed with "$_ZL_ADD_ONCE" set to 1. - Allow updating database only if `$PWD` changed with "$_ZL_ADD_ONCE" set to 1.
- Interactive selection enables you to choose where to go before cd. - Interactive selection enables you to choose where to go before cd.
- Intergrated with FZF (optional) for interactive selection and completion. - Integrated with FZF (optional) for interactive selection and completion.
- Quickly go back to a parent directory instead of typing "cd ../../..". - Quickly go back to a parent directory instead of typing "cd ../../..".
- Corresponding experience in different shells and operating systems. - Corresponding experience in different shells and operating systems.
- Compatible with Lua 5.1, 5.2 and 5.3+ - Compatible with Lua (5.1, 5.2, 5.3+) and luajit.
- Self contained, distributed as a single `z.lua` script, no other dependence. - Self contained, distributed as a single `z.lua` script, no other dependence.
@@ -59,14 +69,20 @@ z -b foo # cd to the parent directory starting with foo
and perhaps this: and perhaps this:
export _ZL_ECHO=1 eval "$(lua /path/to/z.lua --init bash enhanced once echo)"
if you want `z.lua` print the new directory after cd. if you want `z.lua` print the new directory after cd.
If you want `fzf` tab completion use: For `fzf` tab completion use:
eval "$(lua /path/to/z.lua --init bash enhanced once fzf)" eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"
**NOTE**: For wsl-1 users, `lua-filesystem` must be installed:
sudo apt-get install lua-filesystem
To avoid a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
- Zsh: - Zsh:
put something like this in your `.zshrc`: put something like this in your `.zshrc`:
@@ -75,6 +91,8 @@ z -b foo # cd to the parent directory starting with foo
Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh). Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).
**NOTE**: for wsl-1 users, `lua-filesystem` must be installed.
- Posix Shells: - Posix Shells:
put something like this in your `.profile`: put something like this in your `.profile`:
@@ -87,37 +105,47 @@ z -b foo # cd to the parent directory starting with foo
To generate old posix compatible script. To generate old posix compatible script.
- Fish Shell: - Fish Shell (version `2.4.0` or above):
Create `~/.config/fish/conf.d/z.fish` with following code Create `~/.config/fish/conf.d/z.fish` with following code
source (lua /path/to/z.lua --init fish | psub) lua /path/to/z.lua --init fish | source
Fish version `2.4.0` or above is required. If you'd like `z.lua` to cooperate with fish's own [directory history](https://fishshell.com/docs/3.2/index.html#id34), you can put
lua /path/to/z.lua --init fish > ~/.config/fish/conf.d/z.fish set -gx _ZL_CD cd
This is another way to initialize z.lua in fish shell, but remember to regenerate z.fish if z.lua has been updated or moved. into the same file.
- Power Shell: - Power Shell:
> ⚠️ **WARNING**: users of [Starship Prompt](https://starship.rs/) should add the following command *after* `starship init`.
put something like this in your `profile.ps1`: put something like this in your `profile.ps1`:
iex ($(lua /path/to/z.lua --init powershell) -join "`n") Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
- Windows cmd (with clink): - Windows cmd (with clink):
- copy z.lua and z.cmd to clink's home directory - Copy z.lua and z.cmd to clink's home directory
- Add clink's home to `%PATH%` (z.cmd can be called anywhere) - Add clink's home to `%PATH%` (z.cmd can be called anywhere)
- Ensure that "lua" can be called in `%PATH%` - Ensure that "lua" can be called in `%PATH%`
- Windows cmder: - Windows cmder:
- copy z.lua and z.cmd to cmder/vendor - Copy z.lua and z.cmd to cmder/vendor
- Add cmder/vendor to `%PATH%` - Add cmder/vendor to `%PATH%`
- Ensure that "lua" can be called in `%PATH%` - Ensure that "lua" can be called in `%PATH%`
- Windows WSL-1:
Install `lua-filesystem` module before init z.lua:
sudo apt-get install lua-filesystem
This module is required due to a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
## Options ## Options
@@ -127,10 +155,12 @@ z -b foo # cd to the parent directory starting with foo
- set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude. - set `$_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude.
- set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed. - set `$_ZL_ADD_ONCE` to '1' to update database only if `$PWD` changed.
- set `$_ZL_MAXAGE` to define a aging threshold (default is 5000). - set `$_ZL_MAXAGE` to define a aging threshold (default is 5000).
- set `$_ZL_CD` to specify your own cd command. - set `$_ZL_CD` to specify your own cd command (default is `builtin cd` in Unix shells).
- set `$_ZL_ECHO` to 1 to display new directory name after cd. - set `$_ZL_ECHO` to 1 to display new directory name after cd.
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching. - set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean - set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
- set `$_ZL_HYPHEN` to 1 to treat hyphon (-) as a normal character not a lua regexp keyword.
- set `$_ZL_CLINK_PROMPT_PRIORITY` change clink prompt register priority (default 99).
## Aging ## Aging
@@ -195,7 +225,7 @@ If no match is found, it will fall back to default matching method.
30 /home/user/workspace/project2 30 /home/user/workspace/project2
40 /home/user/workspace/project3 40 /home/user/workspace/project3
If you use `"z wo"` in enhanced matching mode, only the `/home/user/work` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`. If you use `"z wo"` in enhanced matching mode, only the `/home/user/workspace` will be matched, because according to rule No.2 it is the only path whose last segment matches `"wo"`.
Since the last segment of a path is always easier to be recalled, it is sane to give it higher priority. You can also achieve this by typing `"z space$"` in both methods, but `"z wo"` is easier to type. Since the last segment of a path is always easier to be recalled, it is sane to give it higher priority. You can also achieve this by typing `"z space$"` in both methods, but `"z wo"` is easier to type.
@@ -240,7 +270,7 @@ To enable this, you can set `$_ZL_ADD_ONCE` to `1` before init z.lua. Or you can
````bash ````bash
eval "$(lua /path/to/z.lua --init bash once)" eval "$(lua /path/to/z.lua --init bash once)"
eval "$(lua /path/to/z.lua --init zsh once)" eval "$(lua /path/to/z.lua --init zsh once)"
source (lua /path/to/z.lua --init fish once | psub) lua /path/to/z.lua --init fish once | source
```` ````
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. 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.
@@ -322,6 +352,7 @@ If you want `zb` jump back to a parent directory contains a `.root` or `package.
**Bonus**: `zb ..` equals to `cd ..`, `zb ...` equals to `cd ../..` and `zb ....` equals to `cd ../../..`, and so on. Finally, `zb ..20` equals to `cd (..)x20`. **Bonus**: `zb ..` equals to `cd ..`, `zb ...` equals to `cd ../..` and `zb ....` equals to `cd ../../..`, and so on. Finally, `zb ..20` equals to `cd (..)x20`.
**Bonus**: try `z -b -i` and `z -b -I` and you can alias them to `zbi` and `zbf`.
## Completion ## Completion
@@ -446,18 +477,30 @@ sys 0m0.030s
As you see, z.lua is the fastest one and requires less resource. As you see, z.lua is the fastest one and requires less resource.
## Native Module
z.lua is fast enough for most case, the path tracking action will be triggered each time when you change your current directory.
## Reputation So I still recommend the pure lua script for portability and flexibility, but for someone who really care about `10ms` or `1ms` things, this module can help them to gain the ultimate speed.
- [czmod](https://github.com/skywind3000/czmod): native module to boost `z.lua`.
Average performance:
| Name | czmod | z.lua |
|-|-|-|
| **Update Time** | 1.6ms | 13.2ms |
| **Query Time** | 1.5ms | 9.8ms |
- "I like this in principal. Im pretty damn predictable at the command line and far too lazy to make shortcuts"
- "It feels far more intuitive and it's so incredibly convenient to be able to jump between folders I'm working in without having to traverse an entire tree. The shell used to feel so constraining for me, but tools like this are making me enjoy it so much more. "
- "I can finally have autojump-like functionality on my Raspberry Pi 1 without waiting 30 seconds every time I open a new shell. Thanks z.lua devs."
- "Anyway, z.lua is a promising project. If you only need directory jumping, it may be the best choice."
## History ## History
- 1.8.7 (2020-06-29): use lfs or luajit's cffi if possible.
- 1.8.4 (2020-02-10): fish shell: set `$_ZL_ECHO` to global scope.
- 1.8.3 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
- 1.7.4 (2019-12-29): new: `$_ZL_HYPHEN` to treat hyphen as a normal character, see [here](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-input-a-hyphen---in-the-keyword-).
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik). - 1.7.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.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.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 +555,7 @@ This project needs help for the tasks below:
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting. - Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting.
- Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting. - Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting.
- Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash. - Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash.
- Thanks to [@barlik](https://github.com/barlik) for many improvements.
And many others. And many others.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@@ -17,11 +17,18 @@ end
set -x _ZL_DATA "$_ZL_DATA" set -x _ZL_DATA "$_ZL_DATA"
set _zlua_dir (dirname (status --current-filename)) set -q XDG_DATA_HOME; or set XDG_DATA_HOME ~/.local/share
if functions -q fisher
set _zlua_dir $XDG_DATA_HOME/fisher/github.com/skywind3000/z.lua
else
set _zlua_dir (dirname (status --current-filename))
end
if test -e $_zlua_dir/z.lua if test -e $_zlua_dir/z.lua
if type -q lua if type -q lua
lua $_zlua_dir/z.lua --init fish enhanced once echo | source lua $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q luajit
luajit $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q lua5.3 else if type -q lua5.3
lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source lua5.3 $_zlua_dir/z.lua --init fish enhanced once echo | source
else if type -q lua5.2 else if type -q lua5.2
@@ -35,6 +42,8 @@ if test -e $_zlua_dir/z.lua
alias zz='z -i' # cd with interactive selection alias zz='z -i' # cd with interactive selection
alias zf='z -I' # use fzf to select in multiple matches alias zf='z -I' # use fzf to select in multiple matches
alias zb='z -b' # quickly cd to the parent directory alias zb='z -b' # quickly cd to the parent directory
alias zbi='z -b -i' # interactive jump backward
alias zbf='z -b -I' # interactive jump backward with fzf
set -U ZLUA_SCRIPT "$ZLUA_SCRIPT" 2> /dev/null set -U ZLUA_SCRIPT "$ZLUA_SCRIPT" 2> /dev/null
set -U ZLUA_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null set -U ZLUA_LUAEXE "$ZLUA_LUAEXE" 2> /dev/null
end end

View File

@@ -69,14 +69,10 @@ class z(ranger.api.commands.Command):
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True) p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
else: else:
if mode == '-I': p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
os.environ['_ZL_FZF_HEIGHT'] = '0' stdout, stderr = p.communicate()
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args) path = stdout.rstrip('\n')
self.fm.execute_console('redraw_window') 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): if path and os.path.exists(path):
self.fm.cd(path) self.fm.cd(path)
else: else:

22
z.cmd
View File

@@ -54,6 +54,12 @@ if /i "%1"=="-x" (
goto parse goto parse
) )
if /i "%1"=="--add" (
set "RunMode=--add"
shift /1
goto parse
)
if "%1"=="-i" ( if "%1"=="-i" (
set "InterMode=-i" set "InterMode=-i"
shift /1 shift /1
@@ -100,13 +106,27 @@ if /i "%RunMode%"=="-n" (
pushd !NewPath! pushd !NewPath!
pushd !NewPath! pushd !NewPath!
endlocal endlocal
popd goto popdir
) )
) )
) else ( ) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %* call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
) )
goto end
:popdir
rem -- Exploits variable expansion and the pushd stack to set the current
rem -- directory without leaking a pushd.
popd
setlocal
set "NewPath=%CD%"
set "CDCmd=cd /d"
if /i not "%_ZL_CD%"=="" (
set "CDCmd=%_ZL_CD%"
)
endlocal & popd & %CDCmd% "%NewPath%"
:end :end
echo. echo.

261
z.lua
View File

@@ -1,10 +1,10 @@
#! /usr/bin/env lua #! /usr/bin/env lua
--===================================================================== --=====================================================================
-- --
-- z.lua - a cd command that learns, by skywind 2018, 2019 -- z.lua - a cd command that learns, by skywind 2018-2022
-- Licensed under MIT license. -- Licensed under MIT license.
-- --
-- Version 1.7.2, Last Modified: 2019/08/01 19:45 -- Version 1.8.16, Last Modified: 2022/07/21 22:12
-- --
-- * 10x faster than fasd and autojump, 3x faster than z.sh -- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox -- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -49,9 +49,9 @@
-- source (lua /path/to/z.lua --init fish | psub) -- source (lua /path/to/z.lua --init fish | psub)
-- --
-- Power Shell Install: -- Power Shell Install:
--
-- * put something like this in your config file: -- * put something like this in your config file:
-- iex ($(lua /path/to/z.lua --init powershell) -join "`n") -- Invoke-Expression (& {
-- (lua /path/to/z.lua --init powershell) -join "`n" })
-- --
-- Windows Install (with Clink): -- Windows Install (with Clink):
-- * copy z.lua and z.cmd to clink's home directory -- * copy z.lua and z.cmd to clink's home directory
@@ -63,6 +63,10 @@
-- * Add cmder/vendor to %PATH% -- * Add cmder/vendor to %PATH%
-- * Ensure that "lua" can be called in %PATH% -- * Ensure that "lua" can be called in %PATH%
-- --
-- Windows WSL-1:
-- * Install lua-filesystem module before init z.lua:
-- sudo apt-get install lua-filesystem
--
-- Configure (optional): -- Configure (optional):
-- set $_ZL_CMD in .bashrc/.zshrc to change the command (default z). -- set $_ZL_CMD in .bashrc/.zshrc to change the command (default z).
-- set $_ZL_DATA in .bashrc/.zshrc to change the datafile (default ~/.zlua). -- set $_ZL_DATA in .bashrc/.zshrc to change the datafile (default ~/.zlua).
@@ -74,6 +78,8 @@
-- set $_ZL_MAXAGE to define a aging threshold (default is 5000). -- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
-- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode. -- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
-- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear. -- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear.
-- set $_ZL_USE_LFS to 1 to use lua-filesystem package
-- set $_ZL_HYPHEN to 1 to stop treating hyphen as a regexp keyword
-- --
--===================================================================== --=====================================================================
@@ -120,6 +126,7 @@ Z_CMD = 'z'
Z_MATCHMODE = 0 Z_MATCHMODE = 0
Z_MATCHNAME = false Z_MATCHNAME = false
Z_SKIPPWD = false Z_SKIPPWD = false
Z_HYPHEN = false
os.LOG_NAME = os.getenv('_ZL_LOG_NAME') os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
@@ -316,14 +323,16 @@ if os.native.status then
uint32_t GetTickCount(void); uint32_t GetTickCount(void);
uint32_t GetFileAttributesA(const char *name); uint32_t GetFileAttributesA(const char *name);
uint32_t GetCurrentDirectoryA(uint32_t size, char *ptr); uint32_t GetCurrentDirectoryA(uint32_t size, char *ptr);
uint32_t GetShortPathNameA(const char *longname, char *shortname, uint32_t size);
uint32_t GetLongPathNameA(const char *shortname, char *longname, uint32_t size);
]] ]]
local kernel32 = ffi.load('kernel32.dll') local kernel32 = ffi.load('kernel32.dll')
local buffer = ffi.new('char[?]', 300) local buffer = ffi.new('char[?]', 4100)
local INVALID_FILE_ATTRIBUTES = 0xffffffff local INVALID_FILE_ATTRIBUTES = 0xffffffff
local FILE_ATTRIBUTE_DIRECTORY = 0x10 local FILE_ATTRIBUTE_DIRECTORY = 0x10
os.native.kernel32 = kernel32 os.native.kernel32 = kernel32
function os.native.GetFullPathName(name) function os.native.GetFullPathName(name)
local hr = kernel32.GetFullPathNameA(name, 290, buffer, nil) local hr = kernel32.GetFullPathNameA(name, 4096, buffer, nil)
return (hr > 0) and ffi.string(buffer, hr) or nil return (hr > 0) and ffi.string(buffer, hr) or nil
end end
function os.native.ReplaceFile(replaced, replacement) function os.native.ReplaceFile(replaced, replacement)
@@ -336,6 +345,21 @@ if os.native.status then
function os.native.GetFileAttributes(name) function os.native.GetFileAttributes(name)
return kernel32.GetFileAttributesA(name) return kernel32.GetFileAttributesA(name)
end end
function os.native.GetLongPathName(name)
local hr = kernel32.GetLongPathNameA(name, buffer, 4096)
return (hr ~= 0) and ffi.string(buffer, hr) or nil
end
function os.native.GetShortPathName(name)
local hr = kernel32.GetShortPathNameA(name, buffer, 4096)
return (hr ~= 0) and ffi.string(buffer, hr) or nil
end
function os.native.GetRealPathName(name)
local short = os.native.GetShortPathName(name)
if short then
return os.native.GetLongPathName(short)
end
return nil
end
function os.native.exists(name) function os.native.exists(name)
local attr = os.native.GetFileAttributes(name) local attr = os.native.GetFileAttributes(name)
return attr ~= INVALID_FILE_ATTRIBUTES return attr ~= INVALID_FILE_ATTRIBUTES
@@ -349,7 +373,7 @@ if os.native.status then
return (attr % (2 * isdir)) >= isdir return (attr % (2 * isdir)) >= isdir
end end
function os.native.getcwd() function os.native.getcwd()
local hr = kernel32.GetCurrentDirectoryA(299, buffer) local hr = kernel32.GetCurrentDirectoryA(4096, buffer)
if hr <= 0 then return nil end if hr <= 0 then return nil end
return ffi.string(buffer, hr) return ffi.string(buffer, hr)
end end
@@ -503,13 +527,16 @@ function os.path.abspath(path)
return test return test
end end
end end
for _, python in pairs({'python', 'python2', 'python3'}) do for _, python in pairs({'python3', 'python2', 'python'}) do
local s = 'sys.stdout.write(os.path.abspath(sys.argv[1]))' local s = 'sys.stdout.write(os.path.abspath(sys.argv[1]))'
local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\'' local s = '-c "import os, sys;' .. s .. '" \'' .. path .. '\''
local s = python .. ' ' .. s local s = python .. ' ' .. s
local test = os.path.which(python) local test = os.path.which(python)
if test ~= nil and test ~= '' then if test ~= nil and test ~= '' then
return os.call(s) test = os.call(s)
if test ~= nil and test ~= '' then
return test
end
end end
end end
end end
@@ -548,9 +575,15 @@ end
-- file or path exists -- file or path exists
----------------------------------------------------------------------- -----------------------------------------------------------------------
function os.path.exists(name) function os.path.exists(name)
if name == '/' then
return true
end
if os.native and os.native.exists then
return os.native.exists(name)
end
local ok, err, code = os.rename(name, name) local ok, err, code = os.rename(name, name)
if not ok then if not ok then
if code == 13 then if code == 13 or code == 17 then
return true return true
elseif code == 30 then elseif code == 30 then
local f = io.open(name,"r") local f = io.open(name,"r")
@@ -1263,6 +1296,9 @@ function data_select(M, patterns, matchlast)
local pats = {} local pats = {}
for i = 1, #patterns do for i = 1, #patterns do
local p = patterns[i] local p = patterns[i]
if Z_HYPHEN then
p = p:gsub('-', '%%-')
end
table.insert(pats, case_insensitive_pattern(p)) table.insert(pats, case_insensitive_pattern(p))
end end
for i = 1, #M do for i = 1, #M do
@@ -1348,6 +1384,14 @@ function z_add(path)
end end
end end
if not skip then if not skip then
if windows then
if os.native and os.native.GetRealPathName then
local ts = os.native.GetRealPathName(path)
if ts then
path = ts
end
end
end
M = data_insert(M, path) M = data_insert(M, path)
count = count + 1 count = count + 1
end end
@@ -1576,7 +1620,7 @@ function z_cd(patterns)
io.stderr:write('> ') io.stderr:write('> ')
io.stderr:flush() io.stderr:flush()
local input = io.read('*l') local input = io.read('*l')
if input == nil then if input == nil or input == '' then
return nil return nil
end end
local index = tonumber(input) local index = tonumber(input)
@@ -1590,7 +1634,7 @@ function z_cd(patterns)
elseif Z_INTERACTIVE == 2 then elseif Z_INTERACTIVE == 2 then
local fzf = os.environ('_ZL_FZF', 'fzf') local fzf = os.environ('_ZL_FZF', 'fzf')
local tmpname = '/tmp/zlua.txt' local tmpname = '/tmp/zlua.txt'
local cmd = '--nth 2.. --reverse --inline-info --tac ' local cmd = '--nth 2.. --reverse --info=inline --tac '
local flag = os.environ('_ZL_FZF_FLAG', '') local flag = os.environ('_ZL_FZF_FLAG', '')
flag = (flag == '' or flag == nil) and '+s -e' or flag flag = (flag == '' or flag == nil) and '+s -e' or flag
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
@@ -1758,6 +1802,91 @@ function cd_minus(args, options)
end end
-----------------------------------------------------------------------
-- cd breadcrumbs: z -b -i, z -b -I
-----------------------------------------------------------------------
function cd_breadcrumbs(pwd, interactive)
local pwd = (pwd == nil or pwd == '') and os.pwd() or pwd
local pwd = os.path.normpath(pwd)
local path, _ = os.path.split(pwd)
local elements = {}
local interactive = interactive and interactive or 1
local fullname = os.environ('_ZL_FULL_PATH', false)
while true do
local head, name = os.path.split(path)
if head == path then -- reached root
table.insert(elements, {head, head})
break
elseif name ~= '' then
table.insert(elements, {name, path})
else
break
end
path = head
end
local tmpname = '/tmp/zlua.txt'
local fp = io.stderr
if interactive == 2 then
if not windows then
tmpname = os.tmpname()
else
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
end
fp = io.open(tmpname, 'w')
end
-- print table
local maxsize = string.len(tostring(#elements))
for i = #elements, 1, -1 do
local item = elements[i]
local name = item[1]
local text = string.rep(' ', maxsize - string.len(i)) .. tostring(i)
text = text .. ': ' .. (fullname and item[2] or item[1])
fp:write(text .. '\n')
end
if fp ~= io.stderr then
fp:close()
end
local retval = ''
-- select from stdin or fzf
if interactive == 1 then
io.stderr:write('> ')
io.stderr:flush()
retval = io.read('*l')
elseif interactive == 2 then
local fzf = os.environ('_ZL_FZF', 'fzf')
local cmd = '--reverse --info=inline --tac '
local flag = os.environ('_ZL_FZF_FLAG', '')
flag = (flag == '' or flag == nil) and '+s -e' or flag
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
if not windows then
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
if height ~= nil and height ~= '' and height ~= '0' then
cmd = cmd .. ' --height ' .. height
end
cmd = cmd .. '< "' .. tmpname .. '"'
else
cmd = 'type "' .. tmpname .. '" | ' .. cmd
end
retval = os.call(cmd)
os.remove(tmpname)
if retval == '' or retval == nil then
return nil
end
local pos = retval:find(':')
if not pos then
return nil
end
retval = retval:sub(1, pos - 1):gsub('^%s*', '')
end
local index = tonumber(retval)
if index == nil or index < 1 or index > #elements then
return nil
end
return elements[index][2]
end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- main entry -- main entry
----------------------------------------------------------------------- -----------------------------------------------------------------------
@@ -1792,7 +1921,11 @@ function main(argv)
if options['--cd'] or options['-e'] then if options['--cd'] or options['-e'] then
local path = '' local path = ''
if options['-b'] then if options['-b'] then
path = cd_backward(args, options) if Z_INTERACTIVE == 0 then
path = cd_backward(args, options)
else
path = cd_breadcrumbs('', Z_INTERACTIVE)
end
elseif options['-'] then elseif options['-'] then
path = cd_minus(args, options) path = cd_minus(args, options)
elseif #args == 0 then elseif #args == 0 then
@@ -1829,6 +1962,8 @@ function main(argv)
z_windows_init(opts) z_windows_init(opts)
elseif opts.fish then elseif opts.fish then
z_fish_init(opts) z_fish_init(opts)
elseif opts.powershell then
z_windows_init(opts)
else else
z_shell_init(opts) z_shell_init(opts)
end end
@@ -1864,6 +1999,7 @@ 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
@@ -1916,6 +2052,12 @@ function z_init()
Z_SKIPPWD = true Z_SKIPPWD = true
end end
end end
if _zl_hyphen ~= nil then
local m = string.lower(_zl_hyphen)
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
Z_HYPHEN = true
end
end
end end
@@ -1924,6 +2066,7 @@ end
----------------------------------------------------------------------- -----------------------------------------------------------------------
function z_clink_init() function z_clink_init()
local once = os.environ("_ZL_ADD_ONCE", false) local once = os.environ("_ZL_ADD_ONCE", false)
local _zl_clink_prompt_priority = os.environ('_ZL_CLINK_PROMPT_PRIORITY', 99)
local previous = '' local previous = ''
function z_add_to_database() function z_add_to_database()
pwd = clink.get_cwd() pwd = clink.get_cwd()
@@ -1935,7 +2078,7 @@ function z_clink_init()
end end
z_add(clink.get_cwd()) z_add(clink.get_cwd())
end end
clink.prompt.register_filter(z_add_to_database, 99) clink.prompt.register_filter(z_add_to_database, _zl_clink_prompt_priority)
function z_match_completion(word) function z_match_completion(word)
local M = z_match({word}, Z_METHOD, Z_SUBDIR) local M = z_match({word}, Z_METHOD, Z_SUBDIR)
for _, item in pairs(M) do for _, item in pairs(M) do
@@ -1945,6 +2088,8 @@ function z_clink_init()
end end
local z_parser = clink.arg.new_parser() local z_parser = clink.arg.new_parser()
z_parser:set_arguments({ z_match_completion }) z_parser:set_arguments({ z_match_completion })
z_parser:set_flags("-c", "-r", "-i", "--cd", "-e", "-b", "--add", "-x", "--purge",
"--init", "-l", "-s", "--complete", "--help", "-h")
clink.arg.register_parser("z", z_parser) clink.arg.register_parser("z", z_parser)
end end
@@ -2096,16 +2241,16 @@ fi
local script_complete_zsh = [[ local script_complete_zsh = [[
_zlua_zsh_tab_completion() { _zlua_zsh_tab_completion() {
# tab completion # tab completion
local compl
read -l compl
(( $+compstate )) && compstate[insert]=menu # no expand (( $+compstate )) && compstate[insert]=menu # no expand
reply=(${(f)"$(_zlua --complete "$compl")"}) local -a tmp=(${(f)"$(_zlua --complete "${words/_zlua/z}")"})
_describe "directory" tmp -U
} }
compctl -U -K _zlua_zsh_tab_completion _zlua if [ "${+functions[compdef]}" -ne 0 ]; then
compdef _zlua_zsh_tab_completion _zlua 2> /dev/null
fi
]] ]]
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- initialize bash/zsh -- initialize bash/zsh
---------------------------------------------------------------------- ----------------------------------------------------------------------
@@ -2126,6 +2271,10 @@ function z_shell_init(opts)
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false)) local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
local once = os.environ("_ZL_ADD_ONCE", false) or opts.once ~= nil local once = os.environ("_ZL_ADD_ONCE", false) or opts.once ~= nil
if opts.clean ~= nil then
prompt_hook = false
end
if opts.bash ~= nil then if opts.bash ~= nil then
if prompt_hook then if prompt_hook then
if once then if once then
@@ -2138,7 +2287,7 @@ function z_shell_init(opts)
end end
print(script_complete_bash) print(script_complete_bash)
if opts.fzf ~= nil then if opts.fzf ~= nil then
fzf_cmd = "fzf --nth 2.. --reverse --inline-info --tac " fzf_cmd = "fzf --nth 2.. --reverse --info=inline --tac "
local height = os.environ('_ZL_FZF_HEIGHT', '35%') local height = os.environ('_ZL_FZF_HEIGHT', '35%')
if height ~= nil and height ~= '' and height ~= '0' then if height ~= nil and height ~= '' and height ~= '0' then
fzf_cmd = fzf_cmd .. ' --height ' .. height .. ' ' fzf_cmd = fzf_cmd .. ' --height ' .. height .. ' '
@@ -2295,18 +2444,24 @@ function z_fish_init(opts)
print('set -x ZLUA_SCRIPT "' .. os.scriptname() .. '"') print('set -x ZLUA_SCRIPT "' .. os.scriptname() .. '"')
print('set -x ZLUA_LUAEXE "' .. os.interpreter() .. '"') print('set -x ZLUA_LUAEXE "' .. os.interpreter() .. '"')
local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
if opts.clean ~= nil then
prompt_hook = false
end
print(script_zlua_fish) print(script_zlua_fish)
if once then if prompt_hook then
print(script_init_fish_once) if once then
else print(script_init_fish_once)
print(script_init_fish) else
print(script_init_fish)
end
end end
print(script_complete_fish) print(script_complete_fish)
if opts.enhanced ~= nil then if opts.enhanced ~= nil then
print('set -x _ZL_MATCH_MODE 1') print('set -x _ZL_MATCH_MODE 1')
end end
if opts.echo then if opts.echo then
print('set _ZL_ECHO 1') print('set -g _ZL_ECHO 1')
end end
if opts.nc then if opts.nc then
print('set -x _ZL_NO_CHECK 1') print('set -x _ZL_NO_CHECK 1')
@@ -2357,6 +2512,11 @@ if /i "%1"=="-x" (
shift /1 shift /1
goto parse goto parse
) )
if /i "%1"=="--add" (
set "RunMode=--add"
shift /1
goto parse
)
if "%1"=="-i" ( if "%1"=="-i" (
set "InterMode=-i" set "InterMode=-i"
shift /1 shift /1
@@ -2395,12 +2555,22 @@ if /i "%RunMode%"=="-n" (
pushd !NewPath! pushd !NewPath!
pushd !NewPath! pushd !NewPath!
endlocal endlocal
popd goto popdir
) )
) )
) else ( ) else (
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %* call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
) )
goto end
:popdir
popd
setlocal
set "NewPath=%CD%"
set "CDCmd=cd /d"
if /i not "%_ZL_CD%"=="" (
set "CDCmd=%_ZL_CD%"
)
endlocal & popd & %CDCmd% "%NewPath%"
:end :end
]] ]]
@@ -2489,6 +2659,10 @@ if (!$env:_ZL_NO_PROMPT_COMMAND -and (!$global:_zlua_inited)) {
-- initialize cmd/powershell -- initialize cmd/powershell
----------------------------------------------------------------------- -----------------------------------------------------------------------
function z_windows_init(opts) function z_windows_init(opts)
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
if opts.clean ~= nil then
prompt_hook = false
end
if opts.powershell ~= nil then if opts.powershell ~= nil then
print('$script:ZLUA_LUAEXE = "' .. os.interpreter() .. '"') print('$script:ZLUA_LUAEXE = "' .. os.interpreter() .. '"')
print('$script:ZLUA_SCRIPT = "' .. os.scriptname() .. '"') print('$script:ZLUA_SCRIPT = "' .. os.scriptname() .. '"')
@@ -2505,7 +2679,9 @@ function z_windows_init(opts)
if opts.nc ~= nil then if opts.nc ~= nil then
print('$env:_ZL_NO_CHECK = 1') print('$env:_ZL_NO_CHECK = 1')
end end
print(script_init_powershell) if prompt_hook then
print(script_init_powershell)
end
else else
print('@echo off') print('@echo off')
print('setlocal EnableDelayedExpansion') print('setlocal EnableDelayedExpansion')
@@ -2539,7 +2715,34 @@ end
----------------------------------------------------------------------- -----------------------------------------------------------------------
-- testing case -- LFS optimize
-----------------------------------------------------------------------
os.lfs = {}
os.lfs.enable = os.getenv('_ZL_USE_LFS')
os.lfs.enable = '1'
if os.lfs.enable ~= nil then
local m = string.lower(os.lfs.enable)
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
os.lfs.status, os.lfs.pkg = pcall(require, 'lfs')
if os.lfs.status then
local lfs = os.lfs.pkg
os.path.exists = function (name)
return lfs.attributes(name) and true or false
end
os.path.isdir = function (name)
local mode = lfs.attributes(name)
if not mode then
return false
end
return (mode.mode == 'directory') and true or false
end
end
end
end
-----------------------------------------------------------------------
-- program entry
----------------------------------------------------------------------- -----------------------------------------------------------------------
if not pcall(debug.getlocal, 4, 1) then if not pcall(debug.getlocal, 4, 1) then
-- main script -- main script
@@ -2551,5 +2754,5 @@ if not pcall(debug.getlocal, 4, 1) then
end end
end end
-- vim: set ts=4 sw=4 tw=0 noet :

View File

@@ -2,33 +2,34 @@
ZLUA_SCRIPT="${0:A:h}/z.lua" ZLUA_SCRIPT="${0:A:h}/z.lua"
[[ -n "$ZLUA_EXEC" ]] && [[ ! -x "$ZLUA_EXEC" ]] && ZLUA_EXEC="" if [[ -n "$ZLUA_EXEC" ]] && ! which "$ZLUA_EXEC" &>/dev/null; then
echo "$ZLUA_EXEC not found"
ZLUA_EXEC=""
fi
# search lua executable # search lua executable
if [[ -z "$ZLUA_EXEC" ]]; then if [[ -z "$ZLUA_EXEC" ]]; then
if [[ -x "$(command which lua)" ]]; then for lua in lua luajit lua5.4 lua5.3 lua5.2 lua5.1; do
ZLUA_EXEC="$(command which lua)" ZLUA_EXEC="$(command -v "$lua")"
elif [[ -x "$(command which lua5.3)" ]]; then [[ -n "$ZLUA_EXEC" ]] && break
ZLUA_EXEC="$(command which lua5.3)" done
elif [[ -x "$(command which lua5.2)" ]]; then if [[ -z "$ZLUA_EXEC" ]]; then
ZLUA_EXEC="$(command which lua5.2)"
elif [[ -x "$(command which lua5.1)" ]]; then
ZLUA_EXEC="$(command which lua5.1)"
else
echo "Not find lua in your $PATH, please install it." echo "Not find lua in your $PATH, please install it."
return return
fi fi
fi fi
export _ZL_FZF_FLAG="-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