An open API service indexing awesome lists of open source software.

https://github.com/mearns/fs-cleaner

Some scripts for helping you find things on your disk to clean up.
https://github.com/mearns/fs-cleaner

Last synced: about 1 month ago
JSON representation

Some scripts for helping you find things on your disk to clean up.

Awesome Lists containing this project

README

        

# fs-cleaner

Some scripts for helping you find things on your filesystem that you can cleanup.

Copyright 2019 Brian Mearns - Licensed under the MIT license (see the LICENSE file).

> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.

## Example Usage:

```console
> # Run the prepare script to generate the cleanup document.
> ./prepare-sandbox-clean.sh /path/to/sandbox/directory > cleanup.cfg
>
> # Review and edit the generated cleanup document to determine what to do
> # with each filesystem item.
> vim cleanup.cfg
>
> # Permanently delete the directories (recursively) that you've designated
> # to be "clean"-ed in the document.
> ./execute-cleanup.sh < cleanup.cfg
```

## Overview

The script(s) starting with `prepare-` will scan your filesystem as directed to
try to come up with items to be removed, and summarize its findings in a specially
formatted output document (written to STDOUT).

You should review and potentially edit the generated document to decide what to do
with each of the identified items (or even add additional items).

Once you're confident in the state of the cleanup document, stream it into the
`execute-cleanup.sh` script to actually remove the designated items from the filesystem.

## Example Cleanup Document

The following document was generated by `prepare-sandbox-clean.sh`, targeting the `/Users/bmearns/sandbox`
directory. It has identified 4 items that it recommends you clean from your filesystem.

Left as is, `execute-cleanup.sh` will not actually do anything to these items, because the
action specified for each item is "recommend-clean". If you actually want to delete them, you
would change the action to "recommend-clean".

```config
### The following entries were generated on (Wed Feb 27 16:35:18 EST 2019), by ./prepare-sandbox-clean.sh v1 (with args "-d 3 -a 90 -q /Users/bmearns/sandbox")

# "writings-and-presentations": a clean git repo, 8.6M, last modified Dec 9 14:48:56 2016
recommend-clean /Users/bmearns/sandbox/writings-and-presentations

# "service-checker": a clean git repo, 140M, last modified Apr 5 10:44:17 2017
recommend-clean /Users/bmearns/sandbox/service-checker

# "cork-log": a clean git repo, 85M, last modified Oct 3 21:26:28 2018
recommend-clean /Users/bmearns/sandbox/cork-log

# "xrange": a clean git repo, 4.6M, last modified Sep 28 15:36:41 2018
recommend-clean /Users/bmearns/sandbox/xrange
```

## Suggested Commands

By default (without any`-q` flag), the `prepare-*` scripts may provide specially formatted
comments in the generated cleanup document which it suggests as a way of inspecting an item
to decide what to do with it. These are typically the same commands (or similar) it runs to
determine it's recommendation.

These "suggested command" comments each begin with "#> ", followed by a unique command-id, some
whitespace, and then a shell command. You can ignore the command-id and simply copy the shell
command into your terminal to run it.

Alternatively, you can use the `execute-cleanup.sh` script with the `-x` option and specify
one or more of these command-ids as arguments: the execute-cleanup script will scan the provided
cleanup document and execute any suggested commands it finds with any of the given IDs. By
default (without any `-q` flags), it will output a comment line (beginning with "#")
before executing each suggested command, showing what it is executing, then execute the command
in a subshell, and then echo another comment line with the exit code of the command.

Note that the exit code of `execute-cleanup.sh` is will be 0 regardless of whether or not the
executed suggested commands suceed, and regardless of whether or not the specified command-ids
are found in the cleanup document (both of these behaviors are subject to change in future
versions).

## Creating your own Cleanup Document

You can easily create your own cleanup document for `execute-cleanup.sh` to execute. The format is
simple: lines beginning with '#' are "ignored", as are empty lines and lines containing only
whitespace.

Other lines take the form ` `, where `` is one of the defined actions to
take on a target, and `` is the target (i.e., a filesystem path).

For _suggested commands_, the line should begin with "#> " (note the trailing space character),
followed by the command id, at least one linear whitespace character, and then the shell command
that is being suggested. The **command id** _should_ be composed of only alphanumeric characters
or underscores, but _may_ be any non-whitespace character. The command ids do not _need_ to be
unique within a document, but any commands that share the same id will be executed when that
command id is specified to be run.

## Available Prepare Scripts

### prepare-sandbox-clean.sh

This prepare script scans specified directories looking for git repositories that can likely
be cleaned (removed). Criteria for recommending cleaning are:

* The directory has not be modified in the ast 90 days (cofigurable through the `-a` (age) option).
* The repository has no uncommitted changes.
* The repository has nothing stashed.
* The repository has no untracked files (untracked files does not include anything ignored by the repo).
* The repository has no unpushed commits on any branches.

Note that for the last point, a branch that has no associated remote branch, or a repo that has no
remotes specified, are considered to have unpushed commits (assuming they have any commits at all).

## License

Copyright 2019 Brian Mearns - Licensed under the MIT license (see the LICENSE file, or below,
for details).

>
> MIT License
>
> Copyright (c) 2019 Brian Mearns
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>