The current version attempts to run "redraw-current-line" and
"__zoxide_z_complete_helper" by 1) first replacing the keybinding to
\[0n to "redraw-current-line", 2) printing \e[5n, 3) replacing the
keybinding to \e[0n with "__zoxide_z_complete_helper", and 4) finally
printing \e[5n.
However, this does not work as expected. This ends up running
"__zoxide_z_complete_helper" twice. This is because Bash/Readline
processes the next inputs after the current completion finishes.
Since the above steps 1-4 are performed inside the completion
function, Bash/Readline starts processing the response \e[0n (even if
it is immediately returned with zero time) only after the keybinding
to \e[0n is replaced with "__zoxide_z_complete_helper".
In the first place, Bash/Readline automatically redraws the command
line after processing the keybinding with "bind -x", so one does not
need to explicitly call "redraw-current-line".
This patch simply removes steps 1-2, which did not perform what was
expected.
Only ksh93 supports DEBUG traps, and the rest don't have any features
that can be used for setting up hooks. May as well use the POSIX
implementation for all ksh shells.
* support autocd option
In bash, when autocd option is set and user enters a directory name as a
command, it results in a very specific call to cd:
cd -- [directory name]
zoxide's directory changing function passes all arguments to __zoxide_z as is,
including the "--" first argument. By detecting this and skipping the first
argument changing directory works with autocd set.
* remove directory check
just skip the first argument and pass the rest as is. checking for directory
breaks cd'ing to symlinked directories
* undo some of the hackery
tests are failing
elvish uses lexical scoping for closure capture, as such all `oldpwd`
references within the script refers to the `oldpwd` defined at the top.
However, before-chdir hook is trying to assign to `oldpwd` within the
editor scope, which is not used by this script.
This manifested as a bug in which:
```
~
> mkdir -p /tmp/another
~
> z /tmp
/tmp
> z another
/tmp/another
> z -
~
> # The previous dir should be /tmp not ~!
```
Because the hook was updating a variable that was not used.
Fix the hook so that before-chdir assign to the proper upvalue.