Created
November 14, 2020 16:45
-
-
Save raffylopez/a5554fd64cf155eb921acc35d82455bb to your computer and use it in GitHub Desktop.
Ever typed `cd ..` * 1,000,000 times? This'll help
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# +---------+ | |
# | 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