Skip to content

Commit b9e8501

Browse files
author
skywind3000
committed
new: $_ZL_FZF_FLAG for additional fzf arguments
fix: environment variable parsing is flaky
1 parent 31fd92f commit b9e8501

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ As you see, z.lua is the fastest one and requires less resource.
451451

452452
## History
453453

454+
- 1.5.3 (2019-02-17): environment variable parsing is flaky, new `$_ZL_FZF_FLAG`.
454455
- 1.5.2 (2019-02-16): be aware of all arguments in fzf completion.
455456
- 1.5.1 (2019-02-15): new: simulated dir stack by `z -`, `z --` and `z -{num}`.
456457
- 1.5.0 (2019-02-14): fixed minor issues in backward jumping.

z.lua

Lines changed: 44 additions & 11 deletions
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.5.2, Last Modified: 2019/02/16 14:25
7+
-- Version 1.5.3, Last Modified: 2019/02/17 16:22
88
--
99
-- * 10x faster than fasd and autojump, 3x faster than z.sh
1010
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -757,6 +757,37 @@ function os.scriptname()
757757
end
758758

759759

760+
-----------------------------------------------------------------------
761+
-- get environ
762+
-----------------------------------------------------------------------
763+
function os.environ(name, default)
764+
local value = os.getenv(name)
765+
if value == nil then
766+
return default
767+
elseif type(default) == 'boolean' then
768+
value = value:lower()
769+
if value == '0' or value == '' or value == 'no' then
770+
return false
771+
elseif value == 'false' or value == 'n' or value == 'f' then
772+
return false
773+
else
774+
return true
775+
end
776+
elseif type(default) == 'number' then
777+
value = tonumber(value)
778+
if value == nil then
779+
return default
780+
else
781+
return value
782+
end
783+
elseif type(default) == 'string' then
784+
return value
785+
elseif type(default) == 'table' then
786+
return value:sep(',')
787+
end
788+
end
789+
790+
760791
-----------------------------------------------------------------------
761792
-- parse option
762793
-----------------------------------------------------------------------
@@ -1406,19 +1437,20 @@ function z_cd(patterns)
14061437
end
14071438
retval = M[index].name
14081439
elseif Z_INTERACTIVE == 2 then
1409-
local fzf = os.getenv('_ZL_FZF')
1440+
local fzf = os.environ('_ZL_FZF', 'fzf')
14101441
local tmpname = '/tmp/zlua.txt'
14111442
local cmd = '--nth 2.. --reverse --inline-info +s --tac'
1412-
local cmd = ((not fzf) and 'fzf' or fzf) .. ' ' .. cmd
1443+
cmd = ((fzf == '') and 'fzf' or fzf) .. ' ' .. cmd
1444+
cmd = cmd .. ' ' .. os.environ('_ZL_FZF_FLAG', '') .. ' '
14131445
if not windows then
14141446
tmpname = os.tmpname()
1415-
if not os.getenv('_ZL_FZF_FULLSCR') then
1447+
if not os.environ('_ZL_FZF_FULLSCR', false) then
14161448
cmd = cmd .. ' --height 35%'
14171449
end
14181450
cmd = cmd .. ' < "' .. tmpname .. '"'
14191451
else
14201452
tmpname = os.tmpname():gsub('\\', ''):gsub('%.', '')
1421-
tmpname = os.getenv('TMP') .. '\\zlua_' .. tmpname .. '.txt'
1453+
tmpname = os.environ('TMP', '') .. '\\zlua_' .. tmpname .. '.txt'
14221454
cmd = 'type "' .. tmpname .. '" | ' .. cmd
14231455
end
14241456
PRINT_MODE = tmpname
@@ -1710,7 +1742,7 @@ function z_init()
17101742
table.insert(Z_EXCLUDE, name)
17111743
end
17121744
end
1713-
if _zl_cmd ~= nil then
1745+
if _zl_cmd ~= nil and _zl_cmd ~= '' then
17141746
Z_CMD = _zl_cmd
17151747
end
17161748
if _zl_matchname ~= nil then
@@ -1740,7 +1772,7 @@ end
17401772
-- initialize clink hooks
17411773
-----------------------------------------------------------------------
17421774
function z_clink_init()
1743-
local once = os.getenv("_ZL_ADD_ONCE")
1775+
local once = os.environ("_ZL_ADD_ONCE", false)
17441776
local previous = ''
17451777
function z_add_to_database()
17461778
pwd = clink.get_cwd()
@@ -1940,12 +1972,12 @@ function z_shell_init(opts)
19401972
print(script)
19411973
end
19421974

1943-
local prompt_hook = (os.getenv("_ZL_NO_PROMPT_COMMAND") == nil)
1944-
local once = (os.getenv("_ZL_ADD_ONCE") ~= nil) or opts.once ~= nil
1975+
local prompt_hook = (not os.environ("_ZL_NO_PROMPT_COMMAND", false))
1976+
local once = os.environ("_ZL_ADD_ONCE", false) or opts.once ~= nil
19451977

19461978
if opts.bash ~= nil then
19471979
if prompt_hook then
1948-
if opts.once then
1980+
if once then
19491981
print(script_init_bash_once)
19501982
elseif opts.fast then
19511983
print(script_init_bash_fast)
@@ -1956,9 +1988,10 @@ function z_shell_init(opts)
19561988
print(script_complete_bash)
19571989
if opts.fzf ~= nil then
19581990
fzf_cmd = "fzf --nth 2 --reverse --inline-info +s --tac"
1959-
if not os.getenv('_ZL_FZF_FULLSCR') then
1991+
if not os.environ('_ZL_FZF_FULLSCR', false) then
19601992
fzf_cmd = fzf_cmd .. ' --height 35%'
19611993
end
1994+
fzf_cmd = fzf_cmd .. ' ' .. os.environ('_ZL_FZF_FLAG', '') .. ' '
19621995
print('zlua_fzf="' .. fzf_cmd .. '"')
19631996
print(script_fzf_complete_bash)
19641997
end

0 commit comments

Comments
 (0)