Skip to content

Commit 12e325d

Browse files
committed
Tweak and document print-screen command, add feature spec
1 parent 05480f9 commit 12e325d

File tree

5 files changed

+98
-27
lines changed

5 files changed

+98
-27
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
== Next
2+
* New command to print password to screen, patch by @terabyte
23
* New option to exclude specific characters when generating new passwords, patch by @alex0112
34
* Update (and loosen up) clipboard dependency
45

Diff for: features/print-screen.feature

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Feature: PrintScreen
2+
In order to have a helpful password safe when I have no clipboard
3+
As a user
4+
I want to disply passwords from my password safe
5+
6+
Scenario: Get the password for "github" (which exists) and print it to the screen
7+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
8+
When I run `pws ps github 0` interactively
9+
And I type "my_master_password"
10+
Then the output should contain "Master password:"
11+
And the output should contain "The password for github is:\ngithub_password"
12+
13+
14+
Scenario: Get the password for "github" (which exists) and print it to the screen for 10 seconds
15+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
16+
When I run `pws ps github` interactively
17+
And I type "my_master_password"
18+
Then the output should contain "Master password:"
19+
And the output should contain "The password for github will be displayed for 10 seconds:\ngithub"
20+
21+
Scenario: Get the password for "github" (which exists) and print it to the screen for 1 second
22+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
23+
When I run `pws ps github 1` interactively
24+
And I type "my_master_password"
25+
Then the output should contain "Master password:"
26+
And the output should contain "The password for github will be displayed for 1 second:\ngithub"
27+
28+
29+
Scenario: Get the password for "github" (which exists) and print it to the screen for 5 seconds when PWS_SECONDS is set to 5
30+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
31+
When I set env variable "PWS_SECONDS" to "5"
32+
And I run `pws ps github` interactively
33+
And I type "my_master_password"
34+
Then the output should contain "Master password:"
35+
And the output should contain "The password for github will be displayed for 5 seconds:\ngithub"
36+
37+
Scenario: Try to get the password for "google" (which does not exist)
38+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
39+
When I run `pws ps google` interactively
40+
And I type "my_master_password"
41+
Then the output should contain "Master password:"
42+
And the output should contain "No password found for google!"
43+
44+
Scenario: Try to get the password for "github" (but the master password is wrong)
45+
Given A safe exists with master password "my_master_password" and a key "github" with password "github_password"
46+
When I run `pws ps github` interactively
47+
And I type "my_master_password_wrong"
48+
Then the output should contain "Master password:"
49+
And the output should contain "NO ACCESS"
50+
51+
Scenario: Get the password for "gihub" using an abbrev shortcut
52+
Given A safe exists with master password "my_master_password" and keys
53+
| github | 123 |
54+
| google | 345 |
55+
| gitorious | 678 |
56+
When I run `pws ps gith 0` interactively
57+
And I type "my_master_password"
58+
Then the output should contain "Master password:"
59+
And the output should contain "The password for github is:\n123"
60+
61+
62+

Diff for: features/update-generate.feature

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Feature: Update
1+
Feature: UpdateGenerate
22
In order to keep my privacy
33
As a user
44
I want to update a password entry and generate the new password

Diff for: lib/pws.rb

+26-26
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,6 @@ def show(pattern = nil)
6161
end
6262
aliases_for :show, :ls, :list, :status
6363

64-
# print a password entry to the screen
65-
def print_screen(key, seconds = @options[:seconds])
66-
if real_key = @abbrevs[key]
67-
password = @data[real_key][:password]
68-
if seconds && seconds.to_i > 0
69-
#pa %[The password for #{real_key} will be displayed for #{seconds.to_i} seconds: #{password}], :green
70-
print Paint[%[The password for #{real_key} will be displayed for #{seconds.to_i} seconds: #{password}], :green]
71-
begin
72-
sleep seconds.to_i
73-
rescue Interrupt
74-
puts "\e[999D\e[K\e[1A" if $stdin.tty? # clear the pw from the screen
75-
raise
76-
end
77-
puts "\e[999D\e[K\e[1A" if $stdin.tty? # clear the pw from the screen
78-
return true
79-
else
80-
pa %[The password for #{real_key} is: #{password}], :green
81-
return true
82-
end
83-
else
84-
pa %[No password found for #{key}!], :red
85-
return false
86-
end
87-
end
88-
aliases_for :print_screen, :ps
89-
9064
# Add a password entry, params: name, password (optional, opens prompt if not given)
9165
def add(key, password = nil)
9266
if @data[key]
@@ -153,6 +127,32 @@ def get(key, seconds = @options[:seconds])
153127
end
154128
end
155129
aliases_for :get, :entry, :copy, :password, :for, :[]
130+
131+
# Print a password entry to the screen
132+
def print_screen(key, seconds = @options[:seconds])
133+
if real_key = @abbrevs[key]
134+
password = @data[real_key][:password]
135+
if seconds && seconds.to_i > 0
136+
print Paint[%[The password for #{real_key} will be displayed for #{seconds.to_i} second#{?s if seconds.to_i > 1}:\n#{password}], :green]
137+
begin
138+
sleep seconds.to_i
139+
rescue Interrupt
140+
puts "\e[999D\e[K\e[1A"*2 if $stdin.tty? # clear the pw from the screen
141+
raise
142+
end
143+
puts "\e[999D\e[K\e[1A"*2 if $stdin.tty? # clear the pw from the screen
144+
return true
145+
else
146+
pa %[The password for #{real_key} is:\n#{password}], :green
147+
return true
148+
end
149+
else
150+
pa %[No password found for #{key}!], :red
151+
return false
152+
end
153+
end
154+
alias :'print-screen' :print_screen
155+
alias :ps :print_screen
156156

157157
# Adds a password entry with a freshly generated random password
158158
def generate(

Diff for: lib/pws/runner.rb

+8
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ def run(action, arguments, options)
6868
#{Paint['get', :bold]} / entry / copy / password / for ( name, seconds = 10 )
6969
Copies the password for <name> to the clipboard. The second argument specifies,
7070
how long the password is kept in the clipboard (0 = no deletion).
71+
Please keep in mind that other programs can access (and log) the contents
72+
of your clipboard.
73+
74+
#{Paint['ps', :bold]} / print-screen ( name, seconds = 10 )
75+
Displays the password on stdout. The second argument specifies,
76+
how long the password is shown (0 = no deletion).
77+
Please keep in mind that the password will appear in your shell's logfile,
78+
for example, in "~/.bash_history"
7179
7280
#{Paint['add', :bold]} / set / store / create ( name, password = nil )
7381
Stores a new password entry. The second argument can be the password, but

0 commit comments

Comments
 (0)