-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanbird.sh
More file actions
executable file
·131 lines (110 loc) · 3.57 KB
/
cleanbird.sh
File metadata and controls
executable file
·131 lines (110 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
#-----------------------------------------------------------------------------------
# _ _ _ _
# __| |___ __ _ _ _ | |__(_)_ _ __| |
# / _| / -_) _` | ' \| '_ \ | '_/ _` |
# \__|_\___\__,_|_||_|_.__/_|_| \__,_|
# recursive directory git pull
#-----------------------------------------------------------------------------------
VERSION="1.0.0"
#-----------------------------------------------------------------------------------
#
# This script will recursively traverse all directories under a specified folder
# and do git pull
#
# Usage: cleanbird.sh /path/to/folder
#
#-----------------------------------------------------------------------------------
# Author : Rick Ellis https://github.com/rickellis
# :
# Source URL : https://github.com/rickellis/Shell-Scripts/dirtybird.sh
# License : MIT
#-----------------------------------------------------------------------------------
# Path you want checked if script is called with no path argument.
# If this is left blank then the present working directory will be used.
SEARCHPATH=""
# Put directories you want ignored by this script into this array. Can be a
# name or a path. Paths are relative to the parent directory.
# Do not use a full path or a leading or trailing slash
#
# EXAMPLE: IGNORE=('Third-Party' 'Utilites/Server/Setup')
#
# NOTE: Only directories are ignored, not paths to individual files.
#
IGNORE=('Third-Party')
# Load colors.sh script to display pretty headings and colored text
# This is an optional (but recommended) dependency
BASEPATH=$(dirname "$0")
if [[ -f "${BASEPATH}/colors.sh" ]]; then
. "${BASEPATH}/colors.sh"
else
heading() {
echo "---------------------------------------------------------------------"
echo " $2"
echo "---------------------------------------------------------------------"
echo
}
fi
clear
heading green "CleanBird ${VERSION}"
# Set the search path
if [[ -z "$1" ]]; then
if [[ -z $SEARCHPATH ]]; then
SEARCHPATH=$PWD
fi
else
if [[ $1 == '-p' ]]; then
SEARCHPATH=$PWD
else
SEARCHPATH="$1"
fi
fi
if [[ ! -d "$SEARCHPATH" ]]; then
echo " The supplied path does not resolve to a valid directory"
echo
echo " Aborting..."
echo
exit 1
fi
cd "$SEARCHPATH"
# Preserve the old input field separator
OLDIFS=$IFS
# Change the input field separator from a space to a null
IFS=$'\n'
# Find all directories that have a .git directory in them
found_dirty=0
dir_count=0
for gitprojpath in `find . -type d -name .git | sort | sed "s/\/\.git//"`; do
# Are there any directories that need to be ignored?
if [ "${#IGNORE}" -gt 0 ]; then
# Remove leading dot-slash from path
localpath=${gitprojpath:2}
# Extract the first segment
pathseg1=$(echo "$localpath" | sed "s/[\/].*//")
# Do we have a match?
for dir in ${IGNORE[@]}; do
if [ "$localpath" == "$dir" ] || [ "$pathseg1" == "$dir" ]; then
continue 2
fi
done
fi
(( dir_count++))
# Save the current working directory before CDing
pushd . >/dev/null
cd $gitprojpath
# Print the directory name
if [[ $gitprojpath == '.' ]]; then
echo -e "${yellow}${PWD##*/}${reset}"
else
echo -e "${yellow}${gitprojpath:2}${reset}"
fi
# git pull >/dev/null 2>&1
git pull
echo
# Return to the starting directory
popd >/dev/null
done
echo "DIRECTORIES CHECKED: $dir_count"
echo
# Restore original state
IFS=$OLDIFS