mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-22 07:39:48 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4900651af3 | ||
|
|
836efd3973 | ||
|
|
3b8b4c1fbb | ||
|
|
8eaebca04a | ||
|
|
fdd037acf8 | ||
|
|
a817cf6ed2 | ||
|
|
5c36d55698 | ||
|
|
bdab27db1b | ||
|
|
e08f5beca4 | ||
|
|
a245db0d93 | ||
|
|
dd721703c3 | ||
|
|
7920d56c89 | ||
|
|
645818ccc8 | ||
|
|
b98911a227 | ||
|
|
671830059b |
@@ -131,6 +131,7 @@ z -b foo # cd to the parent directory starting with foo
|
||||
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
|
||||
- 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.
|
||||
|
||||
## Aging
|
||||
|
||||
@@ -458,6 +459,9 @@ As you see, z.lua is the fastest one and requires less resource.
|
||||
|
||||
## History
|
||||
|
||||
- 1.7.4 (2019-12-29): new: `$_ZL_HYPHEN` to treat hyphen as a normal character, see [here](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-input-a-hyphen---in-the-keyword-).
|
||||
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
|
||||
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik).
|
||||
- 1.7.1 (2019-06-07): Fixed: `$_ZL_DATA` failure on Linux sometimes.
|
||||
- 1.7.0 (2019-03-09): Support [ranger](https://github.com/skywind3000/z.lua/wiki/FAQ#how-to-integrate-zlua-to-ranger-), fix ReplaceFile issue in luajit (windows).
|
||||
- 1.6.0 (2019-03-04): optimize with ffi module (luajit builtin module).
|
||||
@@ -511,6 +515,7 @@ This project needs help for the tasks below:
|
||||
- Thanks to [@TeddyDD](https://github.com/TeddyDD) for Fish Shell porting.
|
||||
- Thanks to [@manhong2112](https://github.com/manhong2112) for Power Shell porting.
|
||||
- Thanks to [@BarbUk](https://github.com/BarbUk) for fzf completion in Bash.
|
||||
- Thanks to [@barlik](https://github.com/barlik) for many improvements.
|
||||
|
||||
And many others.
|
||||
|
||||
|
||||
56
z.lua
56
z.lua
@@ -4,7 +4,7 @@
|
||||
-- z.lua - a cd command that learns, by skywind 2018, 2019
|
||||
-- Licensed under MIT license.
|
||||
--
|
||||
-- Version 1.7.1, Last Modified: 2019/06/07 22:07
|
||||
-- Version 1.7.4, Last Modified: 2019/12/29 04:52
|
||||
--
|
||||
-- * 10x faster than fasd and autojump, 3x faster than z.sh
|
||||
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
||||
@@ -74,6 +74,8 @@
|
||||
-- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
|
||||
-- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
|
||||
-- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear.
|
||||
-- set $_ZL_USE_LFS to 1 to use lua-filesystem package
|
||||
-- set $_ZL_HYPHEN to 1 to stop treating hyphen as a regexp keyword
|
||||
--
|
||||
--=====================================================================
|
||||
|
||||
@@ -120,6 +122,7 @@ Z_CMD = 'z'
|
||||
Z_MATCHMODE = 0
|
||||
Z_MATCHNAME = false
|
||||
Z_SKIPPWD = false
|
||||
Z_HYPHEN = false
|
||||
|
||||
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
|
||||
|
||||
@@ -548,6 +551,9 @@ end
|
||||
-- file or path exists
|
||||
-----------------------------------------------------------------------
|
||||
function os.path.exists(name)
|
||||
if name == '/' then
|
||||
return true
|
||||
end
|
||||
local ok, err, code = os.rename(name, name)
|
||||
if not ok then
|
||||
if code == 13 then
|
||||
@@ -1263,6 +1269,9 @@ function data_select(M, patterns, matchlast)
|
||||
local pats = {}
|
||||
for i = 1, #patterns do
|
||||
local p = patterns[i]
|
||||
if Z_HYPHEN then
|
||||
p = p:gsub('-', '%%-')
|
||||
end
|
||||
table.insert(pats, case_insensitive_pattern(p))
|
||||
end
|
||||
for i = 1, #M do
|
||||
@@ -1864,6 +1873,7 @@ function z_init()
|
||||
local _zl_matchname = os.getenv('_ZL_MATCH_NAME')
|
||||
local _zl_skippwd = os.getenv('_ZL_SKIP_PWD')
|
||||
local _zl_matchmode = os.getenv('_ZL_MATCH_MODE')
|
||||
local _zl_hyphen = os.getenv('_ZL_HYPHEN')
|
||||
if _zl_data ~= nil and _zl_data ~= "" then
|
||||
if windows then
|
||||
DATA_FILE = _zl_data
|
||||
@@ -1916,6 +1926,12 @@ function z_init()
|
||||
Z_SKIPPWD = true
|
||||
end
|
||||
end
|
||||
if _zl_hyphen ~= nil then
|
||||
local m = string.lower(_zl_hyphen)
|
||||
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
|
||||
Z_HYPHEN = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2010,14 +2026,14 @@ alias ${_ZL_CMD:-z}='_zlua'
|
||||
local script_init_bash = [[
|
||||
case "$PROMPT_COMMAND" in
|
||||
*_zlua?--add*) ;;
|
||||
*) PROMPT_COMMAND="(_zlua --add \"\$(command pwd 2>/dev/null)\" &);$PROMPT_COMMAND" ;;
|
||||
*) PROMPT_COMMAND="(_zlua --add \"\$(command pwd 2>/dev/null)\" &)${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||
esac
|
||||
]]
|
||||
|
||||
local script_init_bash_fast = [[
|
||||
case "$PROMPT_COMMAND" in
|
||||
*_zlua?--add*) ;;
|
||||
*) PROMPT_COMMAND="(_zlua --add \"\$PWD\" &);$PROMPT_COMMAND" ;;
|
||||
*) PROMPT_COMMAND="(_zlua --add \"\$PWD\" &)${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||
esac
|
||||
]]
|
||||
|
||||
@@ -2029,7 +2045,7 @@ _zlua_precmd() {
|
||||
}
|
||||
case "$PROMPT_COMMAND" in
|
||||
*_zlua_precmd*) ;;
|
||||
*) PROMPT_COMMAND="_zlua_precmd;$PROMPT_COMMAND" ;;
|
||||
*) PROMPT_COMMAND="_zlua_precmd${PROMPT_COMMAND:+;$PROMPT_COMMAND}" ;;
|
||||
esac
|
||||
]]
|
||||
|
||||
@@ -2056,7 +2072,7 @@ local script_init_zsh = [[
|
||||
_zlua_precmd() {
|
||||
(_zlua --add "${PWD:a}" &)
|
||||
}
|
||||
typeset -gaU precmd_functions
|
||||
typeset -ga precmd_functions
|
||||
[ -n "${precmd_functions[(r)_zlua_precmd]}" ] || {
|
||||
precmd_functions[$(($#precmd_functions+1))]=_zlua_precmd
|
||||
}
|
||||
@@ -2066,7 +2082,7 @@ local script_init_zsh_once = [[
|
||||
_zlua_precmd() {
|
||||
(_zlua --add "${PWD:a}" &)
|
||||
}
|
||||
typeset -gaU chpwd_functions
|
||||
typeset -ga chpwd_functions
|
||||
[ -n "${chpwd_functions[(r)_zlua_precmd]}" ] || {
|
||||
chpwd_functions[$(($#chpwd_functions+1))]=_zlua_precmd
|
||||
}
|
||||
@@ -2539,7 +2555,33 @@ end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- testing case
|
||||
-- LFS optimize
|
||||
-----------------------------------------------------------------------
|
||||
os.lfs = {}
|
||||
os.lfs.enable = os.getenv('_ZL_USE_LFS')
|
||||
if os.lfs.enable ~= nil then
|
||||
local m = string.lower(os.lfs.enable)
|
||||
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
|
||||
os.lfs.status, os.lfs.pkg = pcall(require, 'lfs')
|
||||
if os.lfs.status then
|
||||
local lfs = os.lfs.pkg
|
||||
os.path.exists = function (name)
|
||||
return lfs.attributes(name) and true or false
|
||||
end
|
||||
os.path.isdir = function (name)
|
||||
local mode = lfs.attributes(name)
|
||||
if not mode then
|
||||
return false
|
||||
end
|
||||
return (mode.mode == 'directory') and true or false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- program entry
|
||||
-----------------------------------------------------------------------
|
||||
if not pcall(debug.getlocal, 4, 1) then
|
||||
-- main script
|
||||
|
||||
@@ -20,15 +20,15 @@ if [[ -z "$ZLUA_EXEC" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
export _ZL_FZF_FLAG="-e"
|
||||
export _ZL_FZF_FLAG=${_ZL_FZF_FLAG:-"-e"}
|
||||
|
||||
eval "$($ZLUA_EXEC $ZLUA_SCRIPT --init zsh once enhanced)"
|
||||
|
||||
|
||||
alias zz='z -i'
|
||||
alias zc='z -c'
|
||||
alias zf='z -I'
|
||||
alias zb='z -b'
|
||||
alias zh='z -I -t .'
|
||||
alias zzc='zz -c'
|
||||
|
||||
if [[ -z "$_ZL_NO_ALIASES" ]]; then
|
||||
alias zz='z -i'
|
||||
alias zc='z -c'
|
||||
alias zf='z -I'
|
||||
alias zb='z -b'
|
||||
alias zh='z -I -t .'
|
||||
alias zzc='zz -c'
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user