Coder Social home page Coder Social logo

maid / maid Goto Github PK

View Code? Open in Web Editor NEW
1.8K 1.8K 84.0 817 KB

Be lazy. Let Maid clean up after you, based on rules you define. Think of it as "Hazel for hackers".

Home Page: http://rubygems.org/gems/maid

License: GNU General Public License v2.0

Ruby 97.96% Shell 1.79% Dockerfile 0.24%

maid's Introduction

Maid

Gem Version Test Code Climate Test Coverage StackOverflow

Be lazy! Let Maid clean up after you, based on rules you define.

Installation | Tutorial | Example | User Community | Documentation | Changelog

Maid keeps files from sitting around too long, untouched. Many of the downloads and temporary files you collect can easily be categorized and handled appropriately by rules you define. Let the maid in your computer take care of the easy stuff, so you can spend more of your time on what matters.

Think of it like the email filters you might already have, but for files. Worried about things happening that you don't expect? Maid doesn't overwrite files and actions are logged so you can tell what happened.

Maid is inspired by the Mac OS X shareware program Hazel. Think of Maid as "Hazel for hackers".

Your rules are defined in Ruby, so simple rules are easy and difficult rules are possible. This also makes Maid a great general-purpose advanced file renaming tool.

Want to help?

This project wouldn't be where it is today without its users and contributors. Thank you! See AUTHORS and the contributors graph for more info.

For Users

For Developers

  • Address a TODO or FIXME in the code (list them with rake notes.)
  • Fix an existing issue
  • Working on an issue? Please leave a comment so others know.
  • See the Contributing guide

Buzz

Hacker News Logo

Hazel for hackers - December 16th, 2012 (peaked at #2)

Ruby5 Logo

Podcast #302 (at 2:45) - August 31st, 2012

OneThingWell Logo

Maid - August 29th, 2012

More...

Installation

Maid is a gem, so just gem install maid like normal. If you're unfamiliar with Ruby, please see below for details.

Requirements

Modern Ruby versions and Unix-like operating systems should work, but only OS X and Ubuntu are tested regularly.

Offically supported:

  • OS: Mac OS X, Ubuntu
  • Ruby: 2.7.0+ (3.0.0+ preferred)

Some features require OS X. See the documentation for more details.

Manual Installation

First, you need Ruby 2.7 or 3. If you're starting without any Rubies, we strongly recommend going for Ruby 3 as 2.7 is EOL.

Consider using rvm, rbenv, rtx, or any other version management tool.

Then, install via RubyGems. Open a terminal and run:

gem install maid

At a later date, you can update by running:

gem update maid

If you decide you don't want Maid installed anymore, remove it:

gem uninstall maid

NOTE: This does not remove any files under ~/.maid or crontab entries. Please remove them at your convenience.

Install through RVM and a dedicated gemset

Install Ruby 3.2 and create a gemset:

rvm install ruby-3.2 && rvm use 3.2 && rvm gemset create maid && rvm alias create maid ruby-3.2@maid

Install maid:

rvm use maid && gem install maid

Update maid:

rvm use maid && gem update maid

Update ruby:

rvm install ruby-3.3 && rvm gemset copy 3.{2,3}@maid && rvm alias maid 3.3@maid

Tutorial

In a nutshell, Maid uses "rules" to define how files are handled. Once you have rules defined, you can either test what cleaning would do (maid clean -n) or actually clean (maid clean -f).

To generate a sample rules file, run:

maid sample

Maid rules are defined using Ruby, with some common operations made easier with a small DSL (Domain Specific Language).

For example, this is a rule:

Maid.rules do
  rule 'Old files downloaded while developing/testing' do
    dir('~/Downloads/*').each do |path|
      if downloaded_from(path).any? {|u| u.match 'http://localhost'} && 1.week.since?(accessed_at(path))
        trash(path)
      end
    end
  end
end

If you're new to Ruby and would prefer a more traditional for loop, you can also do this:

Maid.rules do
  rule 'My rule' do
    for path in dir('~/Downloads/*')
      # ...
    end
  end
end

Before you start running your rules, you'll likely want to be able to test them. Here's how:

# No actions are taken; you just see what would happen with your rules as defined.
maid clean --dry-run # Synonyms: -n, --noop

To run your rules on demand, you can run maid manually:

maid clean -f                 # Run the rules at ~/.maid/rules.rb, logging to ~/.maid/maid.log
maid clean -fr some_rules.rb  # Run the rules in the file 'some_rules.rb', logging to ~/.maid/maid.log

So, for example, if this is some_rules.rb:

Maid.rules do
  rule 'downloaded PDF books' do
    move(dir('~/Downloads/*.pdf'), '~/Books')
  end
end

Then, this is the command to test, as well as some sample output:

$ maid clean -nr some_rules.rb
Rule: downloaded PDF books
mv "/Users/ben/Downloads/book.pdf" "/Users/ben/Books/"
mv "/Users/ben/Downloads/issue12.pdf" "/Users/ben/Books/"
mv "/Users/ben/Downloads/spring2011newsletter.pdf" "/Users/ben/Books/"

For help with command line usage, run maid help. For more help, please see the links at the top of this README.

Automation

Once you get a hang for what you can do with Maid, let it do its stuff automatically throughout the day. You'll find your computer stays a little tidier with as you teach it how to handle your common files.

Note: Daemon support (using fsevent/inotify) was recently added. That said, cron takes care of the needs of many users.

To do this, edit your crontab in your tool of choice:

crontab -e

...and have it invoke the maid clean -f command. The --silent option is provided to keep this from emailing you, if desired. A log of the actions taken is kept at ~/.maid/maid.log.

Example for every day at 1am:

# minute hour day_of_month month day_of_week command_to_execute
0 1 * * * /bin/bash -li -c "maid clean --force --silent"

Running as a daemon

To run Maid as a daemon you first have to specify watch/repeat rules.

They are defined like this:

Maid.rules do
  repeat '1s' do
    rule 'This rule will run every second' do
      # some task
    end
  end

  watch '/home/user/Downloads' do
    rule 'This rule will run on every change to the downloads directory' do
      # another task
    end
  end

  watch '~/Desktop', ignore: /some_directory/ do
    # rules in here
  end
end

Here's a simple "watch" rule that organizes images by dimensions as soon as they're added to ~/Pictures:

Maid.rules do
  watch '~/Pictures' do
    rule 'organize images by dimensions' do
      where_content_type(dir('~/Pictures/*'), 'image').each do |image|
        width, height = dimensions_px(image)
        move(image, mkdir("~/Pictures/#{width}x#{height}"))
      end
    end
  end
end

The command to run the daemon is maid daemon. Starting the daemon on login depends on the platform.

With RVM and cron

See above to install RVM and maid in its own gemset.

Run maid daily in a cron:

# /etc/cron.daily/maid

#!/usr/bin/env bash
sudo -Hu <your username> bash -li -c "<your username>/.rvm/wrappers/maid/maid clean --force --silent --rules ~/.maid/rules.rb"

Ubuntu

You can run maid daemon as a normal startup application (Power/Gear Menu -> Startup Applications... -> Add).

OS X

Please see Jurriaan Pruis' blog post, Maid as a Daemon on OS X. (Automating this setup would be welcome as a pull request!)

Rake Tasks

Maid includes helpers that make file managment easier. You may find them useful if you need to automate tasks in your Ruby projects. This is available via support for Maid-based Rake tasks:

# File: Rakefile
require 'maid'

Maid::Rake::Task.new :clean do
  # Clean up Rubinius-compilied Ruby
  trash(dir('**/*.rbc'))
end

In fact, the Maid project uses Maid in its Rakefile.

You can also provide a custom description:

Maid::Rake::Task.new clean_torrents: [:dependency], description: 'Clean Torrents' do
  trash(dir('~/Downloads/*.torrent'))
end

Warranty

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM β€œAS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

License

GPLv2. See LICENSE for a copy.

maid's People

Contributors

amonks avatar benjaminoakes avatar bitdeli-chef avatar blomma avatar bobthecow avatar bradleyd avatar coaxial avatar jayrhynas avatar johai avatar johncolvin avatar jurriaan avatar larrylv avatar lewis-od avatar lostapathy avatar maid-release-bot avatar markjaquith avatar markprzepiora avatar mourner avatar nicosuave avatar p-lambert avatar phoolish avatar phylor avatar quintrino avatar sobolevn avatar songchenwen avatar winniethemu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maid's Issues

Add ability to list duplicate files

It would be useful for a Downloads directory, and possibly on a larger scale.

I'm unsure of how to best implement it. One possibility would be creating a digest (SHA1, etc) of each file and then picking out the duplicates that way. That would seem like a really slow solution; it might need some clever caching, etc.

# Something like this:
require 'digest/md5'
Digest::MD5.hexdigest(File.read(filename)) # maybe check modification times and cache in ~/.maid/digests

Use XDG standard for Maid configuration files

Since we're starting to use XDG on Linux, it may make sense to store configuration files, etc. according to the XDG standard. See http://rubyworks.github.com/xdg/

It would also work on OS X:

>> XDG['DATA_HOME'].to_s
 => "/Users/username/.local/share"

If this is done, it may make sense to add command line actions like the below before it is implemented, so people can easily find/edit their rules and log:

maid path:rules
maid path:log

(Not sure of the naming of those yet.)

Then you could do:

vi `maid path:rules`

Add "import into music library" tool

Just simplifying a common operation.

Something like this:

def move_to_music_library(paths)
  if Platform.osx?
    library_path = '~/Music/iTunes/iTunes Media/Automatically Add to iTunes/'
    # TODO: Handle .localized as well.  See issue #86
  elsif Platform.linux?
    library_path = '~/Music/'
  else
    raise NotImplementedError, 'Unknown music library path'
  end

  move(paths, library_path)
end

OSX zipfile extraction tool fails on zip files with UTF8 characters

The function for opening zip files as found in the sample rules file failed when unicode characters are in zip-file names.

The rule used:

rule 'Mac OS X applications in zip files' do
  dir('~/Downloads/*.zip').select do |path|
    candidates = zipfile_contents(path)
    candidates.any? { |c| c.match(/\.app$/) }
  end.each { |p| trash p }
end

The error:

/opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/tools.rb:97:in `split': invalid byte sequence in UTF-8 (ArgumentError)
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/tools.rb:97:in `zipfile_contents'
    from /Users/derekt/.maid/rules.rb:53:in `block (3 levels) in <top (required)>'
    from /Users/derekt/.maid/rules.rb:52:in `select'
    from /Users/derekt/.maid/rules.rb:52:in `block (2 levels) in <top (required)>'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/rule.rb:4:in `call'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/rule.rb:4:in `follow'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/maid.rb:78:in `block in follow_rules'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/maid.rb:76:in `each'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/maid.rb:76:in `follow_rules'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/maid.rb:51:in `clean'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/lib/maid/app.rb:23:in `clean'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
    from /opt/local/lib/ruby1.9/gems/1.9.1/gems/maid-0.1.2/bin/maid:5:in `<top (required)>'
    from /opt/local/bin/maid:23:in `load'
    from /opt/local/bin/maid:23:in `<main>'

Linux - Unsupported system command: "mdls -raw -name kMDItemDurationSeconds

Hi - just tried getting started with maid on linux/64bit/12.04

after installing it - icreated a sample rule - edited it - and continued with the test-function from your instructions. While running

maid --dry-run

with maid-0.1.0.gem i get

Rule: MP3s likely to be music
/var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/maid.rb:85:in cmd': Unsupported system command: "mdls -raw -name kMDItemDurationSeconds \"/home/fidel/Downloads/SOME_MP3_FILE.mp3\"" (ArgumentError) from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/tools.rb:89:induration_s'
from ./.maid/rules.sample.rb:20
from ./.maid/rules.sample.rb:19:in each' from ./.maid/rules.sample.rb:19 from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/rule.rb:4:incall'
from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/rule.rb:4:in follow' from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/maid.rb:74:infollow_rules'
from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/maid.rb:72:in each' from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/maid.rb:72:infollow_rules'
from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/maid.rb:47:in clean' from /var/lib/gems/1.8/gems/maid-0.1.0/lib/maid/app.rb:23:inclean'
from /var/lib/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:in send' from /var/lib/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:inrun'
from /var/lib/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:118:in invoke_task' from /var/lib/gems/1.8/gems/thor-0.14.6/lib/thor.rb:263:indispatch'
from /var/lib/gems/1.8/gems/thor-0.14.6/lib/thor/base.rb:389:in start' from /var/lib/gems/1.8/gems/maid-0.1.0/bin/maid:5 from /usr/local/bin/maid:19:inload'
from /usr/local/bin/maid:19

am i guessing right that this is some osx-specific setting?
If so - is there an option to disable the osx-related AND not in linux supported parts to avoid errors?
Or am i totally wrong and the error is somewhere else?

Please tell me if you are missing some relevant informations

Best regards in advance.

XDG gives a warning about RbConfig vs Config

As mentioned in #6:

I'm using the XDG standard, along with its implementation in Ruby. However, there's a minor bug that causes this to spit out a warning:

 /var/lib/gems/1.9.1/gems/xdg-2.2.2/lib/xdg/base_dir.rb:9: Use RbConfig instead of obsolete and deprecated Config.

It has already been fixed in a pull request. rubyworks/xdg#3

There will either be a fixed version of xdg in the next beta, or a workaround.

More Spotlight Attributes Supported

It would be nice to have more Spotlight Attributes supported such as:

kMDItemAttributeChangeDate
kMDItemContentCreationDate
kMDItemLastUsedDate
kMDItemContentModificationDate

kMDItemAuthors
kMDItemContentType

Could possibly be handled by a primer on how to add these to tools.rb file.

Add mkdir tool

Should probably do mkdir_p actually

I'm trying something in my personal rules.rb, but it still needs specs (FakeFS assisted, hopefully).

Add "humanize" reformatter

Still needs thought, but I've made something like it before...

humanize('Write_Yourself_a_Scheme_in_48_Hours.pdf')

which does:

'Write_Yourself_a_Scheme_in_48_Hours.pdf' 'Write Yourself a Scheme in 48 Hours.pdf'

Possibly more variations too.

Update dependencies

Since Maid was originally written in May 2011, a lot of its gem dependencies are out of date. They should be updated without other changes and then regression tested.

Should be a simple way for someone to get their feet wet. πŸ˜„

After doing that, let's add this badge to the README:

Dependency Status

[![Dependency Status](https://gemnasium.com/benjaminoakes/maid.png)](https://gemnasium.com/benjaminoakes/maid)

Trash does not expand paths

That is:

trash(dir('~/foo.zip') # works
trash('~/foo.zip') # doesn't work

I'm not sure why this wasn't detected earlier, but it might be because of magic that fakefs performs that doesn't act exactly like the standard library.

Move/trash an array of paths

Right now, moving multiple files is more difficult than it needs to be:

dir('~/Downloads/*.m4v').each { |p| move(p, '~/Videos/To Watch') }

It would be nice to be able to write:

move(dir('~/Downloads/*.m4v'), '~/Videos/To Watch')
# Or generally:
move(any_array_of_paths, '~/path/to/destination')

Basic implementation idea:

def move(froms, to)
  Array(froms).each |from|
    # existing `move` implementation...
  end
end

Something similar needs to be done with trash.

Allow dir to take multiple paths

Sometimes I have to do this:

(dir('foo/*') + dir('bar/*') + dir('baz/*'))

It would be nice to do this:

dir(['foo/*', 'bar/*', 'baz/*'])

Package for Ubuntu

Want easier installation? Make your voice heard.

It might be worth making a .deb and adding this to the Ubuntu Software Center for easier installation. Right now, there are just manual installation instructions in the README.

Interested? Just leave a comment with a +1 so I know. πŸ˜„

Beta test v0.1.3

This issue is meant to track the beta testing effort. Please make separate issues for any problems that you find, and include them in the simple-tools milestone. Please mention this issue too if you would (i.e., #52).

To install the beta:

gem install maid --pre

Because this is a beta, it's recommended to test this on a virtual machine before it handles any important data. Once it's been shown to be stable enough for everyday use (and it might be that stable now), please also test the beta in your normal use.

For a summary of changes in this version, please see https://github.com/benjaminoakes/maid/issues?milestone=1&state=closed

Note: The documentation at http://rubydoc.info/gems/maid/Maid/Tools will be out of date until a release is made; pre-releases don't update the documentation.

Add filetype detection

I often want to be able to say "move videos here"... but there are a lot of extensions that might include, so it's messy.

However, with mime types, I could look for video/*.

What this could look like:

# Example:  `~/Downloads/` has `foo.txt`, `foo.m4v`, and `foo.flv`

# With an `Array`, it filters:
mimetype(dir('~/Downloads/*'), 'video/*') # => ['foo.m4v', 'foo.flv']

# With a single path.  Still thinking about this one, but giving back an array makes sense in the context of the movement methods, etc.
mimetype('~/Downloads/foo.txt', 'video/*') # => []
mimetype('~/Downloads/foo.m4v', 'video/*') # => ['~/Downloads/foo.m4v']

# Full example:

# Move video files to `~/Videos/To Watch`
move(mimetype(dir('~/Downloads/*'), 'video/*'), '~/Videos/To Watch/')

# Same thing, but in two lines:
videos = mimetype(dir('~/Downloads/*'), 'video/*')
move(videos, '~/Videos/To Watch/')

Update README, samples with changes from simple-tools

We can be doing this throughout development, but it definitely needs to be rechecked before release.

Things to do:

  • Make sure the tutorial is still accurate, uses new calls as appropriate
  • Update sample rules to use the new tools (maybe adding new samples)
  • Maybe link to the sample rules

Add "compress" tool

Still needs thought:

Add a tool to compress a file or directory for archive purposes. Not sure which formats, etc (tar, zip, image/video compression, etc).

When would this be useful:

I have a set of directories that I work through, but as they get old, I don't look at them anymore. I want to archive them:

# Psuedo-code:
dir('~/Work/*').each do |path|
  if accessed_at?(path) > 1.week.ago
    compressed = compress(path)
    trash(path)
    move(compressed, '/path/to/long-term-storage')
  end
end

Or I have a folder that I want to archive, so I'll just drop it in a standard place, and just let Maid take care of it:

# Psuedo-code:
dir('~/Outbox/To Archive/*').each do |path|
  compressed = compress(path)
  trash(path)
  move(compressed, '/path/to/long-term-storage')
end

Or as a "trash compactor":

# Psuedo-code:
dir('/place/i/keep/easy/to/compress/files').each do |path|
  compressed = compress(path)
  delete(path)
  trash(compressed)
end
# Psuedo-code:
dir("#{trash_path}/files-that-are-easy-to-compress").each do |path|
  compress(path)
  delete(path)
end

Bug | maid --dry-run and --noop and -n dont work with 0.1.2

Just updated to 0.1.2 on ubuntu - regenerated a sample config via 'maid sample' which worked as expected.
I edited that sample - saved it and renamed it. Great so far ;)

Executing:

maid --dray-run
or
maid--noop
or
maid -n

all fail here with the following output:

Unknown switch XY

Is that a result of the update or am i doing something wrong?

Edit:
basically it looks like i cant execute any maid command which comes with a --parameter.
Just tested 'maid version' which worked - but 'maid -nr rules.rb' doesnt work.

Add date reformatter

Still needs thought, but I've made something like it before...

The idea:

# "Magic" version (does some interpolation and uses a default format)
format_date('Some Bill 09-11-12.pdf')
# Specifying the input format...
format_date('Some Bill 09-11-12.pdf', input: '%m-%d-%y')
# Fully specified
format_date('Some Bill 09-11-12.pdf', input: '%m-%d-%y', output: '%Y-%m-%d')

which transforms like so:

'Some Bill 09-11-12.pdf' => 'Some Bill 2012-09-11.pdf'

Possible usage:

# An NBC podcast:  http://podcastfeeds.nbcnews.com/audio/podcast/MSNBC-NN-NETCAST-M4V.xml
dir('~/Downloads/pdv_nn_netcast_m4v-*.m4v').each do |path|
  move(path, format_date(path, input: '%m-%d-%Y'))
  # or: move(path, '/path/to/someplace/else/' + format_date(path, input: '%m-%d-%Y'))
end

From a script I've written before, which could be adapted:

require 'date'

def reformat(path)
  basename = File.basename(path).gsub(/\.[^.]*?$/, '')

  begin
    parsed = Date.parse(basename)
  rescue ArgumentError # "invalid date" (e.g. 03-25-2011)
    split = basename.split(/[^A-Za-z0-9\s]/)

    if split.last.length == 4
      split.unshift(split.pop)
    end

    parsed = Date.parse(split.join('/'))
  end

  formatted = parsed.strftime('%Y.%m.%d')

  path.sub(basename, formatted)
end

Add timestamp tool

timestamp('foo') # => moved to 'foo 2012-10-25-13-53' (or something similar, maybe ISO 8601 date)

Add a man page

Original title:

Feature-request | man-page

Hi,
how about adding a man-page?

afaik both system (linux and osx with bsd under it) do use man to offer instructions about cli-applications.

might be related with the install-script

Add modified_at tool

I moved this into a separate issue (originally in #10).

From @MacDude:

I'm playing with it on MacOSX. I don't have much Ruby experience, but I'd like to see something like:

def modified_time(path)
cmd("mdls -raw -name kMDItemAttributeChangeDate #{path.inspect}")
end

In the tools.rb

Add tool to empty trash (first in, first out)

I don't need files in the trash that are there for a while... but I'm more likely to need the ones I just threw away. The only option I'm given is "empty trash" in the Finder or Nautilus, which gets rid of everything.

It'd be nice if Maid could get rid of the older trash first.

Add "rule packs" so people can share their rules easily

Keeping with the Maid theme, we might call them "appliances".

I'd want to be able to have a folder like ~/.maid/appliances that has a set of appliances. Rules that would be highly reusable could be stored there, and people could mix and match rules with other users, but not have to get them merged into Maid itself.

For example, this is a highly reusable rule, which might be at ~/.maid/appliances/dump_tmp.rb:

rule 'Dump temp folder into the trash' do
  trash('~/tmp')
  mkdir('~/tmp')
end

Another:

rule 'Move downloaded videos to unwached video folder' do
  to_watch = '~/Videos/To Watch'

  mkdir(to_watch)
  move(dir('~/Downloads/*.webm'), to_watch)
  move(dir('~/Downloads/*.m4v'), to_watch)
  move(dir('~/Downloads/*.mp4'), to_watch)
end

Sort results from dir tool

At least on Ubuntu 12.04.1, they sometimes come out not in lexical (alphabetical) order.

It's a bigger issue when you're testing using --noop and there's no apparent order. For example, I had to sort in this script.

If there's a big performance penalty, we could possibly only do this when noop is set. But I don't think that's worth the effort/complexity right now. Best to always sort.

difference between different maid clean parameters

I am wondering where the diff between (copied from README.md)

maid clean --dry-run
maid clean --noop
maid clean -n

is.

If i execute those 3 variations i always get the same output (0.1.2 on linux/ubuntu) ... but i assume they are supposed to be somehow different ...or am i wrong in the first place?

Add replace_dir

I have some workflows that trash then recreate a directory. That could warrant a helper method.

Want to beta test? Please leave a comment so you can be notified.

From issue #8:

Given the amount of people that have recently started using Maid, I'd like to start making beta releases before making stable releases.

For now, please just leave a comment bellow so I know you're interested. During the next release, I'll coordinate a beta test by notifying you (via an @mention). Details on how to install, etc. will be given then.

Where possible, change specs to use FakeFS instead of mocking/stubbing

NOTE: This has already been started on the simple-tools branch. If you pick this issue to work on, please work off that branch.

We depend too much on mocking and stubbing that could be handled more generally using FakeFS. It's not entirely clear how many specs could be simplified, however.

Basically, the specs should reflect what actually happens ("a file is here, the foo command is run, then it no longer exists") rather than implementation details ("foo should receive bar with baz").

More info: https://github.com/defunkt/fakefs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.