change_name.sh 636 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. if [ "$#" -lt 2 ]
  3. then
  4. USAGE="Usage:
  5. scripts/name_change.sh old_name new_name";
  6. echo "$USAGE"
  7. exit 1
  8. fi
  9. old="$1"
  10. new="$2"
  11. old_cpp=`find . -name "$old.cpp"`
  12. if [ -z "$old_cpp" ]
  13. then
  14. echo "Error: $old.cpp does not exist."
  15. exit 1
  16. fi
  17. old_h=`find . -name "$old.h"`
  18. if [ -z "$old_h" ]
  19. then
  20. echo "Error: $old.h does not exist."
  21. exit 1
  22. fi
  23. grep -rI "$old" *
  24. read -r -p "Are you sure? [y/N] " response
  25. if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]
  26. then
  27. exit 1
  28. fi
  29. if git status | grep -v --quiet "nothing to commit, working directory clean"
  30. then
  31. echo "Error: git is not committed or not clean"
  32. exit 1
  33. fi