Xargs to cd for files with spaces on mac

56 views Asked by At

I have referred to quite a few answers on SO but haven't been able to figure out a solution for this.

What I am trying to do is to have a cd command that uses fzf to match the directory to jump into. I have been successful in implementing it with the following -

cd "$(find * -type d | fzf)"  # Works exactly as expected

However, I have been trying to see if the same behavior can be done by using xargs instead of a subshell. The challenge is the files can have spaces in them.

I have tried the following (after referring to multiple SO answers) but can't seem to figure out why this command silently fails.

find * -type d | fzf | tr \\n \\0 | xargs -t -0 cd  # Silently fails

I need help with the following -

  1. Analyzing why the command runs but does nothing (silently fails)
  2. An approach to pass the path (with spaces) to xargs cd

Any help would be appreciated!

0

There are 0 answers