Skip to content

Commit

Permalink
dry option
Browse files Browse the repository at this point in the history
  • Loading branch information
bntzio committed May 6, 2017
1 parent c1123aa commit 100def6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
5 changes: 4 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,17 @@ If you're using zsh or a different shell, make sure to have `~/bin` in your `$PA
```
$ wipe-modules --help
Usage: wipe-modules [path] [days]
Usage: wipe-modules [path] [days] [options]
Path:
The full path of your code directory
Days:
The days you want to set to mark projects as inactive
Options:
-D, --dry Only show node_modules to be removed
Example: wipe-modules ~/code 30
That will remove the node_modules of your ~/code projects
Expand Down
38 changes: 32 additions & 6 deletions wipe-modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# variables
code_dir=$1
last_modified=$2
dry=$3
modules_removed=0
is_dir=0
is_number=0
Expand All @@ -12,14 +13,17 @@ run=0
usage() {
cat <<EOF
Usage: wipe-modules [path] [days]
Usage: wipe-modules [path] [days] [options]
Path:
The full path of your code directory
Days:
The days you want to set to mark projects as inactive
Options:
-D, --dry Only show node_modules to be removed
Example: wipe-modules ~/code 30
That will remove the node_modules of your ~/code projects
Expand All @@ -33,26 +37,48 @@ 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
for d in `find . -maxdepth 1 -type d -mtime +$last_modified`; do
# move to code dir subdirectory
cd $d
if [ `find . -maxdepth 1 -type d -name 'node_modules'` ]
then
# wipe the node_modules folder!
rm -rf node_modules
modules_removed=`expr $modules_removed + 1`
# 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
fi

# go one directory up to continue iterating
cd ..
done

# display nice little information message when done
if [ $modules_removed -gt 0 ]; then
echo "\033[90m $modules_removed node_modules successfully removed! \033[39m"
if [ "$dry" == "--dry" -o "$dry" == "-D" ]; then
echo ""
echo "\033[90m $modules_removed node_modules were found! \033[39m"
else
echo "\033[90m $modules_removed node_modules successfully removed! \033[39m"
fi
else
echo "\033[90m Our agent couldn't find any inactive project. \033[39m"
echo "\033[90m Our agent couldn't find any inactive projects. \033[39m"
fi
}

Expand Down

0 comments on commit 100def6

Please sign in to comment.