So I started with this discussion, and it basically does exactly what I want.
However, the solution to preserve directory whitespace using quotes fails when using arguments, e.g. cd -P dir
. Any ideas for preserving whitespace and allowing for option flags?
This is the function I'm currently using.
function cd {
new_directory="$*";
if [ $# -eq 0 ]; then
new_directory=${HOME};
fi;
builtin cd "${new_directory}" && ls;
}
For example, with the above, cd -P My\ Documents/
becomes cd "-P My Documents"
which obviously fails.
"$@"
. It looks like you left out the quotes. – Gilles 'SO- stop being evil' Aug 20 '13 at 23:55