mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-22 15:49:47 +00:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a8acd469d | ||
|
|
52e066aae7 | ||
|
|
e1a44ee9a5 | ||
|
|
9c0eb6cfbc | ||
|
|
e646d5baa5 | ||
|
|
be90b1a528 | ||
|
|
bda94435fc | ||
|
|
831d617cef | ||
|
|
97fa941ac3 | ||
|
|
c0ff299d67 | ||
|
|
3deb8c7b5c | ||
|
|
222b28571f | ||
|
|
48a77adf35 | ||
|
|
72c3676344 | ||
|
|
9dc5875fa3 | ||
|
|
c90279b677 | ||
|
|
9fb8cadda3 | ||
|
|
edd92d935d | ||
|
|
7848a0a2f3 | ||
|
|
515da0a3d1 | ||
|
|
aebd18cec4 | ||
|
|
90223cf10b | ||
|
|
d666c93ed9 | ||
|
|
805e5c24f3 |
@@ -142,6 +142,7 @@ z -b foo # cd to the parent directory starting with foo
|
|||||||
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
|
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
|
||||||
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
|
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
|
||||||
- set `$_ZL_HYPHEN` to 1 to treat hyphon (-) as a normal character not a lua regexp keyword.
|
- set `$_ZL_HYPHEN` to 1 to treat hyphon (-) as a normal character not a lua regexp keyword.
|
||||||
|
- set `$_ZL_CLINK_PROMPT_PRIORITY` change clink prompt register priority (default 99).
|
||||||
|
|
||||||
## Aging
|
## Aging
|
||||||
|
|
||||||
@@ -469,7 +470,7 @@ So I still recommend the pure lua script for portability and flexibility, but fo
|
|||||||
Average performance:
|
Average performance:
|
||||||
|
|
||||||
| Name | czmod | z.lua |
|
| Name | czmod | z.lua |
|
||||||
|-|-|-|-|-|
|
|-|-|-|
|
||||||
| **Update Time** | 1.6ms | 13.2ms |
|
| **Update Time** | 1.6ms | 13.2ms |
|
||||||
| **Query Time** | 1.5ms | 9.8ms |
|
| **Query Time** | 1.5ms | 9.8ms |
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ end
|
|||||||
|
|
||||||
set -x _ZL_DATA "$_ZL_DATA"
|
set -x _ZL_DATA "$_ZL_DATA"
|
||||||
|
|
||||||
set -q XDG_CONFIG_HOME; or set XDG_CONFIG_HOME ~/.config
|
set -q XDG_DATA_HOME; or set XDG_DATA_HOME ~/.local/share
|
||||||
if functions -q fisher
|
if functions -q fisher
|
||||||
set _zlua_dir $XDG_CONFIG_HOME/fisher/github.com/skywind3000/z.lua
|
set _zlua_dir $XDG_DATA_HOME/fisher/github.com/skywind3000/z.lua
|
||||||
else
|
else
|
||||||
set _zlua_dir (dirname (status --current-filename))
|
set _zlua_dir (dirname (status --current-filename))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,14 +69,10 @@ class z(ranger.api.commands.Command):
|
|||||||
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
|
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
|
||||||
stdout, stderr = p.communicate()
|
stdout, stderr = p.communicate()
|
||||||
else:
|
else:
|
||||||
if mode == '-I':
|
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
|
||||||
os.environ['_ZL_FZF_HEIGHT'] = '0'
|
stdout, stderr = p.communicate()
|
||||||
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
path = stdout.rstrip('\n')
|
||||||
self.fm.execute_console('redraw_window')
|
self.fm.execute_console('redraw_window')
|
||||||
else:
|
|
||||||
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
|
|
||||||
stdout, stderr = p.communicate()
|
|
||||||
path = stdout.rstrip('\n')
|
|
||||||
if path and os.path.exists(path):
|
if path and os.path.exists(path):
|
||||||
self.fm.cd(path)
|
self.fm.cd(path)
|
||||||
else:
|
else:
|
||||||
|
|||||||
18
z.cmd
18
z.cmd
@@ -54,6 +54,12 @@ if /i "%1"=="-x" (
|
|||||||
goto parse
|
goto parse
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if /i "%1"=="--add" (
|
||||||
|
set "RunMode=--add"
|
||||||
|
shift /1
|
||||||
|
goto parse
|
||||||
|
)
|
||||||
|
|
||||||
if "%1"=="-i" (
|
if "%1"=="-i" (
|
||||||
set "InterMode=-i"
|
set "InterMode=-i"
|
||||||
shift /1
|
shift /1
|
||||||
@@ -100,13 +106,23 @@ if /i "%RunMode%"=="-n" (
|
|||||||
pushd !NewPath!
|
pushd !NewPath!
|
||||||
pushd !NewPath!
|
pushd !NewPath!
|
||||||
endlocal
|
endlocal
|
||||||
popd
|
goto popdir
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
|
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
|
||||||
)
|
)
|
||||||
|
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:popdir
|
||||||
|
rem -- Exploits variable expansion and the pushd stack to set the current
|
||||||
|
rem -- directory without leaking a pushd.
|
||||||
|
popd
|
||||||
|
setlocal
|
||||||
|
set NewPath=%CD%
|
||||||
|
endlocal & popd & cd /d "%NewPath%"
|
||||||
|
|
||||||
:end
|
:end
|
||||||
echo.
|
echo.
|
||||||
|
|
||||||
|
|||||||
22
z.lua
22
z.lua
@@ -4,7 +4,7 @@
|
|||||||
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020
|
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020
|
||||||
-- Licensed under MIT license.
|
-- Licensed under MIT license.
|
||||||
--
|
--
|
||||||
-- Version 1.8.7, Last Modified: 2020/06/29 18:04
|
-- Version 1.8.11, Last Modified: 2020/12/31 02:05
|
||||||
--
|
--
|
||||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||||
@@ -1955,6 +1955,8 @@ function main(argv)
|
|||||||
z_windows_init(opts)
|
z_windows_init(opts)
|
||||||
elseif opts.fish then
|
elseif opts.fish then
|
||||||
z_fish_init(opts)
|
z_fish_init(opts)
|
||||||
|
elseif opts.powershell then
|
||||||
|
z_windows_init(opts)
|
||||||
else
|
else
|
||||||
z_shell_init(opts)
|
z_shell_init(opts)
|
||||||
end
|
end
|
||||||
@@ -2057,6 +2059,7 @@ end
|
|||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
function z_clink_init()
|
function z_clink_init()
|
||||||
local once = os.environ("_ZL_ADD_ONCE", false)
|
local once = os.environ("_ZL_ADD_ONCE", false)
|
||||||
|
local _zl_clink_prompt_priority = os.environ('_ZL_CLINK_PROMPT_PRIORITY', 99)
|
||||||
local previous = ''
|
local previous = ''
|
||||||
function z_add_to_database()
|
function z_add_to_database()
|
||||||
pwd = clink.get_cwd()
|
pwd = clink.get_cwd()
|
||||||
@@ -2068,7 +2071,7 @@ function z_clink_init()
|
|||||||
end
|
end
|
||||||
z_add(clink.get_cwd())
|
z_add(clink.get_cwd())
|
||||||
end
|
end
|
||||||
clink.prompt.register_filter(z_add_to_database, 99)
|
clink.prompt.register_filter(z_add_to_database, _zl_clink_prompt_priority)
|
||||||
function z_match_completion(word)
|
function z_match_completion(word)
|
||||||
local M = z_match({word}, Z_METHOD, Z_SUBDIR)
|
local M = z_match({word}, Z_METHOD, Z_SUBDIR)
|
||||||
for _, item in pairs(M) do
|
for _, item in pairs(M) do
|
||||||
@@ -2078,6 +2081,8 @@ function z_clink_init()
|
|||||||
end
|
end
|
||||||
local z_parser = clink.arg.new_parser()
|
local z_parser = clink.arg.new_parser()
|
||||||
z_parser:set_arguments({ z_match_completion })
|
z_parser:set_arguments({ z_match_completion })
|
||||||
|
z_parser:set_flags("-c", "-r", "-i", "--cd", "-e", "-b", "--add", "-x", "--purge",
|
||||||
|
"--init", "-l", "-s", "--complete", "--help", "-h")
|
||||||
clink.arg.register_parser("z", z_parser)
|
clink.arg.register_parser("z", z_parser)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -2500,6 +2505,11 @@ if /i "%1"=="-x" (
|
|||||||
shift /1
|
shift /1
|
||||||
goto parse
|
goto parse
|
||||||
)
|
)
|
||||||
|
if /i "%1"=="--add" (
|
||||||
|
set "RunMode=--add"
|
||||||
|
shift /1
|
||||||
|
goto parse
|
||||||
|
)
|
||||||
if "%1"=="-i" (
|
if "%1"=="-i" (
|
||||||
set "InterMode=-i"
|
set "InterMode=-i"
|
||||||
shift /1
|
shift /1
|
||||||
@@ -2538,12 +2548,18 @@ if /i "%RunMode%"=="-n" (
|
|||||||
pushd !NewPath!
|
pushd !NewPath!
|
||||||
pushd !NewPath!
|
pushd !NewPath!
|
||||||
endlocal
|
endlocal
|
||||||
popd
|
goto popdir
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) else (
|
) else (
|
||||||
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
|
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
|
||||||
)
|
)
|
||||||
|
goto end
|
||||||
|
:popdir
|
||||||
|
popd
|
||||||
|
setlocal
|
||||||
|
set "NewPath=%CD%"
|
||||||
|
endlocal & popd & cd /d "%NewPath%"
|
||||||
:end
|
:end
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ ZLUA_SCRIPT="${0:A:h}/z.lua"
|
|||||||
|
|
||||||
# search lua executable
|
# search lua executable
|
||||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||||
if [[ -x "$(command which lua)" ]]; then
|
for lua in lua lua5.3 lua5.2 lua5.1; do
|
||||||
ZLUA_EXEC="$(command which lua)"
|
ZLUA_EXEC="$(command -v "$lua")"
|
||||||
elif [[ -x "$(command which lua5.3)" ]]; then
|
[[ -n "$ZLUA_EXEC" ]] && break
|
||||||
ZLUA_EXEC="$(command which lua5.3)"
|
done
|
||||||
elif [[ -x "$(command which lua5.2)" ]]; then
|
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||||
ZLUA_EXEC="$(command which lua5.2)"
|
|
||||||
elif [[ -x "$(command which lua5.1)" ]]; then
|
|
||||||
ZLUA_EXEC="$(command which lua5.1)"
|
|
||||||
else
|
|
||||||
echo "Not find lua in your $PATH, please install it."
|
echo "Not find lua in your $PATH, please install it."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user