Skip to content
Myr

[shell][zsh] Don't resolve symlinks in ALT-c (#4816) (#4817)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This way ALT-c behaves more aligned with `cd`. Imagine a setup like: ``` /foo -> foo_real /foo_real/bar ``` Right now if we first `cd foo` (a symlink to `foo_real`), and then use ALT-c to goto `bar`, then we would end up executing `cd /foo_real/bar` instead of `cd /foo/bar`. `$PWD = /foo_real/bar`. For comparison, if we first `cd foo` and then `cd bar`, we end up with `$PWD = /foo/bar`. This commit changes the internal logic of `fzf-cd-widget` to first run `cd <result of FZF_ALT_C_COMMAND>` in a subshell to simulate the behavior of `cd`, and then insert the target PWD into the shell history. This way we get behavior consistent with the builtin `cd` command, while also recording reusable shell history. Co-authored-by: Yi-Yo Chiang <5255547+silverneko@users.noreply.github.com> Close #4816

authored by Junegunn Choi · committed by GitHub · parent a506193 · Browse files · 1 file+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−1 removed

  • other:+7 added−1 removed

1 file+7 added−1 removed

modified:shell/key-bindings.zsh+7 added-1 removed
108 unmodified lines
109 if [[ -z "$dir" ]]; then110 zle redisplay111 return 0112 fi113 # Use subshell expansion to get the absolute PWD of the target dir.114 # This allows the recorded shell history to be reused even from a different115 # working directory.116 # If failed, fallback to the unexpanded path to surface the error to the user.117 # NOTE: Don't use the `:a` modifier as it resolves symlinks like `pwd -P`.118 dir=$(builtin cd >/dev/null -- "${dir}" && echo "${PWD}" || echo "${dir}")119 zle push-line # Clear buffer. Auto-restored on next prompt.114 BUFFER="builtin cd -- ${(q)dir:a}"120 BUFFER="builtin cd -- ${(q)dir}"121 zle accept-line122 local ret=$?123 unset dir # ensure this doesn't end up appearing in prompt expansion124 zle reset-prompt
79 unmodified lines