commit 8f3b0d88465a9dbe6f154d1d411605c53cd383ab Author: encrypt Date: Tue Feb 16 19:47:18 2016 +0100 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b25c15b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1d63d05 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +install: + cp organize.rb /usr/local/bin/organize + +install-config: + mkdir -p ${HOME}/.config/organize/scripts + cp -R scripts/ ${HOME}/.config/organize/scripts + cp organizers/* ${HOME}/.config/organize/ diff --git a/organize.rb b/organize.rb new file mode 100644 index 0000000..3f0e022 --- /dev/null +++ b/organize.rb @@ -0,0 +1,46 @@ +#!/usr/bin/env ruby +require 'json' +require 'fileutils' + + +organizer = JSON.parse(File.read(File.expand_path('~/.config/organize/organizer.json'))) + +organizer.each do |match| + puts "[+] Match: "+match["match"] + keep_answer = false + answer = nil + Dir.glob(match["match"]).each do |file| + file = File.realdirpath(file) + puts " [-] File matched "+file + + if match.has_key?("ask_confirm") and match["ask_confirm"] + if !keep_answer + print "Really y,n ! " + answer = gets.chomp + end + keep_answer = true if answer.match /(y|n)!/ + case answer + when /y!?/ + when /n!?/ + next + end + end + + match["action"] = "none" unless match.has_key?("action") # no action if action not exists + + case match["action"] + when "exec" + if match.has_key?("exec") + system match["exec"]+' "'+File.expand_path(file)+'"' + end + when "move" + if match.has_key?("to") + FileUtils.mv(file, File.expand_path(match["to"])) + end + when "remove" + FileUtils.rm(file) + when "none" + else + end + end +end diff --git a/organizers/organizer.json b/organizers/organizer.json new file mode 100644 index 0000000..d104f82 --- /dev/null +++ b/organizers/organizer.json @@ -0,0 +1,56 @@ +[ + { + "name": "music-p4f", + "match": "*{\\[P4F\\],p4f}.zip", + "action": "exec", + "exec": "~/.config/organize/scripts/unzip-music.sh" + }, + { + "name": "screenshots", + "match": "*_scrot.png", + "action": "move", + "to": "~/images/screenshots" + }, + { + "match": "*.html", + "action": "move", + "to": "~/docs/html/" + }, + { + "match": "*.pdf", + "action": "move", + "to": "~/docs/pdf/" + }, + { + "match": "*.txt", + "action": "move", + "to": "~/docs/txt/" + }, + { + "match": "*.{jpeg,jpg,gif,png,svg,xcf}", + "action": "move", + "to": "~/images/" + }, + { + "match": "*.{mkv,mp4,wmv}", + "action": "move", + "to": "~/videos" + }, + { + "match": "*.{sh,bash}", + "action": "move", + "to": "~/random/code/sh", + "ask_confirm": true + }, + { + "match": "*.c", + "action": "move", + "to": "~/random/code/c", + "ask_confirm": true + }, + { + "match": "*~", + "action": "remove", + "ask_confirm": true + } +] diff --git a/scripts/dummy-script.sh b/scripts/dummy-script.sh new file mode 100755 index 0000000..e5303fb --- /dev/null +++ b/scripts/dummy-script.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "dummy-script: $1" diff --git a/scripts/unzip-music.sh b/scripts/unzip-music.sh new file mode 100755 index 0000000..17ec7d5 --- /dev/null +++ b/scripts/unzip-music.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +unzip -n "$1" -d ~/music +rm -rf "$1"