change pwd path

This commit is contained in:
Alexander Popov 2022-03-15 01:42:17 +03:00
parent ce5bca45a3
commit 6fc0459d81
Signed by: iiiypuk
GPG Key ID: 3F76816AEE08F908
2 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,5 @@
name: pmng name: pmng
version: 0.1.0 version: 0.2.1
authors: authors:
- Alexander Popov <iiiypuk@iiiypuk.me> - Alexander Popov <iiiypuk@iiiypuk.me>

View File

@ -2,6 +2,7 @@ require "option_parser"
require "yaml" require "yaml"
require "colorize" require "colorize"
# password serializer
class Password class Password
include YAML::Serializable include YAML::Serializable
@ -23,6 +24,7 @@ end
VERSION = "0.2.1" VERSION = "0.2.1"
# program options
begin begin
OptionParser.parse do |parser| OptionParser.parse do |parser|
parser.banner = "pmng -- ver.: #{VERSION}\nThe very simple password manager for humans\n" parser.banner = "pmng -- ver.: #{VERSION}\nThe very simple password manager for humans\n"
@ -50,11 +52,15 @@ rescue ex
puts ex.message, "" puts ex.message, ""
end end
password_file_path = PROGRAM_NAME.split("/") # password_file_path = PROGRAM_NAME.split("/")
password_file_path.pop # password_file_path.pop
password_file_path.insert(-1, "pwd.yml") # password_file_path.insert(-1, "pwd.yml")
password_file_path = password_file_path.join("/") # 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) if File.exists?(password_file_path)
yaml = File.open(password_file_path) do |file| yaml = File.open(password_file_path) do |file|
YAML.parse(file) YAML.parse(file)
@ -72,22 +78,27 @@ while count < yaml.size
count += 1 count += 1
end end
# main loop
loop = true loop = true
while loop while loop
# shell prompt
print "Enter URL (or :q for exit)\n> " print "Enter URL (or :q for exit)\n> "
password_string = gets password_string = gets
# if ':q' to close program
if password_string.to_s == ":q" if password_string.to_s == ":q"
puts "Bye! 👋🏻" puts "Bye! 👋🏻"
exit(0) exit(0)
# if puts empty, retry prompt
elsif password_string.to_s.size == 0 elsif password_string.to_s.size == 0
puts puts
# if ':h' to view help
elsif password_string.to_s == ":h" elsif password_string.to_s == ":h"
puts "Help:\n-----" puts "Help:\n-----"
puts ":s - Return stats" puts ":s - Return stats"
# if ':s' to view Statistics
elsif password_string.to_s == ":s" elsif password_string.to_s == ":s"
puts "Statictics:\n----------" puts "Statistics:\n----------"
print "Elements: ".colorize(:yellow) print "Elements: ".colorize(:yellow)
puts new_array.size puts new_array.size
@ -103,6 +114,7 @@ while loop
end end
puts outdated_count puts outdated_count
# list search password
else else
new_array.each do |item| new_array.each do |item|
if item.url.includes?(password_string.to_s) if item.url.includes?(password_string.to_s)