Skip to content

Commit

Permalink
standardize config file location (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dohliam committed Mar 17, 2015
1 parent 01e8621 commit 8f77596
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ Alternatively, you can just point the gdcl.rb script at any folder containing _u
#### gdcl.rb
The script for actually searching through the dictionary is called **gdcl.rb**.

There are a number of configuration options available in the `config.yml` file. By default, this file should be installed in the standard config folder under the user's home directory (i.e., in the folder `~/.config/gdcl`). If gdcl can't find the file `config.yml` in that folder, it will look for it in the current working directory (i.e., wherever you have called the script from).
There are a number of configuration options available in the `config.yml` file. By default, this file should be installed in the standard config folder under the user's home directory (i.e., in the folder `~/.config/gdcl`). If gdcl can't find the file `config.yml` in that folder, it will look for it in $XDG_CONFIG_DIRS (i.e., `/etc/xdg/gdcl`), and failing that, the script folder (i.e., the same directory as the script executable).

If you have a copy of `config.yml` in your xdg config directory or somewhere else (e.g., if you installed gdcl through a package manager), you should avoid editing that file as it will be overwritten when upgrading the package. Instead, you should make changes to a separate configuration file in your home directory (`~/.config/gdcl/config.yml`) which will take precedence over files in other locations. The `~/.config/gdcl` folder and default `config.yml` file will be created if they do not already exist when you first run gdcl.

The options available in config.yml are commented and should be self-explanatory. They are listed below for reference:

Expand Down
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@

# dsl markup options
# remove markup (i.e. all text between "[]" tags); default is to remove markup
:markup: /\[.*?\]/ # remove dsl markup
:markup: '\[.*?\]' # remove dsl markup
# :markup: "" # example: uncomment to allow dsl markup in entries
:markup_replace: = ""
:markup_replace: ""
15 changes: 12 additions & 3 deletions gdcl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@
########################

require 'yaml'
require 'fileutils'

config_dir = Dir.home + "/.config/gdcl/"
xdg = "/etc/xdg/gdcl/"
script_dir = File.expand_path(File.dirname(__FILE__)) + "/"

# read config file from default directory or cwd, otherwise quit
if File.exist?(config_dir + "config.yml")
config = YAML::load(File.read(config_dir + "config.yml"))
elsif File.exist?("config.yml")
config = YAML::load(File.read("config.yml"))
elsif File.exist?(xdg + "config.yml")
config = YAML::load(File.read(xdg + "config.yml"))
FileUtils.mkdir_p config_dir
FileUtils.cp xdg + "config.yml", config_dir
elsif File.exist?(script_dir + "config.yml")
config = YAML::load(File.read(script_dir + "config.yml"))
FileUtils.mkdir_p config_dir
FileUtils.cp script_dir + "config.yml", config_dir
else
abort(" No configuration file found. Please make sure config.yml is located
either in the config folder under your home directory (i.e.,
Expand All @@ -35,7 +44,7 @@
temp_dir = config[:temp_dir].gsub(/^~/, Dir.home)
search_term = config[:search_term]
del_dict = config[:del_dict]
markup = config[:markup]
markup = /#{config[:markup]}/
markup_replace = config[:markup_replace]


Expand Down

0 comments on commit 8f77596

Please sign in to comment.