Skip to content

Instantly share code, notes, and snippets.

@poweld
Created April 23, 2015 15:16
Show Gist options
  • Save poweld/d581538084c6372fac5f to your computer and use it in GitHub Desktop.
Save poweld/d581538084c6372fac5f to your computer and use it in GitHub Desktop.
Go to a directory within the current path
function cd..() {
if [ -z $1 ]; then
cd ..
else
grep "\/" <<<$1 &>/dev/null
if [ $? -eq 0 ]; then
echo "Invalid filename"
return
fi
grep $1 <<<`pwd` &>/dev/null
if [ $? -eq 0 ]; then
pushd . &>/dev/null
while [ $(basename `pwd`) != $1 ]; do
cd .. &>/dev/null
done
popd &>/dev/null
cd - &>/dev/null
else
echo "Could not find $1 in path to current working directory"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment