aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Gawehn <3gawehn@informatik.uni-hamburg.de>2018-03-14 21:39:49 +0100
committerPhilip Gawehn <3gawehn@informatik.uni-hamburg.de>2018-03-14 21:39:49 +0100
commitb14e1c99ff0e8c9983e9987e234dd3aa9c2e08ec (patch)
tree195c64749d46273b331f806922cded64fd97e3d0
parentb6514f9186740f633871fe546625bb916d6d9d68 (diff)
downloadrofi-pass-b14e1c99ff0e8c9983e9987e234dd3aa9c2e08ec.tar.gz
fixed loading multiple config files to one, see #118
-rw-r--r--README.md12
-rwxr-xr-xrofi-pass34
2 files changed, 29 insertions, 17 deletions
diff --git a/README.md b/README.md
index 607424e..f2bc4f9 100644
--- a/README.md
+++ b/README.md
@@ -77,14 +77,20 @@ in a convenient way using [rofi](https://github.com/DaveDavenport/rofi).
## Configuration
-rofi-pass may read its configuration values from `/etc/rofi-pass.conf` and/or `$HOME/.config/rofi-pass/config`.
-You can also set a configuration by using the environment variable ROFI_PASS_CONFIG (see example below).
-For an example configuration please take a look at the included `config.example` file.
+rofi-pass may read its configuration values from different locations in the following order:
+* `ROFI_PASS_CONFIG` (environment variable)
+* `$HOME/.config/rofi-pass/config`
+* `/etc/rofi-pass.conf`
+rofi-pass only loads the first existing file.
+In case no config file exists, rofi-pass uses its internal default values.
+You can set the environment variable like this:
```
ROFI_PASS_CONFIG="$HOME/path/to/config" rofi-pass
```
+For an example configuration please take a look at the included `config.example` file.
+
## Extras
### addpass
diff --git a/rofi-pass b/rofi-pass
index 180dca5..f08d1bc 100755
--- a/rofi-pass
+++ b/rofi-pass
@@ -710,24 +710,30 @@ Usage:
EOF
}
+get_config_file () {
+ configs=(
+ "$ROFI_PASS_CONFIG"
+ "$HOME/.config/rofi-pass/config"
+ "/etc/rofi-pass.conf"
+ )
+
+ # return the first config file with a valid path
+ for config in "${configs[@]}"; do
+ # '! -z' is needed in case ROFI_PASS_CONFIG is not set
+ if [[ ! -z "${config}" && -f "${config}" ]]; then
+ printf "%s" "$config"
+ return
+ fi
+ done
+}
+
main () {
# enable extended globbing
shopt -s nullglob globstar
- # check if global config exists and load it
- if [[ -f /etc/rofi-pass.conf ]]; then
- source /etc/rofi-pass.conf
- fi
-
- # check if local config exists and load it
- if [[ -f "$HOME/.config/rofi-pass/config" ]]; then
- source "$HOME/.config/rofi-pass/config"
- fi
-
- # check if path to config in environment variable exists and load it
- if [[ -f "$ROFI_PASS_CONFIG" ]]; then
- source "$ROFI_PASS_CONFIG"
- fi
+ # load config file
+ config_file="$(get_config_file)"
+ [[ ! -z "$config_file" ]] && source "$config_file"
# create tmp dir
if [[ ! -d "$HOME/.cache/rofi-pass" ]]; then