Skip to content

Commit cada42e

Browse files
author
skywind3000
committed
z.lua 1.8.3: polish interactive mode in z -b -i
1 parent b8b6d1a commit cada42e

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ As you see, z.lua is the fastest one and requires less resource.
460460

461461
## History
462462

463-
- 1.8.2 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
463+
- 1.8.3 (2020-02-09): new: `z -b -i` and `z -b -I` to jump backwards in interactive mode.
464464
- 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-).
465465
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
466466
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik).

z.lua

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020
55
-- Licensed under MIT license.
66
--
7-
-- Version 1.8.2, Last Modified: 2020/02/09 23:33
7+
-- Version 1.8.3, Last Modified: 2020/02/10 00:05
88
--
99
-- * 10x faster than fasd and autojump, 3x faster than z.sh
1010
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -1814,19 +1814,12 @@ function cd_breadcrumbs(pwd, interactive)
18141814
if fp ~= io.stderr then
18151815
fp:close()
18161816
end
1817+
local retval = ''
18171818
-- select from stdin or fzf
18181819
if interactive == 1 then
18191820
io.stderr:write('> ')
18201821
io.stderr:flush()
1821-
local input = io.read('*l')
1822-
if input == nil or input == '' then
1823-
return nil
1824-
end
1825-
local index = tonumber(input)
1826-
if index == nil or index < 1 or index > #elements then
1827-
return nil
1828-
end
1829-
retval = elements[index][2]
1822+
retval = io.read('*l')
18301823
elseif interactive == 2 then
18311824
local fzf = os.environ('_ZL_FZF', 'fzf')
18321825
local cmd = '--reverse --inline-info --tac '
@@ -1852,13 +1845,12 @@ function cd_breadcrumbs(pwd, interactive)
18521845
return nil
18531846
end
18541847
retval = retval:sub(1, pos - 1):gsub('^%s*', '')
1855-
index = tonumber((retval == nil) and '0' or retval)
1856-
if index == nil or index < 1 or index > #elements then
1857-
return nil
1858-
end
1859-
retval = elements[index][2]
18601848
end
1861-
return retval
1849+
local index = tonumber(retval)
1850+
if index == nil or index < 1 or index > #elements then
1851+
return nil
1852+
end
1853+
return elements[index][2]
18621854
end
18631855

18641856

0 commit comments

Comments
 (0)