1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-22 15:49:47 +00:00

24 Commits

Author SHA1 Message Date
skywind3000
7a8acd469d update z.lua to 1.8.11 2020-12-31 02:11:09 +08:00
skywind3000
52e066aae7 commit new z.lua 2020-12-31 02:05:46 +08:00
skywind3000
e1a44ee9a5 fix: pushd leak in windows cmd 2020-12-31 01:47:18 +08:00
Linwei
9c0eb6cfbc Merge pull request #127 from chrisant996/fixpushd
Fix leaked pushd
2020-12-30 23:01:17 +08:00
Chris Antos
e646d5baa5 A better fix for the final blank line. 2020-12-30 05:00:26 -08:00
Chris Antos
be90b1a528 Match original output.
Originally `z foo` printed a blank line after the command.  My recent
change accidentally changed how CMD interpreted the end of the file such
that CMD stopped printing the blank line.  This change adjusts the end
of the file to once again cause CMD to print a blank line on finish.
2020-12-30 04:50:29 -08:00
Chris Antos
bda94435fc Fix leaked pushd.
`z somedir` uses double `pushd` to tunnel the new path out past the
endlocal that restores the environment state.  But it ended up leaving
a pushd on the dir stack.

This change exploits normal variable expansion to restore the dir stack
to its initial state while still successfully tunneling the new path out
past the endlocal.
2020-12-30 04:42:05 -08:00
skywind3000
831d617cef improve clink 1.1 compatibility 2020-12-24 15:27:48 +08:00
Linwei
97fa941ac3 Merge pull request #126 from chrisant996/master
Add flags to the `z` arg matcher for Clink.
2020-12-24 10:36:57 +08:00
Chris Antos
c0ff299d67 Add flags to the z arg matcher for Clink. 2020-12-23 14:48:48 -08:00
skywind3000
3deb8c7b5c advance version number 2020-12-23 16:37:56 +08:00
Linwei
222b28571f Merge pull request #125 from fcying/master
add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority.
2020-12-23 16:36:16 +08:00
fcying
48a77adf35 add _ZL_CLINK_PROMPT_PRIORITY set clink prompt register priority. 2020-12-23 14:41:27 +08:00
Linwei
72c3676344 Merge pull request #123 from kankaristo/patch-1
Fix `z -I` in ranger_zlua.py
2020-11-25 22:12:30 +08:00
Sami Kankaristo
9dc5875fa3 Fix z -I in ranger_zlua.py
`z -I` had 2 issues:
- it used  `subprocess.check_output()`, but didn't UTF-8 decode the string (like the `if mode` statement's `else` branch does on row 80)
- it wasn't actually interactive, like `-I` is supposed to be (subprocess.check_output()` is not interactive)

I'm not sure why `-I` mode was originally treated differently from e.g. `-i` mode, but the same code works for both.

I took the `redraw_window` console command from the original `-I` mode code, because without it the screen updates a bit slower, causing an ugly "flash".
2020-11-25 14:19:08 +02:00
skywind3000
c90279b677 expose '--add' in cmd.exe 2020-10-31 18:59:03 +08:00
Linwei
9fb8cadda3 Merge pull request #120 from azuwis/master
Use `command -v` to reduce zsh startup time
2020-10-22 11:50:19 +08:00
Zhong Jianxin
edd92d935d Use command -v to reduce zsh startup time 2020-10-22 10:55:23 +08:00
Linwei
7848a0a2f3 Merge pull request #114 from ayalhw/patch-1
Update Fisher compatibility
2020-08-09 14:59:25 +08:00
Coelacanthus
515da0a3d1 Update Fisher compatibility
更新 fisher 路径
https://github.com/jorgebucaran/fisher/pull/571
2020-08-09 13:14:07 +08:00
Linwei
aebd18cec4 Merge pull request #113 from 3usi9/master
Add Powershell support
2020-08-04 17:48:34 +08:00
3usi9
90223cf10b Add Powershell support 2020-08-04 17:37:46 +08:00
Linwei
d666c93ed9 Merge pull request #111 from stigkj/patch-1
Fix benchmark table markdown formatting
2020-08-01 02:45:46 +08:00
Stig Kleppe-Jørgensen
805e5c24f3 Fix benchmark table markdown formatting 2020-07-31 17:31:16 +02:00
6 changed files with 49 additions and 24 deletions

View File

@@ -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 |

View File

@@ -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

View File

@@ -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
View File

@@ -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
View File

@@ -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
]] ]]

View File

@@ -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