summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2018-12-26 15:04:34 +0000
committerPaul Buetow <paul@buetow.org>2018-12-26 15:04:34 +0000
commit843070e0e6ab0de4a4cd6b14a465e283545d7801 (patch)
treefced184d0c8afee0ac525ccb14d19e5a5bc83ec8
parent030e014769f6423f901f33f23a3e949b76aa3e42 (diff)
parentc19cd48231e452c6197dd1128c42f82cdd2acfa0 (diff)
merge
-rwxr-xr-xgeheim.rb26
1 files changed, 14 insertions, 12 deletions
diff --git a/geheim.rb b/geheim.rb
index 3a023a2..4b71bd4 100755
--- a/geheim.rb
+++ b/geheim.rb
@@ -74,7 +74,7 @@ module Encryption
input = ENV['PIN']
else
print "PIN: "
- input = $stdin.gets.chomp
+ input = STDIN.noecho(&:gets).chomp
end
iv = input * 2 + "Hello world" + input * 2
@@iv = iv[0..15]
@@ -182,9 +182,9 @@ class GeheimData < CommitFile
end
end
- def import(source_file:)
- puts "Importing #{source_file} to #{@data_path}"
- @data = File.read(source_file)
+ def reimport_after_export
+ @data = File.read(@exported_path)
+ commit(force: true)
end
def commit(force: false)
@@ -287,11 +287,14 @@ class Geheim
Dir.glob("#{directory}/**/*").each do |source_file|
next if File.directory?(source_file)
file = source_file.sub("#{directory}/", "")
- add(description: file, file: source_file, dest_dir: dest_dir)
+ add(description: file, action: :import, file: source_file, dest_dir: dest_dir)
end
end
- def add(description: nil, file: nil, dest_dir: nil, force: false)
+ def add(description: nil, action: :newtxt, file: nil, dest_dir: nil, force: false)
+ if action == :newtxt
+ file = external_edit(file: File.basename(description))
+ end
src_path = file.gsub("//", "/")
dest_path = if dest_dir.nil?
@@ -306,15 +309,14 @@ class Geheim
hash = hash_path(dest_path)
- if file.nil?
- print "Data: "
- data = $stdin.gets.chomp
- elsif !File.exists?(src_path)
+ if !File.exists?(src_path)
+ # Assume import
puts "ERROR: #{file} does not exist!"
exit(3)
else
puts "Importing #{src_path} -> #{dest_path}"
data = File.read(src_path)
+ shred_file(file: src_path) if action == :newtxt
end
description = dest_path if description.nil?
@@ -377,7 +379,7 @@ class Geheim
file_path
end
- private def edit_exported(file:)
+ private def external_edit(file:)
file_path = "#{$export_dir}/#{file}"
edit_cmd= "#{$edit_cmd} #{file_path}"
puts edit_cmd
@@ -453,7 +455,7 @@ class CLI
when 'add'
geheim.add(description: argv[1])
when 'import'
- geheim.add(file: argv[1], dest_dir: argv[2], force: !argv[3].nil?)
+ geheim.add(file: argv[1], action: :import, dest_dir: argv[2], force: !argv[3].nil?)
when 'import_r'
geheim.import_recursive(directory: argv[1], dest_dir: argv[2])
when 'rm'