From 836efd3973a586dd35fcee9db0f5e636fbc82756 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Sun, 29 Dec 2019 04:59:08 +0800 Subject: [PATCH] 1.7.4: new $_ZL_HYPHEN option --- README.md | 2 ++ z.lua | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23460b0..85952cf 100644 --- a/README.md +++ b/README.md @@ -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,7 @@ 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. diff --git a/z.lua b/z.lua index ef154f1..106c6f9 100755 --- a/z.lua +++ b/z.lua @@ -4,7 +4,7 @@ -- z.lua - a cd command that learns, by skywind 2018, 2019 -- Licensed under MIT license. -- --- Version 1.7.3, Last Modified: 2019/09/06 17:27 +-- 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 @@ -75,6 +75,7 @@ -- 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 -- --===================================================================== @@ -121,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') @@ -1267,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 @@ -1868,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 @@ -1920,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