sfeed_opml_export: sync loadconfig() function fixes from sfeed_update

- Do not show stderr of readlink.
- Show the reference to the example sfeedrc (like sfeed_update).
- Make the error message a bit shorter.
- Fix showing the path if it does not exist, for example:

	$ sfeed_opml_export "a"
	readlink: a: No such file or directory
	Configuration file "" does not exist or is not readable.

Now shows:

	$ sfeed_opml_export "a"
	Configuration file "a" cannot be read.
	See sfeedrc.example for an example.
This commit is contained in:
Hiltjo Posthuma 2021-05-29 15:14:33 +02:00
parent 02b590f6a2
commit b723fbcd98
1 changed files with 10 additions and 8 deletions

View File

@ -4,20 +4,22 @@
# loadconfig(configfile)
loadconfig() {
# allow to specify config via argv[1].
if [ ! x"$1" = x"" ]; then
# get absolute path of config file.
config=$(readlink -f "$1")
if [ "$1" != "" ]; then
# get absolute path of config file required for including.
config="$1"
path=$(readlink -f "${config}" 2>/dev/null)
else
# default config location.
config="$HOME/.sfeed/sfeedrc"
path="${config}"
fi
# load config: config is loaded here to be able to override above variables
# (sfeedpath, sfeedfile, etc).
if [ -r "$config" ]; then
. "$config"
# config is loaded here to be able to override $sfeedpath or functions.
if [ -r "${path}" ]; then
. "${path}"
else
echo "Configuration file \"$config\" does not exist or is not readable." >&2
echo "Configuration file \"${config}\" cannot be read." >&2
echo "See sfeedrc.example for an example." >&2
exit 1
fi
}