Compare commits
2 Commits
ce5bca45a3
...
d49dcda651
Author | SHA1 | Date | |
---|---|---|---|
d49dcda651 | |||
6fc0459d81 |
@ -6,7 +6,9 @@
|
||||
- ℹ️ - Information
|
||||
- ♻️ - Edited
|
||||
|
||||
## 0.2.1 - [13/03/2022]
|
||||
## 0.2.1 - [14/03/2022]
|
||||
- ➕ - prompt '>' set color green
|
||||
- ♻️ - change default pwd path to '$HOME/.pwd.yml'
|
||||
- ✔️ - fixed empty search field
|
||||
- ✔️ - fixed password generate colors to russian flag
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: pmng
|
||||
version: 0.1.0
|
||||
version: 0.2.1
|
||||
|
||||
authors:
|
||||
- Alexander Popov <iiiypuk@iiiypuk.me>
|
||||
|
40
src/pmng.cr
40
src/pmng.cr
@ -2,6 +2,7 @@ require "option_parser"
|
||||
require "yaml"
|
||||
require "colorize"
|
||||
|
||||
# password serializer
|
||||
class Password
|
||||
include YAML::Serializable
|
||||
|
||||
@ -23,9 +24,10 @@ end
|
||||
|
||||
VERSION = "0.2.1"
|
||||
|
||||
# program options
|
||||
begin
|
||||
OptionParser.parse do |parser|
|
||||
parser.banner = "pmng -- ver.: #{VERSION}\nThe very simple password manager for humans\n"
|
||||
parser.banner = "The very simple password manager for humans\n"
|
||||
|
||||
parser.on "-v", "--version", "Show version" do
|
||||
puts "Version #{VERSION}"
|
||||
@ -50,11 +52,15 @@ rescue ex
|
||||
puts ex.message, ""
|
||||
end
|
||||
|
||||
password_file_path = PROGRAM_NAME.split("/")
|
||||
password_file_path.pop
|
||||
password_file_path.insert(-1, "pwd.yml")
|
||||
password_file_path = password_file_path.join("/")
|
||||
# password_file_path = PROGRAM_NAME.split("/")
|
||||
# password_file_path.pop
|
||||
# password_file_path.insert(-1, "pwd.yml")
|
||||
# password_file_path = password_file_path.join("/")
|
||||
|
||||
# TODO: Fix later
|
||||
password_file_path = "#{ENV["HOME"]}/.pwd.yml"
|
||||
|
||||
# check password file exists
|
||||
if File.exists?(password_file_path)
|
||||
yaml = File.open(password_file_path) do |file|
|
||||
YAML.parse(file)
|
||||
@ -65,37 +71,44 @@ else
|
||||
exit(1)
|
||||
end
|
||||
|
||||
new_array = [] of Password
|
||||
# fill passwords array
|
||||
passwords_array = [] of Password
|
||||
count = 0
|
||||
while count < yaml.size
|
||||
new_array << Password.from_yaml(yaml[count].to_yaml)
|
||||
passwords_array << Password.from_yaml(yaml[count].to_yaml)
|
||||
count += 1
|
||||
end
|
||||
|
||||
# main loop
|
||||
loop = true
|
||||
while loop
|
||||
print "Enter URL (or :q for exit)\n> "
|
||||
# shell prompt
|
||||
print "Enter URL (or :q for exit)\n"
|
||||
print "> ".colorize(:green)
|
||||
password_string = gets
|
||||
|
||||
# if ':q' to close program
|
||||
if password_string.to_s == ":q"
|
||||
puts "Bye! 👋🏻"
|
||||
exit(0)
|
||||
# if puts empty, retry prompt
|
||||
elsif password_string.to_s.size == 0
|
||||
puts
|
||||
# if ':h' to view help
|
||||
elsif password_string.to_s == ":h"
|
||||
puts "Help:\n-----"
|
||||
puts ":s - Return stats"
|
||||
|
||||
# if ':s' to view Statistics
|
||||
elsif password_string.to_s == ":s"
|
||||
puts "Statictics:\n----------"
|
||||
puts "Statistics:\n----------"
|
||||
print "Elements: ".colorize(:yellow)
|
||||
puts new_array.size
|
||||
puts passwords_array.size
|
||||
|
||||
print "Outdated: ".colorize(:red)
|
||||
outdated_count = 0
|
||||
current_time = Time.local.to_unix
|
||||
a = [] of String
|
||||
new_array.each do |item|
|
||||
passwords_array.each do |item|
|
||||
if item.update + (2629743 * 2) < current_time # 2629743 * 2 -- 2 month
|
||||
outdated_count += 1
|
||||
a << item.url
|
||||
@ -103,8 +116,9 @@ while loop
|
||||
end
|
||||
|
||||
puts outdated_count
|
||||
# list search password
|
||||
else
|
||||
new_array.each do |item|
|
||||
passwords_array.each do |item|
|
||||
if item.url.includes?(password_string.to_s)
|
||||
puts item.url.colorize(:magenta).mode(:blink)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user