Advertisement
Guest User

ct - climb tree

a guest
Jan 10th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.65 KB | None | 0 0
  1. function ct {
  2.     local cd_path="$( pwd )"
  3.     local flag=""
  4.  
  5.     if [ $# -eq 0 ]; then
  6.         echo "You must supply a directory name"
  7.         return
  8.     fi
  9.  
  10.     while [ -z ${flag} ]; do
  11.         if [ $( basename "${cd_path}" ) = "${1}" ]; then
  12.             flag="yes"
  13.         else
  14.             cd_path="$( dirname "${cd_path}" )"
  15.             if [ "${cd_path}" = "/" ]; then
  16.                 flag="no"
  17.             fi
  18.         fi
  19.     done
  20.  
  21.     if [ ${flag} = "yes" ]; then
  22.         cd "${cd_path}"
  23.         if [ -n "${2}" ]; then
  24.             cd "${2}"
  25.         fi
  26.     else
  27.         echo "'${1}' not found in working directory path"
  28.     fi
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement