@@ -127,7 +127,7 @@ Z_CMD = 'z'
127127Z_MATCHMODE = 0
128128Z_MATCHNAME = false
129129Z_SKIPPWD = false
130- Z_HYPHEN = false
130+ Z_HYPHEN = " auto "
131131
132132os .LOG_NAME = os.getenv (' _ZL_LOG_NAME' )
133133
@@ -1292,13 +1292,16 @@ end
12921292---- -------------------------------------------------------------------
12931293-- select matched pathnames
12941294---- -------------------------------------------------------------------
1295- function data_select (M , patterns , matchlast )
1295+ -- z_hyphen must be `true`, `false``, or `"auto"`.
1296+ function data_select (M , patterns , matchlast , z_hyphen )
12961297 local N = {}
12971298 local i = 1
12981299 local pats = {}
1300+ local hyphens = false
12991301 for i = 1 , # patterns do
13001302 local p = patterns [i ]
1301- if Z_HYPHEN then
1303+ hyphens = hyphens or string.match (p , " %-" )
1304+ if z_hyphen == true then
13021305 p = p :gsub (' -' , ' %%-' )
13031306 end
13041307 table.insert (pats , case_insensitive_pattern (p ))
@@ -1309,6 +1312,9 @@ function data_select(M, patterns, matchlast)
13091312 table.insert (N , item )
13101313 end
13111314 end
1315+ if (hyphens and z_hyphen == " auto" and # N == 0 ) then
1316+ N = data_select (M , patterns , matchlast , true )
1317+ end
13121318 return N
13131319end
13141320
@@ -1458,10 +1464,10 @@ function z_match(patterns, method, subdir)
14581464 method = method ~= nil and method or ' frecent'
14591465 subdir = subdir ~= nil and subdir or false
14601466 local M = data_load (DATA_FILE )
1461- M = data_select (M , patterns , false )
1467+ M = data_select (M , patterns , false , Z_HYPHEN )
14621468 M = data_filter (M )
14631469 if Z_MATCHNAME then
1464- local N = data_select (M , patterns , true )
1470+ local N = data_select (M , patterns , true , Z_HYPHEN )
14651471 N = data_filter (N )
14661472 if # N > 0 then
14671473 M = N
@@ -2067,10 +2073,13 @@ function z_init()
20672073 Z_SKIPPWD = true
20682074 end
20692075 end
2076+ assert (Z_HYPHEN == " auto" , " Z_HYPHEN initialized to an unexpected value" )
20702077 if _zl_hyphen ~= nil then
20712078 local m = string.lower (_zl_hyphen )
20722079 if (m == ' 1' or m == ' yes' or m == ' true' or m == ' t' ) then
20732080 Z_HYPHEN = true
2081+ elseif (m == ' 0' or m == ' no' or m == ' false' or m == ' f' ) then
2082+ Z_HYPHEN = false
20742083 end
20752084 end
20762085end
0 commit comments