Skip to content

Instantly share code, notes, and snippets.

@raffylopez
Created November 14, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raffylopez/a5554fd64cf155eb921acc35d82455bb to your computer and use it in GitHub Desktop.
Save raffylopez/a5554fd64cf155eb921acc35d82455bb to your computer and use it in GitHub Desktop.
Ever typed `cd ..` * 1,000,000 times? This'll help
# +---------+
# | CD Find |
# +---------+
cdf() {
sp=$(pwd)
if [[ "$1" = "" ]]; then
echo "Usage: ..."
return
fi
while true
do
bn=$(basename $(pwd))
if [ "$bn" = "/" ]; then
echo "${RED}No match for '$1'${NC}"
cd $sp
return -1
fi
if $(echo "$bn" | grep -q "$1" ); then
echo "${GREEN}'$1'${NC} matches '$(pwd)/'"
return 0
fi
cd ..
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment