mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-21 23:29:48 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfad8f54ce | ||
|
|
501f619f94 | ||
|
|
7a8acd469d | ||
|
|
52e066aae7 | ||
|
|
e1a44ee9a5 | ||
|
|
9c0eb6cfbc | ||
|
|
e646d5baa5 | ||
|
|
be90b1a528 | ||
|
|
bda94435fc | ||
|
|
831d617cef | ||
|
|
97fa941ac3 | ||
|
|
c0ff299d67 | ||
|
|
3deb8c7b5c | ||
|
|
222b28571f | ||
|
|
48a77adf35 | ||
|
|
72c3676344 | ||
|
|
9dc5875fa3 | ||
|
|
c90279b677 | ||
|
|
9fb8cadda3 | ||
|
|
edd92d935d | ||
|
|
7848a0a2f3 | ||
|
|
515da0a3d1 | ||
|
|
aebd18cec4 | ||
|
|
90223cf10b | ||
|
|
d666c93ed9 | ||
|
|
805e5c24f3 |
@@ -65,7 +65,12 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
antigen bundle skywind3000/z.lua
|
||||
|
||||
就可以了(主要要放在 antigen apply 语句之前)。
|
||||
|
||||
**注意**:使用 WSL-1 的用户,需要安装 `lua-filesystem` 包:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
这是由于 wsl-1 的 [bug](https://github.com/microsoft/WSL/issues/5505) 引起的,使用 lua-filesystem 可以避免该问题。
|
||||
|
||||
- Fish Shell:
|
||||
|
||||
@@ -83,7 +88,7 @@ z -b foo # 跳转到父目录中名称以 foo 开头的那一级
|
||||
|
||||
在你 Power Shell 的配置文件 `profile.ps1` 中放入下面语句:
|
||||
|
||||
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
|
||||
Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
|
||||
|
||||
|
||||
- Windows cmd (with clink):
|
||||
|
||||
31
README.md
31
README.md
@@ -69,13 +69,19 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
and perhaps this:
|
||||
|
||||
export _ZL_ECHO=1
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once echo)"
|
||||
|
||||
if you want `z.lua` print the new directory after cd.
|
||||
|
||||
If you want `fzf` tab completion use:
|
||||
For `fzf` tab completion use:
|
||||
|
||||
eval "$(lua /path/to/z.lua --init bash enhanced once fzf)"
|
||||
|
||||
**NOTE**: For wsl-1 users, `lua-filesystem` must be installed:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
To avoid a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
|
||||
|
||||
- Zsh:
|
||||
|
||||
@@ -85,6 +91,8 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
Options like "enhanced" and "once" can be used after `--init` too. It can also be initialized from "skywind3000/z.lua" with your zsh plugin managers (antigen / oh-my-zsh).
|
||||
|
||||
**NOTE**: for wsl-1 users, `lua-filesystem` must be installed.
|
||||
|
||||
- Posix Shells:
|
||||
|
||||
put something like this in your `.profile`:
|
||||
@@ -113,21 +121,29 @@ z -b foo # cd to the parent directory starting with foo
|
||||
|
||||
put something like this in your `profile.ps1`:
|
||||
|
||||
iex ($(lua /path/to/z.lua --init powershell) -join "`n")
|
||||
|
||||
Invoke-Expression (& { (lua /path/to/z.lua --init powershell) -join "`n" })
|
||||
|
||||
- Windows cmd (with clink):
|
||||
|
||||
- copy z.lua and z.cmd to clink's home directory
|
||||
- Copy z.lua and z.cmd to clink's home directory
|
||||
- Add clink's home to `%PATH%` (z.cmd can be called anywhere)
|
||||
- Ensure that "lua" can be called in `%PATH%`
|
||||
|
||||
- Windows cmder:
|
||||
|
||||
- copy z.lua and z.cmd to cmder/vendor
|
||||
- Copy z.lua and z.cmd to cmder/vendor
|
||||
- Add cmder/vendor to `%PATH%`
|
||||
- Ensure that "lua" can be called in `%PATH%`
|
||||
|
||||
- Windows WSL-1:
|
||||
|
||||
Install `lua-filesystem` module before init z.lua:
|
||||
|
||||
sudo apt-get install lua-filesystem
|
||||
|
||||
This module is required due to a wsl-1 [defect](https://github.com/microsoft/WSL/issues/5505).
|
||||
|
||||
|
||||
|
||||
## Options
|
||||
|
||||
@@ -142,6 +158,7 @@ z -b foo # cd to the parent directory starting with foo
|
||||
- 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_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
|
||||
|
||||
@@ -469,7 +486,7 @@ So I still recommend the pure lua script for portability and flexibility, but fo
|
||||
Average performance:
|
||||
|
||||
| Name | czmod | z.lua |
|
||||
|-|-|-|-|-|
|
||||
|-|-|-|
|
||||
| **Update Time** | 1.6ms | 13.2ms |
|
||||
| **Query Time** | 1.5ms | 9.8ms |
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ end
|
||||
|
||||
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
|
||||
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
|
||||
set _zlua_dir (dirname (status --current-filename))
|
||||
end
|
||||
|
||||
@@ -69,14 +69,10 @@ class z(ranger.api.commands.Command):
|
||||
p = self.fm.execute_command(cmd + ' 2>&1 | less +G', universal_newlines=True)
|
||||
stdout, stderr = p.communicate()
|
||||
else:
|
||||
if mode == '-I':
|
||||
os.environ['_ZL_FZF_HEIGHT'] = '0'
|
||||
path = subprocess.check_output([PATH_LUA, PATH_ZLUA, '--cd'] + args)
|
||||
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')
|
||||
p = self.fm.execute_command(cmd, universal_newlines=True, stdout=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
path = stdout.rstrip('\n')
|
||||
self.fm.execute_console('redraw_window')
|
||||
if path and os.path.exists(path):
|
||||
self.fm.cd(path)
|
||||
else:
|
||||
|
||||
18
z.cmd
18
z.cmd
@@ -54,6 +54,12 @@ if /i "%1"=="-x" (
|
||||
goto parse
|
||||
)
|
||||
|
||||
if /i "%1"=="--add" (
|
||||
set "RunMode=--add"
|
||||
shift /1
|
||||
goto parse
|
||||
)
|
||||
|
||||
if "%1"=="-i" (
|
||||
set "InterMode=-i"
|
||||
shift /1
|
||||
@@ -100,13 +106,23 @@ if /i "%RunMode%"=="-n" (
|
||||
pushd !NewPath!
|
||||
pushd !NewPath!
|
||||
endlocal
|
||||
popd
|
||||
goto popdir
|
||||
)
|
||||
)
|
||||
) else (
|
||||
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
|
||||
echo.
|
||||
|
||||
|
||||
32
z.lua
32
z.lua
@@ -1,10 +1,10 @@
|
||||
#! /usr/bin/env lua
|
||||
--=====================================================================
|
||||
--
|
||||
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020
|
||||
-- z.lua - a cd command that learns, by skywind 2018, 2019, 2020, 2021
|
||||
-- Licensed under MIT license.
|
||||
--
|
||||
-- Version 1.8.7, Last Modified: 2020/06/29 18:04
|
||||
-- Version 1.8.12, Last Modified: 2021/02/15 00:05
|
||||
--
|
||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||
@@ -51,7 +51,8 @@
|
||||
-- Power Shell Install:
|
||||
--
|
||||
-- * put something like this in your config file:
|
||||
-- iex ($(lua /path/to/z.lua --init powershell) -join "`n")
|
||||
-- Invoke-Expression (& {
|
||||
-- (lua /path/to/z.lua --init powershell) -join "`n" })
|
||||
--
|
||||
-- Windows Install (with Clink):
|
||||
-- * copy z.lua and z.cmd to clink's home directory
|
||||
@@ -63,6 +64,10 @@
|
||||
-- * Add cmder/vendor to %PATH%
|
||||
-- * Ensure that "lua" can be called in %PATH%
|
||||
--
|
||||
-- Windows WSL-1:
|
||||
-- * Install lua-filesystem module before init z.lua:
|
||||
-- sudo apt-get install lua-filesystem
|
||||
--
|
||||
-- Configure (optional):
|
||||
-- set $_ZL_CMD in .bashrc/.zshrc to change the command (default z).
|
||||
-- set $_ZL_DATA in .bashrc/.zshrc to change the datafile (default ~/.zlua).
|
||||
@@ -1955,6 +1960,8 @@ function main(argv)
|
||||
z_windows_init(opts)
|
||||
elseif opts.fish then
|
||||
z_fish_init(opts)
|
||||
elseif opts.powershell then
|
||||
z_windows_init(opts)
|
||||
else
|
||||
z_shell_init(opts)
|
||||
end
|
||||
@@ -2057,6 +2064,7 @@ end
|
||||
-----------------------------------------------------------------------
|
||||
function z_clink_init()
|
||||
local once = os.environ("_ZL_ADD_ONCE", false)
|
||||
local _zl_clink_prompt_priority = os.environ('_ZL_CLINK_PROMPT_PRIORITY', 99)
|
||||
local previous = ''
|
||||
function z_add_to_database()
|
||||
pwd = clink.get_cwd()
|
||||
@@ -2068,7 +2076,7 @@ function z_clink_init()
|
||||
end
|
||||
z_add(clink.get_cwd())
|
||||
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)
|
||||
local M = z_match({word}, Z_METHOD, Z_SUBDIR)
|
||||
for _, item in pairs(M) do
|
||||
@@ -2078,6 +2086,8 @@ function z_clink_init()
|
||||
end
|
||||
local z_parser = clink.arg.new_parser()
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -2500,6 +2510,11 @@ if /i "%1"=="-x" (
|
||||
shift /1
|
||||
goto parse
|
||||
)
|
||||
if /i "%1"=="--add" (
|
||||
set "RunMode=--add"
|
||||
shift /1
|
||||
goto parse
|
||||
)
|
||||
if "%1"=="-i" (
|
||||
set "InterMode=-i"
|
||||
shift /1
|
||||
@@ -2538,12 +2553,18 @@ if /i "%RunMode%"=="-n" (
|
||||
pushd !NewPath!
|
||||
pushd !NewPath!
|
||||
endlocal
|
||||
popd
|
||||
goto popdir
|
||||
)
|
||||
)
|
||||
) else (
|
||||
call "%LuaExe%" "%LuaScript%" "%RunMode%" %MatchType% %StrictSub% %InterMode% %StripMode% %*
|
||||
)
|
||||
goto end
|
||||
:popdir
|
||||
popd
|
||||
setlocal
|
||||
set "NewPath=%CD%"
|
||||
endlocal & popd & cd /d "%NewPath%"
|
||||
:end
|
||||
]]
|
||||
|
||||
@@ -2727,4 +2748,5 @@ if not pcall(debug.getlocal, 4, 1) then
|
||||
end
|
||||
end
|
||||
|
||||
-- vim: set ts=4 sw=4 tw=0 noet :
|
||||
|
||||
|
||||
@@ -6,15 +6,11 @@ ZLUA_SCRIPT="${0:A:h}/z.lua"
|
||||
|
||||
# search lua executable
|
||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
if [[ -x "$(command which lua)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua)"
|
||||
elif [[ -x "$(command which lua5.3)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua5.3)"
|
||||
elif [[ -x "$(command which lua5.2)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua5.2)"
|
||||
elif [[ -x "$(command which lua5.1)" ]]; then
|
||||
ZLUA_EXEC="$(command which lua5.1)"
|
||||
else
|
||||
for lua in lua lua5.3 lua5.2 lua5.1; do
|
||||
ZLUA_EXEC="$(command -v "$lua")"
|
||||
[[ -n "$ZLUA_EXEC" ]] && break
|
||||
done
|
||||
if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
echo "Not find lua in your $PATH, please install it."
|
||||
return
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user