Skip to content

Commit 834c258

Browse files
authored
adjust to ambiguous os.tmpname() behaviour on Windows and fix integration with fzf
os.tmpname() results on Windows can be different depending on compiler used to compile Lua library i.e one of the following: 1) \sXXX. or \sXX. where X is random alphanumeric character. Old code is assuming this result. 2) <full\path\to\user\tempfolder>\sXXX.0 where X is as above. In this case old code produces incompatible with system path to temporary file (with colon in it's name) so file is created with different truncated filename and nothing is ever written to it. That way nothing is ever passed to fzf. Code changed to be compatible with both cases.
1 parent 4bbd0f1 commit 834c258

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

z.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,16 +1668,18 @@ function z_cd(patterns)
16681668
local flag = os.environ('_ZL_FZF_FLAG', '')
16691669
flag = (flag == '' or flag == nil) and '+s -e' or flag
16701670
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd .. ' ' .. flag
1671+
tmpname = os.tmpname()
16711672
if not windows then
1672-
tmpname = os.tmpname()
16731673
local height = os.environ('_ZL_FZF_HEIGHT', '35%')
16741674
if height ~= nil and height ~= '' and height ~= '0' then
16751675
cmd = cmd .. ' --height ' .. height
16761676
end
16771677
cmd = cmd .. ' < "' .. tmpname .. '"'
16781678
else
1679-
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
1680-
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
1679+
if string.match(tmpname, "^\\s%w+%.$") then
1680+
tmpname = tmpname:gsub('\\', ''):gsub('%.', '')
1681+
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
1682+
end
16811683
cmd = 'type "' .. tmpname .. '" | ' .. cmd
16821684
end
16831685
PRINT_MODE = tmpname
@@ -1870,10 +1872,9 @@ function cd_breadcrumbs(pwd, interactive)
18701872
local tmpname = '/tmp/zlua.txt'
18711873
local fp = io.stderr
18721874
if interactive == 2 then
1873-
if not windows then
1874-
tmpname = os.tmpname()
1875-
else
1876-
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
1875+
tmpname = os.tmpname()
1876+
if windows and string.match(tmpname, "^\\s%w+%.$") then
1877+
tmpname = tmpname():gsub('\\', ''):gsub('%.', '')
18771878
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
18781879
end
18791880
fp = io.open(tmpname, 'w')

0 commit comments

Comments
 (0)