first commit

This commit is contained in:
encrypt 2016-02-16 19:47:18 +01:00
commit 8f3b0d8846
6 changed files with 117 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*~

7
Makefile Normal file
View file

@ -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/

46
organize.rb Normal file
View file

@ -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

56
organizers/organizer.json Normal file
View file

@ -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
}
]

3
scripts/dummy-script.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
echo "dummy-script: $1"

4
scripts/unzip-music.sh Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
unzip -n "$1" -d ~/music
rm -rf "$1"