1
0
mirror of https://github.com/skywind3000/z.lua synced 2026-03-18 21:59:49 +00:00

improve compatibility for ksh

This commit is contained in:
skywind3000
2019-02-10 15:08:23 +08:00
parent 17281a9de1
commit eef9f5a4a0
2 changed files with 14 additions and 14 deletions

View File

@@ -81,11 +81,11 @@ z -b foo # cd to the parent directory starting with foo
eval "$(lua /path/to/z.lua --init posix)"
For new posix shells like dash/ash, you can use:
For very old shells like ksh (Korn Shell), some keywords like `local` and `builtin` are unsupported, you can use:
eval "$(lua /path/to/z.lua --init posix new)"
eval "$(lua /path/to/z.lua --init posix legacy)"
To take advantage of keywords `local` and `builtin`.
To generate old posix compatible script.
- Fish Shell:
@@ -397,7 +397,7 @@ awk -F '\t' '{print $2 "|" $1 "|" 0}' $FN >> ~/.zlua
## History
- 1.4.4 (2019-02-10): supports legacy posix shells like ksh.
- 1.4.4 (2019-02-10): supports legacy posix shells like ksh, init with `z.lua --init posix legacy`.
- 1.4.3 (2019-02-08): fixed minor issues.
- 1.4.2 (2019-02-06): you can disabled path validation by `$_ZL_NO_CHECK`, and use `z --purge` to clear bad paths manually.
- 1.4.1 (2019-02-06): fzf tab-completion in bash (@[BarbUk](https://github.com/BarbUk)), fixed hang in fish shell (close [#29](https://github.com/skywind3000/z.lua/issues/29)).

20
z.lua
View File

@@ -4,7 +4,7 @@
-- z.lua - a cd command that learns, by skywind 2018, 2019
-- Licensed under MIT license.
--
-- Version 1.4.4, Last Modified: 2019/02/10 12:56
-- Version 1.4.4, Last Modified: 2019/02/10 15:07
--
-- * 10x faster than fasd and autojump, 3x faster than z.sh
-- * available for posix shells: bash, zsh, sh, ash, dash, busybox
@@ -1916,16 +1916,11 @@ function z_shell_init(opts)
print('ZLUA_SCRIPT="' .. os.scriptname() .. '"')
print('ZLUA_LUAEXE="' .. os.interpreter() .. '"')
print('')
if not opts.posix then
if not opts.legacy then
print(script_zlua)
else
if opts.new or opts.modern then
print(script_zlua)
else
local script = script_zlua:gsub('local ', '')
script = script:gsub('builtin ', '')
print(script)
end
local script = script_zlua:gsub('local ', ''):gsub('builtin ', '')
print(script)
end
local prompt_hook = (os.getenv("_ZL_NO_PROMPT_COMMAND") == nil)
@@ -1957,7 +1952,12 @@ function z_shell_init(opts)
print(script_complete_zsh)
elseif opts.posix ~= nil then
if prompt_hook then
print(once and script_init_posix_once or script_init_posix)
local script = script_init_posix
if once then script = script_init_posix_once end
if opts.legacy then
script = script:gsub('%&%)', ')')
end
print(script)
end
print('_ZL_NO_BUILTIN_CD=1')
else