Skip to content

Commit

Permalink
spaces in folder names support
Browse files Browse the repository at this point in the history
- fix subshell issue: not updating modules_removed global variable
  • Loading branch information
bntzio committed May 8, 2017
1 parent 1854c9d commit df9b1e5
Showing 1 changed file with 47 additions and 37 deletions.
84 changes: 47 additions & 37 deletions wipe-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,32 @@ usage() {
EOF
}

# instructs agent gir to start ripping off those pesky node_modules
go_gir() {
# move to code directory
cd $code_dir

# if $dry is --dry (or -D) then show message
if [ "$dry" == "--dry" -o "$dry" == "-D" ]; then
echo "\033[90m The node_modules in the following directories can be wiped out. \033[39m"
sleep 2
echo ""
fi

# find the code directories whose last modify time (mtime) is older than $last_modified days
# and loop through each resulting dir
find . -maxdepth 1 -type d -mtime +$last_modified | while read d; do
if [ "$d" == "." ]; then
continue
fi
# move to code dir subdirectory
cd "$d"
if [ `find . -maxdepth 1 -type d -name 'node_modules'` ]
# wipe node_modules
wipe() {
dir="$1" # now dir is the 1st parameter ($1)
dir="${dir%/}" # strip trailing slash
dir="${dir##*/}" # strip path and leading slash
cd "$dir"
if [ $(find . -maxdepth 1 -type d -name 'node_modules') ]; then
# if $dry is not --dry (or -D) then just print the name of the folder that
# matches the search
if [ "$dry" == "--dry" -o "$dry" == "-D" ]
then
# if $dry is not --dry (or -D) then just print the name of the folder that
# matches the search
if [ "$dry" == "--dry" -o "$dry" == "-D" ]
then
# print the current directory name
echo "$d"
modules_removed=`expr $modules_removed + 1`
else
# wipe the node_modules folder!
rm -rf node_modules
modules_removed=`expr $modules_removed + 1`
fi
# print the current directory name
echo "\033[90m $dir \033[39m"
else
# wipe the node_modules folder!
rm -rf node_modules
fi

# go one directory up to continue iterating
cd ..
done
# counter for modules to be removed
modules_removed=$(expr $modules_removed + 1)
fi
cd ..
}

# display nice little information message when done
# exit message
display_message() {
if [ $modules_removed -gt 0 ]; then
if [ "$dry" == "--dry" -o "$dry" == "-D" ]; then
echo ""
Expand All @@ -85,6 +70,31 @@ go_gir() {
fi
}

# instructs agent gir to start ripping off those pesky node_modules
go_gir() {
# move to code directory
cd $code_dir

# if $dry is --dry (or -D) then show message
if [ "$dry" == "--dry" -o "$dry" == "-D" ]; then
echo "\033[90m The node_modules in the following directories can be wiped out: \033[39m"
sleep 2
echo ""
fi

# find $code_dir directories whose last modify time (mtime) is older than
# $last_modified days, loop through each resulting dir and execute wipe function
# then display message
find . -maxdepth 1 -type d -mtime +$last_modified |
{
while read d; do
wipe "$d"
done

display_message
}
}

# if $1 parameter is --help or -h then show usage info
if [ "$1" == "--help" -o "$1" == "-h" ]
then
Expand Down

0 comments on commit df9b1e5

Please sign in to comment.