diff --git a/src/cli.cr b/src/cli.cr index bb6f941..892ca77 100644 --- a/src/cli.cr +++ b/src/cli.cr @@ -69,8 +69,19 @@ module GX names_display = {} of String => NamedTuple(filesystem: Filesystem, ansi_name: String) @config.filesystems.each do |filesystem| - result_name = filesystem.mounted? ? "#{filesystem.name} [open]" : filesystem.name - ansi_name = filesystem.mounted? ? "#{filesystem.name} [#{ "open".colorize(:green) }]" : filesystem.name + fs_str = filesystem.type.ljust(12,' ') + result_name = + if filesystem.mounted? + "#{fs_str} #{filesystem.name} [open]" + else + "#{fs_str} #{filesystem.name}" + end + ansi_name = + if filesystem.mounted? + "#{fs_str.colorize(:dark_gray)} #{filesystem.name} [#{ "open".colorize(:green) }]" + else + "#{fs_str.colorize(:dark_gray)} #{filesystem.name}" + end names_display[result_name] = { filesystem: filesystem, diff --git a/src/filesystems.cr b/src/filesystems.cr index fb69044..86a2cd6 100644 --- a/src/filesystems.cr +++ b/src/filesystems.cr @@ -1,3 +1,5 @@ require "./filesystems/gocryptfs" +require "./filesystems/sshfs" +require "./filesystems/httpdirfs" require "./filesystems/filesystem" diff --git a/src/filesystems/filesystem.cr b/src/filesystems/filesystem.cr index e99d4fe..0f597e9 100644 --- a/src/filesystems/filesystem.cr +++ b/src/filesystems/filesystem.cr @@ -8,7 +8,8 @@ module GX use_yaml_discriminator "type", { gocryptfs: GoCryptFS, - sshfs: SshFS + sshfs: SshFS, + httpdirfs: HttpDirFS } property type : String diff --git a/src/filesystems/gocryptfs.cr b/src/filesystems/gocryptfs.cr index d28a825..aaa6e8f 100644 --- a/src/filesystems/gocryptfs.cr +++ b/src/filesystems/gocryptfs.cr @@ -13,7 +13,7 @@ module GX def after_initialize() home_dir = ENV["HOME"] || raise "Home directory not found" - @mount_dir = File.join(home_dir, "mnt/#{@name}") + @mount_dir = File.join(home_dir, "mnt/#{@name}.Open") end def mounted? : Bool diff --git a/src/filesystems/httpdirfs.cr b/src/filesystems/httpdirfs.cr new file mode 100644 index 0000000..ff5d230 --- /dev/null +++ b/src/filesystems/httpdirfs.cr @@ -0,0 +1,43 @@ +require "shellwords" +require "./filesystem" + +module GX + class HttpDirFS < Filesystem + getter name : String = "" + getter url : String = "" + + @[YAML::Field(key: "mount_dir", ignore: true)] + getter mount_dir : String = "" + + include GenericFilesystem + + def after_initialize() + home_dir = ENV["HOME"] || raise "Home directory not found" + @mount_dir = File.join(home_dir, "mnt/#{@name}") + end + + def mounted? : Bool + `mount`.includes?("httpdirfs on #{mount_dir}") + end + + def mount + super do + input = STDIN + output = STDOUT + error = STDERR + process = Process.new( + "httpdirfs", + ["#{url}", mount_dir], + input: input, + output: output, + error: error + ) + unless process.wait.success? + puts "Error mounting the filesystem".colorize(:red) + return + end + end + end + end +end +