Skip to content

Commit

Permalink
z.lua 1.8.3: polish interactive mode in z -b -i
Browse files Browse the repository at this point in the history
  • Loading branch information
skywind3000 committed Feb 9, 2020
1 parent b8b6d1a commit cada42e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
24 changes: 8 additions & 16 deletions z.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '
Expand All @@ -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


Expand Down

0 comments on commit cada42e

Please sign in to comment.