Hi i was trying to make a script with fzf to cd into a dir by searching name of a file in that directory
fcd(){
cd $(find | fzf )
}
but it will throw error when filename contains space, as it will split it into 2.
EDIT: Thanks
cd "$(...)", not cd $(...); the >quotes are mandatory. – Charles Duffy
so Can anyone help with such a script to cd into directories with file names using fzf?
Actual question before edit V
after so much searching and modifying, i ended up with this
cd $(fzf| awk '{print "\047"$0"\047"}'|xargs dirname | awk '{print "\047"$0"\047"}')
take file tree
a
└── b
└── c d
├── e.txt
└── f g.txt
if we change cd with echo in above script and search for 'f g.txt', it will correctly print out 'a/b/c d' and if we type cd 'a/b/c d', it is going to that dir. but when combine both and run like above script, is giving
bash: cd: too many arguments
whereever i search, i get solution as cd $(find . -d |fzf)
which is not i needed, i wanted to search a filename and go to it's parent directory.
Thanks in advanced :)