From eef9f5a4a0f1bc3b14f2774b38a33cdabb65e490 Mon Sep 17 00:00:00 2001 From: skywind3000 Date: Sun, 10 Feb 2019 15:08:23 +0800 Subject: [PATCH] improve compatibility for ksh --- README.md | 8 ++++---- z.lua | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 1eefe6b..7d68c23 100644 --- a/README.md +++ b/README.md @@ -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)). diff --git a/z.lua b/z.lua index e273802..35a8298 100755 --- a/z.lua +++ b/z.lua @@ -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