Skip to content

Commit 836efd3

Browse files
author
skywind3000
committed
1.7.4: new $_ZL_HYPHEN option
1 parent 5c36d55 commit 836efd3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ z -b foo # cd to the parent directory starting with foo
131131
- set `$_ZL_ECHO` to 1 to display new directory name after cd.
132132
- set `$_ZL_MATCH_MODE` to 1 to enable enhanced matching.
133133
- set `$_ZL_NO_CHECK` to 1 to disable path validation, use `z --purge` to clean
134+
- set `$_ZL_HYPHEN` to 1 to treat hyphon (-) as a normal character not a lua regexp keyword.
134135

135136
## Aging
136137

@@ -458,6 +459,7 @@ As you see, z.lua is the fastest one and requires less resource.
458459

459460
## History
460461

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

z.lua

Lines changed: 13 additions & 1 deletion
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.3, Last Modified: 2019/09/06 17:27
7+
-- Version 1.7.4, Last Modified: 2019/12/29 04:52
88
--
99
-- * 10x faster than fasd and autojump, 3x faster than z.sh
1010
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -75,6 +75,7 @@
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.
7777
-- set $_ZL_USE_LFS to 1 to use lua-filesystem package
78+
-- set $_ZL_HYPHEN to 1 to stop treating hyphen as a regexp keyword
7879
--
7980
--=====================================================================
8081

@@ -121,6 +122,7 @@ Z_CMD = 'z'
121122
Z_MATCHMODE = 0
122123
Z_MATCHNAME = false
123124
Z_SKIPPWD = false
125+
Z_HYPHEN = false
124126

125127
os.LOG_NAME = os.getenv('_ZL_LOG_NAME')
126128

@@ -1267,6 +1269,9 @@ function data_select(M, patterns, matchlast)
12671269
local pats = {}
12681270
for i = 1, #patterns do
12691271
local p = patterns[i]
1272+
if Z_HYPHEN then
1273+
p = p:gsub('-', '%%-')
1274+
end
12701275
table.insert(pats, case_insensitive_pattern(p))
12711276
end
12721277
for i = 1, #M do
@@ -1868,6 +1873,7 @@ function z_init()
18681873
local _zl_matchname = os.getenv('_ZL_MATCH_NAME')
18691874
local _zl_skippwd = os.getenv('_ZL_SKIP_PWD')
18701875
local _zl_matchmode = os.getenv('_ZL_MATCH_MODE')
1876+
local _zl_hyphen = os.getenv('_ZL_HYPHEN')
18711877
if _zl_data ~= nil and _zl_data ~= "" then
18721878
if windows then
18731879
DATA_FILE = _zl_data
@@ -1920,6 +1926,12 @@ function z_init()
19201926
Z_SKIPPWD = true
19211927
end
19221928
end
1929+
if _zl_hyphen ~= nil then
1930+
local m = string.lower(_zl_hyphen)
1931+
if (m == '1' or m == 'yes' or m == 'true' or m == 't') then
1932+
Z_HYPHEN = true
1933+
end
1934+
end
19231935
end
19241936

19251937

0 commit comments

Comments
 (0)