|
4 | 4 | -- z.lua - a cd command that learns, by skywind 2018, 2019
|
5 | 5 | -- Licensed under MIT license.
|
6 | 6 | --
|
7 |
| --- Version 1.7.2, Last Modified: 2019/08/01 19:45 |
| 7 | +-- Version 1.7.3, Last Modified: 2019/09/06 17:27 |
8 | 8 | --
|
9 | 9 | -- * 10x faster than fasd and autojump, 3x faster than z.sh
|
10 | 10 | -- * available for posix shells: bash, zsh, sh, ash, dash, busybox
|
|
74 | 74 | -- set $_ZL_MAXAGE to define a aging threshold (default is 5000).
|
75 | 75 | -- set $_ZL_MATCH_MODE to 1 to enable enhanced matching mode.
|
76 | 76 | -- 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 |
77 | 78 | --
|
78 | 79 | --=====================================================================
|
79 | 80 |
|
@@ -2542,7 +2543,33 @@ end
|
2542 | 2543 |
|
2543 | 2544 |
|
2544 | 2545 | -----------------------------------------------------------------------
|
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 |
2546 | 2573 | -----------------------------------------------------------------------
|
2547 | 2574 | if not pcall(debug.getlocal, 4, 1) then
|
2548 | 2575 | -- main script
|
|
0 commit comments