1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-17 21:29:48 +00:00

z.lua 1.8.3: polish interactive mode in z -b -i

This commit is contained in:
skywind3000
2020-02-10 00:09:08 +08:00
parent b8b6d1afd6
commit cada42e5ea
2 changed files with 9 additions and 17 deletions

View File

@@ -460,7 +460,7 @@ As you see, z.lua is the fastest one and requires less resource.
## History
- 1.8.2 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
- 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).

24
z.lua
View File

@@ -4,7 +4,7 @@
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020
-- Licensed under MIT license.
--
-- Version 1.8.2, Last Modified: 2020/02/09 23:33
-- Version 1.8.3, Last Modified: 2020/02/10 00:05
--
-- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -1814,19 +1814,12 @@ function cd_breadcrumbs(pwd, interactive)
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()
local input = io.read('*l')
if input == nil or input == '' then
return nil
end
local index = tonumber(input)
if index == nil or index < 1 or index > #elements then
return nil
end
retval = elements[index][2]
retval = io.read('*l')
elseif interactive == 2 then
local fzf = os.environ('_ZL_FZF', 'fzf')
local cmd = '--reverse --inline-info --tac '
@@ -1852,13 +1845,12 @@ function cd_breadcrumbs(pwd, interactive)
return nil
end
retval = retval:sub(1, pos - 1):gsub('^%s*', '')
index = tonumber((retval == nil) and '0' or retval)
if index == nil or index < 1 or index > #elements then
return nil
end
retval = elements[index][2]
end
return retval
local index = tonumber(retval)
if index == nil or index < 1 or index > #elements then
return nil
end
return elements[index][2]
end