Compare commits
No commits in common. "7f789daefa6bfec78a23e3ec21e3f2dd140d4fd9" and "63c0bbbb1c9d0685761056c71a834c910816420c" have entirely different histories.
7f789daefa
...
63c0bbbb1c
8 changed files with 15 additions and 77 deletions
56
src/cli.cr
56
src/cli.cr
|
@ -38,11 +38,6 @@ module GX
|
|||
@config.verbose = true
|
||||
end
|
||||
|
||||
parser.on("-o", "--open", "Automatically open directory after mount") do |flag|
|
||||
Log.info { "Auto-open enabled" }
|
||||
@config.auto_open = true
|
||||
end
|
||||
|
||||
parser.on("--version", "Show version") do |flag|
|
||||
@config.mode = Config::Mode::ShowVersion
|
||||
end
|
||||
|
@ -98,56 +93,10 @@ module GX
|
|||
when Config::Mode::Mount
|
||||
@config.load_from_file
|
||||
filesystem = choose_filesystem
|
||||
raise Models::InvalidFilesystemError.new("Invalid filesystem") if filesystem.nil?
|
||||
|
||||
mount_or_umount(filesystem)
|
||||
auto_open(filesystem) if @config.auto_open
|
||||
mount_or_umount(filesystem) if !filesystem.nil?
|
||||
end
|
||||
end
|
||||
|
||||
def auto_open(filesystem)
|
||||
# FIXME: support xdg-open
|
||||
# FIXME: support mailcap
|
||||
# FIXME: support user-defined command
|
||||
# FIXME: detect graphical environment
|
||||
|
||||
mount_point_safe = filesystem.mount_point
|
||||
raise Models::InvalidMountpointError.new("Invalid filesystem") if mount_point_safe.nil?
|
||||
|
||||
if graphical_environment?
|
||||
process = Process.new(
|
||||
"xdg-open", ## FIXME: make configurable
|
||||
[mount_point_safe],
|
||||
input: STDIN,
|
||||
output: STDOUT,
|
||||
error: STDERR
|
||||
)
|
||||
unless process.wait.success?
|
||||
puts "Error opening filesystem".colorize(:red)
|
||||
return
|
||||
end
|
||||
else
|
||||
process = Process.new(
|
||||
"vifm", ## FIXME: make configurable
|
||||
[mount_point_safe],
|
||||
input: STDIN,
|
||||
output: STDOUT,
|
||||
error: STDERR
|
||||
)
|
||||
unless process.wait.success?
|
||||
puts "Error opening filesystem".colorize(:red)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def graphical_environment?
|
||||
if ENV["DISPLAY"]? || ENV["WAYLAND_DISPLAY"]?
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def choose_filesystem()
|
||||
names_display = {} of String => NamedTuple(filesystem: Models::AbstractFilesystemConfig, ansi_name: String)
|
||||
|
||||
|
@ -185,6 +134,9 @@ module GX
|
|||
end
|
||||
|
||||
def mount_or_umount(selected_filesystem)
|
||||
config_root_safe = @config.root
|
||||
return if config_root_safe.nil?
|
||||
|
||||
if !selected_filesystem.mounted?
|
||||
selected_filesystem.mount()
|
||||
else
|
||||
|
|
|
@ -11,9 +11,6 @@ module GX
|
|||
class Config
|
||||
Log = ::Log.for("config")
|
||||
|
||||
class MissingFileError < Exception
|
||||
end
|
||||
|
||||
enum Mode
|
||||
ConfigAdd
|
||||
ConfigDelete
|
||||
|
@ -34,15 +31,14 @@ module GX
|
|||
property mode : Mode
|
||||
property path : String?
|
||||
property args : AddArgs.class | DelArgs.class | NoArgs.class
|
||||
property auto_open : Bool
|
||||
|
||||
def initialize()
|
||||
raise Models::InvalidEnvironmentError.new("Home directory not found") if !ENV["HOME"]?
|
||||
if !ENV["HOME"]?
|
||||
raise "Home directory not found"
|
||||
end
|
||||
@home_dir = ENV["HOME"]
|
||||
|
||||
@verbose = false
|
||||
@auto_open = false
|
||||
|
||||
@mode = Mode::Mount
|
||||
@filesystems = [] of Models::AbstractFilesystemConfig
|
||||
@path = nil
|
||||
|
@ -70,7 +66,7 @@ module GX
|
|||
end
|
||||
|
||||
Log.error { "No configuration file found in any of the standard locations" }
|
||||
raise MissingFileError.new("Configuration file not found")
|
||||
raise "Configuration file not found"
|
||||
end
|
||||
|
||||
def load_from_file
|
||||
|
@ -91,7 +87,7 @@ module GX
|
|||
root = Models::RootConfig.from_yaml(file_patched)
|
||||
|
||||
global_mount_point = root.global.mount_point
|
||||
raise Models::InvalidMountpointError.new("Invalid global mount point") if global_mount_point.nil?
|
||||
raise "Invalid global mount point" if global_mount_point.nil?
|
||||
|
||||
root.filesystems.each do |selected_filesystem|
|
||||
if !selected_filesystem.mount_point?
|
||||
|
|
|
@ -6,12 +6,6 @@
|
|||
require "yaml"
|
||||
|
||||
module GX::Models
|
||||
class InvalidFilesystemError < Exception
|
||||
end
|
||||
|
||||
class InvalidMountpointError < Exception
|
||||
end
|
||||
|
||||
abstract class AbstractFilesystemConfig
|
||||
include YAML::Serializable
|
||||
# include YAML::Serializable::Strict
|
||||
|
|
|
@ -3,14 +3,14 @@ module GX::Models::Concerns
|
|||
module Base
|
||||
def mounted?() : Bool
|
||||
mount_point_safe = @mount_point
|
||||
raise InvalidMountpointError.new("Invalid mountpoint value") if mount_point_safe.nil?
|
||||
raise "Invalid mountpoint value" if mount_point_safe.nil?
|
||||
|
||||
`mount`.includes?(" on #{mount_point_safe} type ")
|
||||
end
|
||||
|
||||
def umount() : Nil
|
||||
mount_point_safe = @mount_point
|
||||
raise InvalidMountpointError.new("Invalid mountpoint value") if mount_point_safe.nil?
|
||||
raise "Invalid mountpoint value" if mount_point_safe.nil?
|
||||
|
||||
system("fusermount -u #{mount_point_safe.shellescape}")
|
||||
fusermount_status = $?
|
||||
|
|
|
@ -7,9 +7,6 @@ require "yaml"
|
|||
require "./abstract_filesystem_config"
|
||||
|
||||
module GX::Models
|
||||
class InvalidEnvironmentError < Exception
|
||||
end
|
||||
|
||||
class GlobalConfig
|
||||
include YAML::Serializable
|
||||
include YAML::Serializable::Strict
|
||||
|
@ -18,8 +15,7 @@ module GX::Models
|
|||
getter mount_point : String?
|
||||
|
||||
def after_initialize()
|
||||
raise InvalidEnvironmentError.new("Home directory not found") if !ENV["HOME"]?
|
||||
home_dir = ENV["HOME"]
|
||||
home_dir = ENV["HOME"] || raise "Home directory not found"
|
||||
|
||||
# Set default mountpoint from global if none defined
|
||||
if @mount_point.nil? || @mount_point.try &.empty?
|
||||
|
|
|
@ -23,7 +23,7 @@ module GX::Models
|
|||
|
||||
def _mount_action()
|
||||
mount_point_safe = @mount_point
|
||||
raise InvalidMountpointError.new("Invalid mount point") if mount_point_safe.nil?
|
||||
raise "Invalid mount point" if mount_point_safe.nil?
|
||||
|
||||
process = Process.new(
|
||||
"gocryptfs",
|
||||
|
|
|
@ -23,7 +23,7 @@ module GX::Models
|
|||
|
||||
def _mount_action()
|
||||
mount_point_safe = @mount_point
|
||||
raise InvalidMountpointError.new("Invalid mount point") if mount_point_safe.nil?
|
||||
raise "Invalid mount point" if mount_point_safe.nil?
|
||||
|
||||
process = Process.new(
|
||||
"httpdirfs",
|
||||
|
|
|
@ -26,7 +26,7 @@ module GX::Models
|
|||
|
||||
def _mount_action()
|
||||
mount_point_safe = @mount_point
|
||||
raise InvalidMountpointError.new("Invalid mount point") if mount_point_safe.nil?
|
||||
raise "Invalid mount point" if mount_point_safe.nil?
|
||||
|
||||
process = Process.new(
|
||||
"sshfs",
|
||||
|
|
Loading…
Add table
Reference in a new issue