indirs.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #! /bin/bash
  2. source $HOME/lib/bash/bashutils.sh # error,warning,...
  3. indirs ()
  4. # return "true" if there is a directory in the stack that contains "$1"
  5. (
  6. CONTAINS="${1:-NONE}"
  7. if [ "$CONTAINS" == "NONE" ]; then
  8. warn "no directory name given for indirs"
  9. return $FALSE
  10. fi
  11. for d in `dirs`;
  12. do
  13. if [[ "$d" == *"${CONTAINS}"* ]]; then
  14. return $TRUE
  15. fi
  16. done
  17. info ${CONTAINS} not found in dirs
  18. return $FALSE
  19. )
  20. p2 ()
  21. # pop to (p2) a directory in the directory stack that contains P2THIS
  22. {
  23. P2THIS="${1:-NONE}"
  24. if [ "$P2THIS" == "NONE" ]; then
  25. warn "no directory name given for p2"
  26. return $FALSE
  27. fi
  28. if indirs $P2THIS; then
  29. # pop until $PWD ends with $P2THIS
  30. while true;
  31. do
  32. if [[ "$PWD" == *"${P2THIS}"* ]]; then
  33. dirs
  34. return $TRUE
  35. else
  36. popd 1> /dev/null || return $FALSE
  37. fi
  38. done
  39. else
  40. echo $INDIRS not found in `dirs`
  41. fi
  42. }