Skip to content

Commit

Permalink
1.7.4: new $_ZL_HYPHEN option
Browse files Browse the repository at this point in the history
  • Loading branch information
skywind3000 committed Dec 28, 2019
1 parent 5c36d55 commit 836efd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion z.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
--
--=====================================================================

Expand Down Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 836efd3

Please sign in to comment.