-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use builtin cd
in fzf Alt+C Key Bindings for Fish Shell
#3826
Comments
#3830 should fix the issue. It's in the devel branch, and will be included in the next release. |
I can't reproduce the bug. I installed the latest version of zoxide, and tried: fzf --fish | sed 's/builtin //' > $__fish_config_dir/conf.d/fzf.fish Reloaded fish shell, and then: zoxide init fish | source And both As far as I can tell, zoxide actually doesn't override the default Seems to me that |
Perhaps a good enough fix would be to document that fzf Alt-C in fish is only guaranteed to work if you do not And in general, I would recommend |
zoxide init --cmd cd fish | source The author of the issue has this setup12 command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init --cmd cd $(__common_rc_get_shell))" # fish
paria@Paria ~> type -a cd
cd is a function with definition
# Defined via `source`
function cd --wraps=__zoxide_z --description 'alias cd=__zoxide_z'
__zoxide_z $argv
end
cd is a builtin
cd is /usr/bin/cd Footnotes |
Ah, thanks! That explains it. Using # =============================================================================
#
# Commands for zoxide. Disable these using --no-cmd.
#
abbr --erase cd &>/dev/null
alias cd=__zoxide_z
abbr --erase cdi &>/dev/null
alias cdi=__zoxide_zi This setup does actually (mostly) work; it preserves fish shell's Directory History and The underlying problem between zoxide and fzf is caused by zoxide actually being incompatible with the default Normally in fish you should be able to run |
An alternative strategy, if zoxide is not able to fix their bug for whatever reason, could be to improve the solution from #2659. Depending on "--" isn't optimal. The best solution is to prepend filenames with "./" when necessary:
|
Would you argue for this change, or should there be a --- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -105,5 +105,5 @@ function fzf_key_bindings
if [ -n "$result" ]
- builtin cd -- $result
+ cd ./$result
# Remove last token from commandline. Applied the patch from above, and it works (only tested on macOS). # Create a dummy folder for testing with a leading '-' (dash)
mkdir -- "-zsh"
# Start minimal Fish environment
command env -i HOME=$HOME TERM=$TERM USER=$USER PATH=$HOME/Developer/fzf/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin /usr/local/bin/fish
fzf --version
# 0.54.0 (9e92b6f1)
fzf --fish | source
zoxide init --cmd cd fish | source
# Press 'alt-c' and select '-zsh'
# 'cdh' and 'cd -' work as expected Current workaround: fzf --fish | sed 's|builtin cd -- |cd ./|' | source |
This won't work if a custom |
Checking for a leading dash: --- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -105,5 +105,9 @@ function fzf_key_bindings
if [ -n "$result" ]
- builtin cd -- $result
+ if string match --quiet -- '-*' "$result"
+ cd ./$result
+ else
+ cd $result
+ end
# Remove last token from commandline. |
That looks good to me! I think this is the best solution. It's as safe as the "--" strategy, while avoiding the bug in zoxide. |
Checklist
man fzf
)Output of
fzf --version
0.52.0 (bcda25a)
OS
Shell
Problem / Steps to reproduce
I'm encountering an issue with the
Alt+C
key binding in the Fish shell when using zoxide, which overrides the cd command. When I activate the Alt+C shortcut, it is not calling the builtin cd because of the alias setup by zoxide, leading to a failure in switching directories.I think changing this line to
builtin cd -- $result
is sufficient to solve this problem.This modification is aligned with the implementation in the Bash script, where builtin cd is explicitly used to avoid similar conflicts.
The text was updated successfully, but these errors were encountered: