Skip to content

Commit 5c36d55

Browse files
author
skywind3000
committed
use lua-filesystem package if possible when $_ZL_USE_LFS is 1
1 parent bdab27d commit 5c36d55

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ As you see, z.lua is the fastest one and requires less resource.
458458

459459
## History
460460

461+
- 1.7.3 (2019-09-07): use [lua-filesystem](http://keplerproject.github.io/luafilesystem/) package if possible when `$_ZL_USE_LFS` is `1`.
461462
- 1.7.2 (2019-08-01): Improve bash/zsh shell compatibility by [@barlik](https://github.com/barlik).
462463
- 1.7.1 (2019-06-07): Fixed: `$_ZL_DATA` failure on Linux sometimes.
463464
- 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).

z.lua

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
-- z.lua - a cd command that learns, by skywind 2018, 2019
55
-- Licensed under MIT license.
66
--
7-
-- Version 1.7.2, Last Modified: 2019/08/01 19:45
7+
-- Version 1.7.3, Last Modified: 2019/09/06 17:27
88
--
99
-- * 10x faster than fasd and autojump, 3x faster than z.sh
1010
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -74,6 +74,7 @@
7474
-- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
7575
-- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
7676
-- set $_ZL_NO_CHECK to 1 to disable path validation. z --purge to clear.
77+
-- set $_ZL_USE_LFS to 1 to use lua-filesystem package
7778
--
7879
--=====================================================================
7980

@@ -2542,7 +2543,33 @@ end
25422543

25432544

25442545
-----------------------------------------------------------------------
2545-
-- testing case
2546+
-- LFS optimize
2547+
-----------------------------------------------------------------------
2548+
os.lfs = {}
2549+
os.lfs.enable = os.getenv('_ZL_USE_LFS')
2550+
if os.lfs.enable ~= nil then
2551+
local m = string.lower(os.lfs.enable)
2552+
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
2553+
os.lfs.status, os.lfs.pkg = pcall(require, 'lfs')
2554+
if os.lfs.status then
2555+
local lfs = os.lfs.pkg
2556+
os.path.exists = function (name)
2557+
return lfs.attributes(name) and true or false
2558+
end
2559+
os.path.isdir = function (name)
2560+
local mode = lfs.attributes(name)
2561+
if not mode then
2562+
return false
2563+
end
2564+
return (mode.mode == 'directory') and true or false
2565+
end
2566+
end
2567+
end
2568+
end
2569+
2570+
2571+
-----------------------------------------------------------------------
2572+
-- program entry
25462573
-----------------------------------------------------------------------
25472574
if not pcall(debug.getlocal, 4, 1) then
25482575
-- main script

0 commit comments

Comments
 (0)