1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-17 13:19:48 +00:00
1. Be aware of all arguments in fzf completion.
2. Don't use regex in backward jumping (use plain text instead).
This commit is contained in:
skywind3000
2019-02-13 17:01:29 +08:00
parent 3d39b65d9e
commit 5c3e9834a5
2 changed files with 13 additions and 10 deletions

View File

@@ -446,6 +446,7 @@ As you see, z.lua is the fastest one and requires less resource.
## History
- 1.4.7 (2019-02-13): Be aware of all arguments in fzf completion, don't use regex in backward jumping (use plain text).
- 1.4.6 (2019-02-12): change: `_ZL_EXCLUDE_DIRS` to a comma separated list of dirs to exclude.
- 1.4.5 (2019-02-10): improve bash fzf completion and posix compatibility.
- 1.4.4 (2019-02-10): supports legacy posix shells like ksh, init with `z.lua --init posix legacy`.

22
z.lua
View File

@@ -4,7 +4,7 @@
-- z.lua - a cd command that learns, by skywind 2018, 2019
-- Licensed under MIT license.
--
-- Version 1.4.6, Last Modified: 2019/02/12 19:19
-- Version 1.4.7, Last Modified: 2019/02/13 16:57
--
-- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -180,7 +180,7 @@ function string:rfind(key)
return self:len(), 0
end
local length = self:len()
local start, ends = self:reverse():find(key:reverse())
local start, ends = self:reverse():find(key:reverse(), 1, true)
if start == nil then
return nil
end
@@ -1499,7 +1499,7 @@ function cd_backward(args, options, pwd)
return os.path.normpath(path)
else
local test = windows and pwd:gsub('\\', '/') or pwd
local key = '/' .. args[1]
local key = windows and args[1]:lower() or args[1]
if not key:match('%u') then
test = test:lower()
end
@@ -1507,7 +1507,12 @@ function cd_backward(args, options, pwd)
if not pos then
return nil
end
local ends = test:find('/', pos + key:len())
if pos > 1 then
if test:sub(pos - 1, pos - 1) ~= '/' then
return nil
end
end
local ends = test:find('/', pos + key:len(), 0, true)
if not ends then
ends = test:len()
end
@@ -1875,18 +1880,14 @@ local script_fzf_complete_bash = [[
if [ "$TERM" != "dumb" ] && command -v fzf >/dev/null 2>&1; then
# To redraw line after fzf closes (printf '\e[5n')
bind '"\e[0n": redraw-current-line'
_zlua_fzf_complete() {
local query="${COMP_WORDS[COMP_CWORD]}"
local selected=$(_zlua | sed "s|$HOME|\~|" | $zlua_fzf --query "$query" | sed 's/^[0-9,.]* *//')
local args=("${COMP_WORDS[@]:1}")
local selected=$(_zlua -l "${args[@]}" | sed "s|$HOME|\~|" | $zlua_fzf | sed 's/^[0-9,.]* *//')
if [ -n "$selected" ]; then
COMPREPLY=( "$selected" )
fi
printf '\e[5n'
}
complete -o bashdefault -o nospace -F _zlua_fzf_complete ${_ZL_CMD:-z}
fi
]]
@@ -1903,6 +1904,7 @@ compctl -U -K _zlua_zsh_tab_completion _zlua
]]
-----------------------------------------------------------------------
-- initialize bash/zsh
----------------------------------------------------------------------