mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-21 23:29:48 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3482460bd2 | ||
|
|
bcb5599c12 | ||
|
|
ef8767c5f0 | ||
|
|
23aeabedd9 | ||
|
|
27dceb9899 | ||
|
|
19b2d1747e | ||
|
|
7c1c73af33 | ||
|
|
b63a38b11a | ||
|
|
c524e28851 |
@@ -122,12 +122,10 @@ z -b foo bar # replace foo with bar in cwd and cd there
|
||||
|
||||
Put something like this in your `env.nu`:
|
||||
|
||||
lua /path/to/z.lua --init nushell | save -f ~/.cache/zlua.nu
|
||||
mkdir ($nu.data-dir | path join "vendor/autoload")
|
||||
lua /path/to/z.lua --init nushell | save -f ($nu.data-dir | path join "vendor/autoload/zlua.nu")
|
||||
|
||||
Then put something like this in your `config.nu`:
|
||||
|
||||
source ~/.cache/zlua.nu
|
||||
alias z = _zlua
|
||||
Note: Only Nushell v0.96+ is supported
|
||||
|
||||
- Power Shell:
|
||||
|
||||
|
||||
4
z.cmd
4
z.cmd
@@ -89,7 +89,9 @@ if /i "%1"=="--purge" (
|
||||
:check
|
||||
|
||||
if /i "%1"=="" (
|
||||
set "RunMode=-l"
|
||||
if /i "%InterMode%"=="" (
|
||||
set "RunMode=-l"
|
||||
)
|
||||
)
|
||||
|
||||
for /f "delims=" %%i in ('cd') do set "PWD=%%i"
|
||||
|
||||
51
z.lua
51
z.lua
@@ -4,7 +4,7 @@
|
||||
-- z.lua - a cd command that learns, by skywind 2018-2022
|
||||
-- Licensed under MIT license.
|
||||
--
|
||||
-- Version 1.8.18, Last Modified: 2024/04/30 17:11
|
||||
-- Version 1.8.24, Last Modified: 2025/05/24 23:04:42
|
||||
--
|
||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||
@@ -1612,21 +1612,23 @@ function z_cd(patterns)
|
||||
if patterns == nil then
|
||||
return nil
|
||||
end
|
||||
if #patterns == 0 then
|
||||
return nil
|
||||
end
|
||||
local last = patterns[#patterns]
|
||||
if last == '~' or last == '~/' then
|
||||
return os.path.expand('~')
|
||||
elseif windows and last == '~\\' then
|
||||
return os.path.expand('~')
|
||||
end
|
||||
if os.path.isabs(last) and os.path.isdir(last) then
|
||||
local size = #patterns
|
||||
if size <= 1 then
|
||||
return os.path.norm(last)
|
||||
elseif last ~= '/' and last ~= '\\' then
|
||||
return os.path.norm(last)
|
||||
if Z_INTERACTIVE == 0 then
|
||||
if #patterns == 0 then
|
||||
return nil
|
||||
end
|
||||
local last = patterns[#patterns]
|
||||
if last == '~' or last == '~/' then
|
||||
return os.path.expand('~')
|
||||
elseif windows and last == '~\\' then
|
||||
return os.path.expand('~')
|
||||
end
|
||||
if os.path.isabs(last) and os.path.isdir(last) then
|
||||
local size = #patterns
|
||||
if size <= 1 then
|
||||
return os.path.norm(last)
|
||||
elseif last ~= '/' and last ~= '\\' then
|
||||
return os.path.norm(last)
|
||||
end
|
||||
end
|
||||
end
|
||||
local M = z_match(patterns, Z_METHOD, Z_SUBDIR)
|
||||
@@ -1668,12 +1670,12 @@ function z_cd(patterns)
|
||||
local flag = os.environ('_ZL_FZF_FLAG', '')
|
||||
flag = (flag == '' or flag == nil) and '+s -e' or flag
|
||||
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
|
||||
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
||||
if height ~= nil and height ~= '' and height ~= '0' then
|
||||
cmd = cmd .. ' --height ' .. height
|
||||
end
|
||||
if not windows then
|
||||
tmpname = os.tmpname()
|
||||
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
|
||||
if height ~= nil and height ~= '' and height ~= '0' then
|
||||
cmd = cmd .. ' --height ' .. height
|
||||
end
|
||||
cmd = cmd .. ' < "' .. tmpname .. '"'
|
||||
else
|
||||
tmpname = os.tmpname():gsub('[\\:]', ''):gsub('%.', '')
|
||||
@@ -1971,13 +1973,13 @@ function main(argv)
|
||||
end
|
||||
elseif options['-'] then
|
||||
path = cd_minus(args, options)
|
||||
elseif #args == 0 then
|
||||
elseif #args == 0 and Z_INTERACTIVE == 0 then
|
||||
path = nil
|
||||
else
|
||||
path = z_cd(args)
|
||||
if path == nil and Z_MATCHMODE ~= 0 then
|
||||
local last = args[#args]
|
||||
if os.path.isdir(last) then
|
||||
if last and os.path.isdir(last) then
|
||||
path = os.path.abspath(last)
|
||||
path = os.path.norm(path)
|
||||
end
|
||||
@@ -2810,7 +2812,7 @@ end
|
||||
-- nushell
|
||||
-----------------------------------------------------------------------
|
||||
local script_zlua_nushell = [[
|
||||
def _zlua --env --wrapped [...args: string] {
|
||||
export def _zlua --env --wrapped [...args: string] {
|
||||
if ($args | length) != 0 and $args.0 == "--add" {
|
||||
with-env { _ZL_RANDOM: (random int) } { ^$env.ZLUA_LUAEXE $env.ZLUA_SCRIPT --add ...($args | skip 1) }
|
||||
} else if ($args | length) != 0 and $args.0 == "--complete" {
|
||||
@@ -2895,6 +2897,9 @@ if completer in $env.config.completions.external {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export alias z = _zlua
|
||||
|
||||
]]
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user