-
-
Save jwarby/11238986 to your computer and use it in GitHub Desktop.
..s - change up to a parent directory by specifying it's name
This file contains 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
#! /bin/bash | |
# Change to a directory higher in the tree by name. | |
# | |
# Usage: | |
# [someone@apc /var/www/mysite/mysubfolder] $ ..s www | |
# [someone@apc /var/www] $ | |
# | |
function ..s() { | |
CUR_PATH=`pwd` | |
query=`basename $1` | |
if [[ "$CUR_PATH" =~ /$query/ ]]; then | |
┆ # Path to cd to | |
┆ [[ "$CUR_PATH" =~ ^.*/$query ]] | |
┆ cd ${BASH_REMATCH[0]} | |
else | |
┆ echo "Directory '$1' not found in current path" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment