drop it - bakkeby/dusk GitHub Wiki

This is about an old gem from the past that has stood the test of time as a cleanup utility.

The idea started with a desktop widget for Windows that took some seriously basic globbing rules like match on "*.doc" and if it matches then move it to My Documents. You could select all the files on your desktop or your download directory and drag them to this widget on the dashboard and files would be moved depending on what rules matched.

drop-it started out trying to replicate that on the basis of dragging and dropping files, but over time it just made more sense scheduling a cron job to process certain directories for cleanup purposes.

The tool evolved to support rather comprehensive rules and actions to perform when a file matches, as well as supporting functionality like statistics on how frequently the rules are used.

The below is just to highlight some of the things that are possible using this tool.

Example rules:

  1. If the file is named *.sh, then don't check this file against any further rules (stop processing the file).

    --stop -file -glob {*.sh}

  2. If this is a file inside the "Documents" folder, then don't process this file.

    --stop -path -re {[\\\\/]Documents[\\\\/]}

  3. If the file is a document or a text file and the name includes "cover letter" then move that to our designated folder.

    --move ~/Documents/CV/cover_letters/ -nocase -file -re {cover.?letter.*.(docx?|txt)$}

  4. If the file extension is .bak then prefix the file name with a date and move the file to our backup directory.

    --date --move ~/Backup/ -nocase -glob {*.bak}

  5. If the file is a temporary file that ends with ~ then just delete it.

    --delete -glob {\*~}

  6. If the file is named Anti-Vir.Dat then let's delete (read move) it to our trash directory (defined with the configuration item DEF_TRASH). Note how configuration items within configuration items are substituted.

    --delete %DEF_TRASH% -file -glob {Anti-Vir.Dat}

  7. If this is a directory named "Downloads", then process all files inside this directory.

    --recurse -dir -glob {Downloads}

  8. If this is a .doc file then move it to the "My Documents" folder, but only if we are running this under windows.

    --windows --move "/home/sbakkeby/My Documents" -nocase -re {[.]docx?$}

  9. We had a rule that didn't do what we thought it would do so we disabled it by adding -- or --suspended.

    -- --delete -file -glob {*.*}

  10. If this is a .txt file that contains the text "Dear Margaret" then let's chuck that into the bin.

    --delete %DEF_TRASH% -file -glob {*.txt} -contains {Dear Margaret}

  11. If this is a budget CSV file, then let's pass that to our budget script for processing. Note how the %file% placeholder is passed in as part of the exec string, this will be substituted with the path to the file that matches the rule.

    --unix --exec {budget.sh -f %file%} -file -nocase -re {^.*budget.*.csv$}

  12. If the passed in file is actually a URL then attempt to download it.

    --unix --exec "wget -P /home/sbakkeby/Downloads %filename% 2>/dev/null" -text -re {^http.*}

Setup

Dependencies:

To set this up you will need:


Back to Other scripts and life hacks.

⚠️ **GitHub.com Fallback** ⚠️