Skip to content

Instantly share code, notes, and snippets.

@obsergiu
Created April 1, 2019 15:31
Show Gist options
  • Save obsergiu/eef848b7fa27f9877b7020c056a039c9 to your computer and use it in GitHub Desktop.
Save obsergiu/eef848b7fa27f9877b7020c056a039c9 to your computer and use it in GitHub Desktop.

Revisions

  1. obsergiu created this gist Apr 1, 2019.
    33 changes: 33 additions & 0 deletions clean_list.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/usr/bin/env bash

    # Old approach - working but
    # the bash approach offers
    # greater mobility
    #GLOBIGNORE=$(paste -s -d : ./config/ignore.list)
    #rm -Rf -- {*,.*}


    # new line is mandatory as allows
    # to skip substrings
    newline='
    '

    # load the project default files
    ignore_list="$newline$(cat ./config/ignore.list)$newline"

    # the ignore.list file would have the files one on a line, eg:
    # file1.ext
    # dir1
    # file2.ext
    # ...

    # echoes the files/directory on first level
    # without going recursively
    # and removes them
    for x in * .[!.]* ..?*; do
    case "$x" in *"$newline"*) continue;; esac # sanity check: if the file name contains a newline, leave it alone
    case "$ignore_list" in
    *"$newline$x$newline"*) echo "Skipping $x";;
    *) echo "Delete: $x" && rm -rf -- "$x";
    esac
    done