shh 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/bin/shh CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.dirname(__FILE__)+'/../lib'
4
- require 'shh'
4
+ require 'shh/cli'
5
5
  Shh::Cli.execute(*ARGV)
data/lib/shh.rb CHANGED
@@ -1 +1,25 @@
1
- require 'shh/cli'
1
+ module Shh
2
+ def self.clipboard
3
+ if RUBY_PLATFORM =~ /mswin32/
4
+ require 'shh/win32_clipboard'
5
+ return Win32Clipboard.new
6
+ end
7
+ if RUBY_PLATFORM =~ /darwin10/
8
+ require 'shh/darwin10_clipboard'
9
+ return Darwin10Clipboard.new
10
+ end
11
+ nil
12
+ end
13
+
14
+ def self.launcher
15
+ if RUBY_PLATFORM =~ /mswin32/
16
+ require 'shh/win32_launcher'
17
+ return Win32Launcher.new
18
+ end
19
+ if RUBY_PLATFORM =~ /darwin10/
20
+ require 'shh/darwin10_launcher'
21
+ return Darwin10Launcher.new
22
+ end
23
+ nil
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ class Darwin10Launcher
2
+ def launch text
3
+ `open #{text}`
4
+ end
5
+ end
@@ -21,7 +21,7 @@ module Shh
21
21
  when 'refresh'
22
22
  refresh
23
23
  when 'list'
24
- list
24
+ @entries.each {|entry| say entry }
25
25
  when /^view (.*)/
26
26
  view $1
27
27
  when /^edit (.*)/
@@ -37,7 +37,9 @@ module Shh
37
37
 
38
38
  def refresh
39
39
  commands = ['list', 'refresh', 'quit']
40
+ @entries = []
40
41
  @repository.each_entry do |entry|
42
+ @entries << "#{entry['name']} (#{entry['id']})"
41
43
  commands << "edit #{entry['name']}"
42
44
  commands << "view #{entry['name']}"
43
45
  end
@@ -47,10 +49,6 @@ module Shh
47
49
  Readline.completer_word_break_characters = ''
48
50
  end
49
51
 
50
- def list
51
- @repository.each_entry {|entry| say "#{entry['name']} (#{entry['id']})" }
52
- end
53
-
54
52
  def edit name
55
53
  entry = @repository.find_entry(name)
56
54
  entry ||= {'name' => name, 'id' => UUIDTools::UUID.random_create.to_s}
@@ -1,10 +1,11 @@
1
- require 'shh/clipboard'
1
+ require 'shh'
2
2
 
3
3
  module Shh
4
4
  class EntryMenu
5
5
  def initialize prompt, hash, read_only=false
6
6
  @prompt, @hash, @read_only = prompt, hash, read_only
7
7
  @clipboard = Shh.clipboard
8
+ @launcher = Shh.launcher
8
9
  refresh
9
10
  end
10
11
 
@@ -20,17 +21,15 @@ module Shh
20
21
  when 'list'
21
22
  say(@hash.keys.sort.join(','))
22
23
  when /^edit (.*)/
23
- name = $1
24
- @hash[name] = new_value(name) unless @read_only
24
+ edit $1
25
25
  when /^copy (.*)/
26
- name = $1
27
- @clipboard.content = @hash[name] if @clipboard and @hash[name]
26
+ copy $1
27
+ when /^launch (.*)/
28
+ launch $1
28
29
  when /^delete (.*)/
29
- name = $1
30
- @hash.delete(name) unless @read_only
30
+ delete $1
31
31
  when /^show (.*)/
32
- name = $1
33
- say(@hash[name]) if @hash[name]
32
+ show $1
34
33
  end
35
34
  end
36
35
  rescue Interrupt => e
@@ -43,13 +42,52 @@ module Shh
43
42
 
44
43
  private
45
44
 
45
+ def can_copy? key
46
+ @clipboard and @hash[key]
47
+ end
48
+
49
+ def can_edit?
50
+ !@read_only
51
+ end
52
+
53
+ def can_launch? key
54
+ @launcher and @hash[key] =~ /^http\:\/\//
55
+ end
56
+
57
+ def show key
58
+ say(@hash[key]) if @hash[key]
59
+ end
60
+
61
+ def copy key
62
+ @clipboard.content = @hash[key] if can_copy?(key)
63
+ end
64
+
65
+ def edit key
66
+ if can_edit?
67
+ @hash[key] = new_value(key)
68
+ refresh
69
+ end
70
+ end
71
+
72
+ def delete key
73
+ if can_edit?
74
+ @hash.delete(key)
75
+ refresh
76
+ end
77
+ end
78
+
79
+ def launch key
80
+ @launcher.launch @hash[key] if can_launch?(key)
81
+ end
82
+
46
83
  def refresh
47
84
  commands = ['list', 'quit']
48
85
  @hash.keys.each do |key|
49
- commands << "edit #{key}" unless @read_only
50
- commands << "delete #{key}" unless @read_only
86
+ commands << "edit #{key}" if can_edit?
87
+ commands << "delete #{key}" if can_edit?
51
88
  commands << "show #{key}"
52
- commands << "copy #{key}"
89
+ commands << "copy #{key}" if can_copy?(key)
90
+ commands << "launch #{key}" if can_launch?(key)
53
91
  end
54
92
  Readline.completion_proc = lambda do |text|
55
93
  commands.grep( /^#{Regexp.escape(text)}/ ).sort
@@ -57,8 +95,8 @@ private
57
95
  Readline.completer_word_break_characters = ''
58
96
  end
59
97
 
60
- def new_value name
61
- @prompt.get "Enter new value for #{name}", :silent => (name =~ /pass/)
98
+ def new_value key
99
+ @prompt.get "Enter new value for #{key}", :silent => (key =~ /pass/)
62
100
  end
63
101
  end
64
102
  end
@@ -5,7 +5,7 @@ module Shh
5
5
  def get text, params={}
6
6
  return params[:value] if params[:value] and params[:value].size > 0
7
7
  echo = params[:silent] ? false : true
8
- ask(text) { |q| q.echo = false }
8
+ ask(text) { |q| q.echo = echo }
9
9
  end
10
10
  end
11
11
  end
@@ -0,0 +1,5 @@
1
+ class Win32Launcher
2
+ def launch text
3
+ `start #{text}`
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -64,14 +64,15 @@ extra_rdoc_files: []
64
64
 
65
65
  files:
66
66
  - lib/shh/cli.rb
67
- - lib/shh/clipboard.rb
68
67
  - lib/shh/crypt.rb
69
68
  - lib/shh/darwin10_clipboard.rb
69
+ - lib/shh/darwin10_launcher.rb
70
70
  - lib/shh/entries_menu.rb
71
71
  - lib/shh/entry_menu.rb
72
72
  - lib/shh/prompt.rb
73
73
  - lib/shh/repository.rb
74
74
  - lib/shh/win32_clipboard.rb
75
+ - lib/shh/win32_launcher.rb
75
76
  - lib/shh.rb
76
77
  - bin/shh
77
78
  - README.rdoc
@@ -1,13 +0,0 @@
1
- module Shh
2
- def self.clipboard
3
- if RUBY_PLATFORM =~ /mswin32/
4
- require 'shh/win32_clipboard'
5
- return Win32Clipboard.new
6
- end
7
- if RUBY_PLATFORM =~ /darwin10/
8
- require 'shh/darwin10_clipboard'
9
- return Darwin10Clipboard.new
10
- end
11
- nil
12
- end
13
- end