From b8b6d1afd6da16aecbc74caa4bd9f0d64920b901 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Sun, 9 Feb 2020 23:46:35 +0800 Subject: [PATCH] z.lua 1.8.2 --- README.cn.md | 32 +++++++++++++++++--------------- README.md | 4 ++-- z.lua | 8 +++----- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/README.cn.md b/README.cn.md index 34d252f..1034d95 100644 --- a/README.cn.md +++ b/README.cn.md @@ -14,11 +14,11 @@ z.lua 是一个快速路径切换工具,它会跟踪你在 shell 下访问过 - 性能比 **z.sh** 快三倍,比 **fasd** / **autojump** 快十倍以上。 - 支持 Posix Shell:bash, zsh, dash, sh, ash, busybox 等等。 -- 支持 Fish Shell,Power Shell 和 Windows cmd。 -- 使用增强匹配算法,更准确的带你去到你想去的地方。 -- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。 -- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。 -- 集成 fzf (可选),可以用来做可视化选择或者参数补全。 +- 支持 Fish Shell,Power Shell 和 Windows cmd。 +- 使用增强匹配算法,更准确的带你去到你想去的地方。 +- 低占用,能够仅在当前路径改变时才更新数据库(将 `$_ZL_ADD_ONCE` 设成 1)。 +- 交互选择模式,如果有多个匹配结果的话,跳转前允许你进行选择。 +- 集成 fzf (可选),可以用来做可视化选择或者参数补全。 - 快速跳转到父目录,或者项目根目录,代替反复 “cd ../../.." 。 - 兼容 lua 5.1, 5.2 和 5.3 以上版本。 - 自包含且无额外依赖,单个 `z.lua` 文件完成所有工作。 @@ -42,10 +42,10 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级 ## Install -- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等): - - 在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句: - +- Posix Shells(Bash、zsh、dash、sh 或 BusyBox 等): + + 在你的 `.bashrc`, `.zshrc` 或者 `.profile` 文件中按 shell 类型添加对应语句: + eval "$(lua /path/to/z.lua --init bash)" # BASH 初始化 eval "$(lua /path/to/z.lua --init zsh)" # ZSH 初始化 eval "$(lua /path/to/z.lua --init posix)" # Posix shell 初始化 @@ -79,8 +79,8 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级 但是第二种方法需要记得在 z.lua 位置改变或者 lua 版本升级后需要重新生成。 -- Power Shell: - +- Power Shell: + 在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句: iex ($(lua /path/to/z.lua --init powershell) -join "`n") @@ -90,7 +90,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级 - 将 z.lua 和 z.cmd 拷贝到 clink 的安装目录。 - 将 clink 的安装目录添加到 `%PATH%` (z.cmd 可以被任意位置调用到)。 - - 保证 lua 命令在你的 `%PATH%` 环境变量中。 + - 保证 lua 命令在你的 `%PATH%` 环境变量中。 - Windows cmder: @@ -161,7 +161,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语 对于一个给定的正则关键字序列(即 z 命令后面的参数),只有同时满足两个条件才算匹配成功: -1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。 +1. 正则关键字将按顺序进行匹配(这条和默认匹配法相同)。 2. 最后一个关键字可以和路径名的最后一段相匹配。 如果两条规则同时启用找不到任何结果,那么将会退回到只用规则 1 进行筛选,这两条规则是参考 fasd 引入的。 @@ -182,7 +182,7 @@ Frecency 是一个由 'recent' 和 'frequency' 组成的合成词,这个术语 小技巧: - 如果你在增强匹配算法下,想让最后一个关键字不当匹配最后一段路径名,还可以像默认匹配算法中一样匹配路径的其他部分的话,你可以在最后加一个独立的 '$' 参数,比如:`"z wo $"` - - 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。 + - 如果你在增强匹配算法下,想让最后一个关键字匹配最后一段路径名以前的部分,那么可以增加一个斜杆参数,比如:`"z wo /"`。 - 如果没法匹配,同时又存在一条路径名和关键字相同,那么 cd 过去: @@ -265,7 +265,7 @@ PS:你可以使用 `$_ZL_FZF` 环境变量来精确指明 fzf 的可执行路 `"-b"` 选项可以快速回到某一级父目录,避免重复的输入 "cd ../../.."。 -- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。 +- **(没有参数)**:`cd` 到项目根目录,即跳转到最近的包含 (.git/.svn/.hg) 的父目录。 - **(单个参数)**:`cd` 到离当前目录最近的以关键字开头的父目录,如果找不到就尝试跳到包含关键字的父目录。 - **(两个参数)**:将当前路径中的第一个关键词替换为第二个关键词。 @@ -302,6 +302,8 @@ export _ZL_ROOT_MARKERS=".git,.svn,.hg,.root,package.json" **Bonus**:`zb ..` 相当于 `cd ..`,`zb ...` 相当于 `cd ../..`,而 `zb ....` 相当于 `cd ../../..` 等等。 最后 `zb ..20` 等同于调用 `cd ..` 二十次。 +**Bonus**: 试试 `z -b -i` 以及 `z -b -I`,推荐把他们取个别名成 `zbi` 和 `zbf`。 + ## 补全功能 diff --git a/README.md b/README.md index 31b6dc6..29c203d 100644 --- a/README.md +++ b/README.md @@ -323,7 +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**: try `zb -i` and `zb -I` and you can alias them to `zbi` and `zbf`. +**Bonus**: try `z -b -i` and `z -b -I` and you can alias them to `zbi` and `zbf`. ## Completion @@ -460,7 +460,7 @@ As you see, z.lua is the fastest one and requires less resource. ## History -- 1.8.1 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode. +- 1.8.2 (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). diff --git a/z.lua b/z.lua index 76c4b74..90f342e 100755 --- a/z.lua +++ b/z.lua @@ -4,7 +4,7 @@ -- z.lua - a cd command that learns, by skywind 2018, 2019, 2020 -- Licensed under MIT license. -- --- Version 1.8.1, Last Modified: 2020/02/09 23:33 +-- Version 1.8.2, Last Modified: 2020/02/09 23:33 -- -- * 10x faster than fasd and autojump, 3x faster than z.sh -- * available for posix shells: bash, zsh, sh, ash, dash, busybox @@ -1823,7 +1823,7 @@ function cd_breadcrumbs(pwd, interactive) return nil end local index = tonumber(input) - if index < 1 or index > #elements then + if index == nil or index < 1 or index > #elements then return nil end retval = elements[index][2] @@ -1853,9 +1853,7 @@ function cd_breadcrumbs(pwd, interactive) end retval = retval:sub(1, pos - 1):gsub('^%s*', '') index = tonumber((retval == nil) and '0' or retval) - if index == nil then - return nil - elseif index < 1 or index > #elements then + if index == nil or index < 1 or index > #elements then return nil end retval = elements[index][2]