Advertisement
LittleJok3r

Function CD

May 27th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.30 KB | None | 0 0
  1. #function cd from https://www.cygwin.com/
  2.     cd_func ()
  3. # {
  4. #   local x2 the_new_dir adir index
  5. #   local -i cnt
  6. #
  7. #   if [[ $1 ==  "--" ]]; then
  8. #     dirs -v
  9. #     return 0
  10. #   fi
  11. #
  12. #   the_new_dir=$1
  13. #   [[ -z $1 ]] && the_new_dir=$HOME
  14. #
  15. #   if [[ ${the_new_dir:0:1} == '-' ]]; then
  16. #     #
  17. #     # Extract dir N from dirs
  18. #     index=${the_new_dir:1}
  19. #     [[ -z $index ]] && index=1
  20. #     adir=$(dirs +$index)
  21. #     [[ -z $adir ]] && return 1
  22. #     the_new_dir=$adir
  23. #   fi
  24. #
  25. #   #
  26. #   # '~' has to be substituted by ${HOME}
  27. #   [[ ${the_new_dir:0:1} == '~' ]] && the_new_dir="${HOME}${the_new_dir:1}"
  28. #
  29. #   #
  30. #   # Now change to the new dir and add to the top of the stack
  31. #   pushd "${the_new_dir}" > /dev/null
  32. #   [[ $? -ne 0 ]] && return 1
  33. #   the_new_dir=$(pwd)
  34. #
  35. #   #
  36. #   # Trim down everything beyond 11th entry
  37. #   popd -n +11 2>/dev/null 1>/dev/null
  38. #
  39. #   #
  40. #   # Remove any other occurence of this dir, skipping the top of the stack
  41. #   for ((cnt=1; cnt <= 10; cnt++)); do
  42. #     x2=$(dirs +${cnt} 2>/dev/null)
  43. #     [[ $? -ne 0 ]] && return 0
  44. #     [[ ${x2:0:1} == '~' ]] && x2="${HOME}${x2:1}"
  45. #     if [[ "${x2}" == "${the_new_dir}" ]]; then
  46. #       popd -n +$cnt 2>/dev/null 1>/dev/null
  47. #       cnt=cnt-1
  48. #     fi
  49. #   done
  50. #
  51. #   return 0
  52. # }
  53. #
  54. # alias cd=cd_func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement