Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. shopt -s nullglob
  4.  
  5. function help {
  6. echo "${1}Runs a command on all git directories below the current directory or a specified directory.
  7. Skips directories that contain a file called .ignore.
  8.  
  9. Usage: $(basename $0) [options] command [directory]
  10.  
  11. Where:
  12. command is any command to run in each repository directory, such as 'commit'.
  13. Options are:
  14. -d - Debug mode on
  15. -n - Do not supply the git repository directory name to the command
  16. -m - Specify argument to pass to command, after -m
  17. -h - Show this help text
  18. -q - Just show processed directory names
  19. -Q - Don't show any information messages
  20.  
  21. Examples:
  22. $(basename $0) 'ls -1' # Show directory contents of the top directory of each git repository
  23. $(basename $0) -q 'ls -1' # As above, with less noise
  24. $(basename $0) -Q 'ls -1' # As above, with even less noise (just shows contents of all directories run together)
  25. $(basename $0) -m 'Initial Commit' commit
  26. $(basename $0) -m 'Initial Commit' commit \$work
  27. "
  28. exit 1
  29. }
  30.  
  31. function forALL {
  32. if [ ! "$QUIET" ]; then echo -e "\n${HIGHLIGHT}Scanning $( pwd )$NORMAL"; fi
  33. for d in */; do
  34. #echo "Directory \"$d\" found"
  35. pushd "$d" > /dev/null
  36. #echo "Working in $( pwd )"
  37. if [ -e ".ignore" ]; then
  38. if [ ! "$QUIET" ]; then echo -e "\n${HIGHLIGHT}Ignoring `pwd`${NORMAL}"; fi
  39. else
  40. if [ -d .git ]; then
  41. if [ ! "$QUIET" == really ]; then echo -e "\n${HIGHLIGHT}Processing `pwd`$NORMAL"; fi
  42. #echo "COMMAND=$COMMAND"
  43. if [ "$PROVIDE_DIRECTORY" ]; then
  44. eval "$COMMAND" `pwd`
  45. else
  46. eval "$COMMAND"
  47. fi
  48. else
  49. forALL .
  50. fi
  51. fi
  52. popd > /dev/null
  53. done
  54. }
  55.  
  56.  
  57. export HIGHLIGHT="\e[01;34m"
  58. export NORMAL='\e[00m'
  59. export REPO=origin
  60. export MSG="-"
  61. export PROVIDE_DIRECTORY=true
  62. unset QUIET
  63. while getopts "dhm:n\?qQ" opt; do
  64. case $opt in
  65. d) set -xv ;;
  66. m) export MSG="$OPTARG" ;;
  67. n) unset PROVIDE_DIRECTORY ;;
  68. q) export QUIET=true ;;
  69. Q) export QUIET=really ;;
  70. *) help ;;
  71. esac
  72. done
  73. shift $(($OPTIND-1))
  74.  
  75. if [ -z "$1" ];then help "Error: No command given to execute.\n\n"; fi
  76. export COMMAND="$1"
  77. shift
  78.  
  79. if [ "$1" ]; then
  80. cd "$1" > /dev/null
  81. shift
  82. fi
  83.  
  84. forALL .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement