I have a function, which I would hope would get me a fuzzy search on the latest directories I have been looking at and save me time, a simple 1 liner:
dirs | sed 'y/ /\n/' | fzf | xargs cd
2 hours later I can't figure out what's wrong ) :
I keep getting errors like:
/usr/bin/cd: line 4: cd: ~/Downloads/demo: No such file or directory
Even when the directory does exist, no matter what I do. What is up with cd, why doesn't this work?
Thanks for Comment: More Info I've tried a few other ways, such as writing a function:
fdr() {
local dir
dir=`dirs | sed 'y/ /\n/' | fzf`
cd $dir
}
Even though dir
has the correct value, I get the same error as seen above.
My Final Function
Thanks for the help, sub shells were doing my head in, here is my final answer, bit hackey, but what isn't these days.
fdr() {
local dir
myusernmae=`whoami`
dir=`dirs | sed 'y/ /\n/' | sed "s/~/\/Users\/$myusernmae/g" | fzf +m`
cd "$dir"
}
"$( <pipeline> )"
). – DannyNiu Mar 01 '20 at 09:51~/Downloads/demo
is expanded by the shell not by thecd
command. – DannyNiu Mar 01 '20 at 09:52.bash_profile
. – Snickers3192 Mar 01 '20 at 10:19