enhancd
enhancd copied to clipboard
Fish cd to non-existent directory changes current working directory to $HOME
What did you expect to happen?
I expected enhancd to return no entry and stay in the current directory, or maybe open the interactive picker (like when cd is called with no arguments)
What actually happened?
enhancd returns no entry and cds to $HOME
Output
~ ❯❯❯ cd Documents
~/Documents ❯❯❯ cd foobar
no entry
~ ❯❯❯
Additional context
This bug is caused by _enhancd_source_argument failing to find any matches for the non-existent directory, leaving args empty. As a result, _enhancd_cd_builtin is called with no directory passed in, changing the directory to $HOME
_enhancd_source_argument does not return an error code if it could not find the directory, so the script does not propagate that error and instead cds without a target directory.
https://github.com/b4b4r07/enhancd/blob/aec0e0c1c0b1376e87da74b8940fda5657269948/functions/enhancd.fish#L70-L76
I think it's the same problem if in fuzzy search i hit ctrl+c or escape. Enhancd changes to $HOME instead of staying in current directory.
I patched this locally and seems to work fine
function _enhancd_cd_builtin
set -l code 0
# in case nothing was passed in argv, default to working directory
if test -z "$argv"
set argv (pwd)
end
_enhancd_cd_before
builtin cd $argv
set code $status
_enhancd_cd_after
return $code
end
Merged
Thank you