babarot / enhancd

:rocket: A next-generation cd command with your interactive filter
2.58k stars 109 forks source link

cd 'single dot' returns nothing when `ENHANCD_USE_ABBREV` is enabled #216

Open BapRx opened 1 year ago

BapRx commented 1 year ago

What did you expect to happen? cd . should open the fzf with a preview of the files present under my current directory.

What actually happened? fzf opens without any path in input, not exiting automatically:

Output image

Additional context

❯ env | grep ENHANCD_
ENHANCD_DIR=/home/baptiste/.enhancd
ENHANCD_ENABLE_DOUBLE_DOT=true
ENHANCD_ENABLE_SINGLE_DOT=true
ENHANCD_ENABLE_HYPHEN=true
ENHANCD_ENABLE_HOME=true
ENHANCD_ARG_DOUBLE_DOT=..
ENHANCD_ARG_SINGLE_DOT=.
ENHANCD_ARG_HYPHEN=-
ENHANCD_ARG_HOME=!
ENHANCD_HYPHEN_NUM=10
ENHANCD_COMPLETION_KEYBIND=^I
ENHANCD_COMPLETION_BEHAVIOR=default
ENHANCD_USE_ABBREV=true
ENHANCD_ROOT=/home/baptiste/.sheldon/repos/github.com/b4b4r07/enhancd
_ENHANCD_VERSION=2.5.1
ENHANCD_COMMAND=cd
ENHANCD_FILTER=fzy:fzf:peco:sk:zf

If I run manually the commands:

❯ filter="$(__enhancd::helper::parse_filter_string "${ENHANCD_FILTER}")"
❯ echo $filter
fzf
❯ filter="__enhancd::filter::replace ${HOME} \~ | ${filter} | __enhancd::filter::replace \~ ${HOME}"
❯ echo $filter
__enhancd::filter::replace /home/baptiste \~ | fzf | __enhancd::filter::replace \~ /home/baptiste
❯ __enhancd::sources::current_dirs
Screenshots/
test/
❯ __enhancd::sources::current_dirs | eval "${filter}"
  ❯
    0/0 (0)
❯ cd .
  ❯
    0/0 (0)

If I disable ENHANCD_USE_ABBREV it works:

❯ export ENHANCD_USE_ABBREV=false
❯ cd .
  ❯
    2/2 (0)
    ▶ Screenshots/
    ▶ test/

The issue seems to be related to the __enhancd::filter::replace function

❯ __enhancd::sources::current_dirs | __enhancd::filter::replace ${HOME} \~
❯ echo $?
0

I personnaly don't need that function at all since I handle it in my FZF filter (I simplified the filter for the demo). My filter works great with the home abbrev enabled:

image