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 version: 0.1.0
targets: targets:
gx-vault: mfm:
main: src/main.cr main: src/main.cr
# authors: # authors:
@ -11,6 +12,10 @@ targets:
# description: | # description: |
# Short description of gx-vault # Short description of gx-vault
dependencies:
shellwords:
github: szTheory/shellwords-crystal
# dependencies: # dependencies:
# pg: # pg:
# github: will/crystal-pg # github: will/crystal-pg

View file

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

View file

@ -1,3 +1,5 @@
require "shellwords"
module GX module GX
class Vault class Vault
getter name : String getter name : String
@ -30,8 +32,9 @@ class Vault
puts "Vault #{name} is now available on #{mount_dir}".colorize(:green) puts "Vault #{name} is now available on #{mount_dir}".colorize(:green)
end end
end end
def unmount def unmount
`fusermount -u #{mount_dir}` system("fusermount -u #{mount_dir.shellescape}")
puts "Vault #{name} is now closed.".colorize(:green) puts "Vault #{name} is now closed.".colorize(:green)
end end
end end