Skip to content

Instantly share code, notes, and snippets.

@jwarby
Last active August 29, 2015 14:00
Show Gist options
  • Save jwarby/11238986 to your computer and use it in GitHub Desktop.
Save jwarby/11238986 to your computer and use it in GitHub Desktop.
..s - change up to a parent directory by specifying it's name
#! /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