Skip to content

Commit

Permalink
Fixed crash when XDG_CONFIG_HOME isn't set
Browse files Browse the repository at this point in the history
  • Loading branch information
jo1gi committed May 4, 2021
1 parent 344baea commit 4896d7e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/config.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "yaml"
require "mime"
require "colorize"

module Config
extend self
Expand All @@ -13,13 +14,11 @@ module Config

# Returns the path of the default config file
def find_config : String
dirs = ["#{ENV["XDG_CONFIG_HOME"]}/openurl", "~/.config/openurl"]
dirs.each do |dir|
path = "#{dir}/config.yaml"
if File.exists?(path)
return path
end
config_dir = ENV["XDG_CONFIG_HOME"]? || "#{ENV["HOME"]?}/.config"
path = "#{config_dir}/openurl/config.yaml"
if File.exists?(path)
return path
end
abort "Could not find config file"
abort "Could not find config file\nThe config should be placed: #{path.colorize(:blue)}"
end
end
2 changes: 1 addition & 1 deletion src/rules.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Rules
"domain" => /(?<=:\/\/)[^\/]+/,
"last_file" => /[^\/]+$/,
"filetype" => /(?<=\.)[^\.\/]+$/,
"url" => /./,
"url" => /.+/,
}

# Tests a url on a specific regex parameter from `tests`
Expand Down

0 comments on commit 4896d7e

Please sign in to comment.