pouf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/pouf +43 -0
  3. data/lib/pouf.rb +75 -0
  4. metadata +46 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5d6ea2b042746cd8f4ed374838abc96ab1fe545
4
+ data.tar.gz: a30c9057a1c7f67611fffc8f1e66bcd0b5a1da7b
5
+ SHA512:
6
+ metadata.gz: 3575ca079b5cec0f779829a8e1f9f8c3ab702d36e991271f54d7b70fd69eca9534ab6e32e9222721babcc78e991edcc97ae0de1054aa07fd64d08cc165d11d22
7
+ data.tar.gz: 2acc7c2e46d31cd3e8f40d140fc3242acf6af57225cf775e39f2c9b060ce0b596933eb71c0c3a7988a1a4a63d961b18b75baa267c494aaf0d939a0feff2eefef
@@ -0,0 +1,43 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+
4
+ require 'pouf'
5
+
6
+ def show_help
7
+ puts <<-EOH
8
+ Usage:
9
+ pouf [command] [args]
10
+
11
+ Available commands:
12
+ add <alias> <filename> - Add a new sound by copying <filename>
13
+ ls - List all available sounds
14
+ play <alias> - Play a sound
15
+ rm <alias> - Remove a sound
16
+
17
+ If the command doesn't exist, pouf will assume it's a sound alias. This allows
18
+ for shorter commands, e.g. `pouf bar` instead of `pouf play bar`.
19
+ EOH
20
+ exit
21
+ end
22
+
23
+ Pouf.init
24
+ cmd = ARGV.shift
25
+
26
+ case cmd
27
+ when 'add' then
28
+ name, filename = ARGV
29
+ show_help unless name and filename
30
+ Pouf.add(name, filename)
31
+ when 'ls' then
32
+ puts Pouf.list.map{ |s| " - #{s}" }.join("\n")
33
+ when 'mv' then
34
+ a1, a2 = ARGV
35
+ show_help unless a1 and a2
36
+ Pouf.mv(a1, a2)
37
+ when 'rm' then
38
+ show_help if ARGV.empty?
39
+ Pouf.rm(*ARGV)
40
+ else
41
+ show_help if !cmd
42
+ Pouf.play cmd == 'play' ? ARGV.first : cmd
43
+ end
@@ -0,0 +1,75 @@
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
3
+
4
+ require 'fileutils'
5
+
6
+ module Pouf
7
+ class << self
8
+
9
+ SOUNDS_DIR = File.expand_path("~/.pouf/sounds")
10
+
11
+ def version
12
+ '0.1.0'
13
+ end
14
+
15
+ def play_sound filename
16
+ # only OSX for now
17
+ system 'afplay', filename if filename
18
+ end
19
+
20
+ def alias2filename name
21
+ fns = Dir["#{SOUNDS_DIR}/#{name}.*"]
22
+ fns.first if fns
23
+ end
24
+
25
+ def filename2alias fname
26
+ fname =~ /(?:.*?\/)?(.+)\.\w+$/
27
+ $1
28
+ end
29
+
30
+ ## Actions ##
31
+
32
+ def add name, fname
33
+ fname =~ /.+\.(\w+)$/
34
+ ext = $1
35
+
36
+ FileUtils.cp fname, "#{SOUNDS_DIR}/#{name}.#{ext}"
37
+ end
38
+
39
+ def init
40
+ FileUtils.mkdir_p SOUNDS_DIR
41
+ end
42
+
43
+ def list
44
+ Dir.entries(SOUNDS_DIR).select{ |f| f !~ /^\./ }.map do |f|
45
+ filename2alias f
46
+ end
47
+ end
48
+
49
+ def mv from, to
50
+ f1 = alias2filename from
51
+ f2 = f1.sub(/\/#{from}\./, "/#{to}.")
52
+
53
+ FileUtils.mv(f1, f2) if f1 and f2
54
+ end
55
+
56
+ def play *aliases
57
+ aliases.each do |a|
58
+ fname = alias2filename a
59
+ play_sound fname if fname
60
+ end
61
+ end
62
+
63
+ def rm *names
64
+ names.each do |n|
65
+ fs = alias2filename n
66
+ if fs
67
+ FileUtils.rm fs
68
+ else
69
+ puts "Warning: No sound found for '#{n}'."
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pouf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Baptiste Fontaine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Quickly play random short sounds from the command-line
14
+ email: batifon@yahoo.fr
15
+ executables:
16
+ - pouf
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/pouf.rb
21
+ - bin/pouf
22
+ homepage: https://github.com/bfontaine/pouf
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Play random sounds from the command-line
46
+ test_files: []