fix: rename to mfm and fix close

This commit is contained in:
Glenn Y. Rolland 2023-10-24 12:50:01 +02:00
parent 8def1979c1
commit 294231cfbb
3 changed files with 53 additions and 38 deletions

View file

@ -1,8 +1,9 @@
name: gx-vault
---
name: Minimalist FUSE Manager
version: 0.1.0
targets:
gx-vault:
mfm:
main: src/main.cr
# authors:
@ -11,6 +12,10 @@ targets:
# description: |
# Short description of gx-vault
dependencies:
shellwords:
github: szTheory/shellwords-crystal
# dependencies:
# pg:
# github: will/crystal-pg

View file

@ -66,19 +66,26 @@ module GX
def run()
@config.load_from_file
# Correcting the fzf interaction part
names_display = @config.vaults.map do |vault|
vault.mounted? ? "#{vault.name} [#{ "open".colorize(:green) }]" : vault.name
names_display = {} of String => NamedTuple(vault: Vault, ansi_name: String)
@config.vaults.each do |vault|
result_name = vault.mounted? ? "#{vault.name} [open]" : vault.name
ansi_name = vault.mounted? ? "#{vault.name} [#{ "open".colorize(:green) }]" : vault.name
names_display[result_name] = {
vault: vault,
ansi_name: ansi_name
}
end
selected_vault_name = Fzf.run(names_display.sort)
puts ">> #{selected_vault_name}".colorize(:yellow)
selected_vault = @config.vaults.find { |v| v.name == selected_vault_name }
result_vault_name = Fzf.run(names_display.values.map(&.[:ansi_name]).sort)
selected_vault = names_display[result_vault_name][:vault]
puts ">> #{selected_vault.name}".colorize(:yellow)
if selected_vault
selected_vault.mounted? ? selected_vault.unmount : selected_vault.mount
else
STDERR.puts "Vault not found.".colorize(:red)
STDERR.puts "Vault not found: #{selected_vault}.".colorize(:red)
end
end

View file

@ -1,38 +1,41 @@
require "shellwords"
module GX
class Vault
getter name : String
getter encrypted_path : String
getter mount_dir : String
class Vault
getter name : String
getter encrypted_path : String
getter mount_dir : String
def initialize(@name, @encrypted_path, mount_name : String)
home_dir = ENV["HOME"] || raise "Home directory not found"
@mount_dir = File.join(home_dir, "mnt/#{mount_name}")
end
def initialize(@name, @encrypted_path, mount_name : String)
home_dir = ENV["HOME"] || raise "Home directory not found"
@mount_dir = File.join(home_dir, "mnt/#{mount_name}")
end
def mounted? : Bool
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
end
def mounted? : Bool
`mount`.includes?("#{encrypted_path} on #{mount_dir}")
end
def mount
Dir.mkdir_p(mount_dir) unless Dir.exists?(mount_dir)
def mount
Dir.mkdir_p(mount_dir) unless Dir.exists?(mount_dir)
if mounted?
puts "Already mounted. Skipping.".colorize(:yellow)
else
input = STDIN
output = STDOUT
error = STDERR
process = Process.new("gocryptfs", ["-idle", "15m", encrypted_path, mount_dir], input: input, output: output, error: error)
unless process.wait.success?
puts "Error mounting the vault".colorize(:red)
return
if mounted?
puts "Already mounted. Skipping.".colorize(:yellow)
else
input = STDIN
output = STDOUT
error = STDERR
process = Process.new("gocryptfs", ["-idle", "15m", encrypted_path, mount_dir], input: input, output: output, error: error)
unless process.wait.success?
puts "Error mounting the vault".colorize(:red)
return
end
puts "Vault #{name} is now available on #{mount_dir}".colorize(:green)
end
puts "Vault #{name} is now available on #{mount_dir}".colorize(:green)
end
def unmount
system("fusermount -u #{mount_dir.shellescape}")
puts "Vault #{name} is now closed.".colorize(:green)
end
end
def unmount
`fusermount -u #{mount_dir}`
puts "Vault #{name} is now closed.".colorize(:green)
end
end
end