# -*- shell-script -*-

################################################################################

# setup bashrun environment vars
bashrun=0
bashrun_mode=${bashrun_mode:-terminal}
bashrun_debug=${bashrun_debug:-0}
bashrun_feedback=${bashrun_feedback:-0}
bashrun_frontend=${bashrun_frontend:-0}

# setup user environment vars used by bashrun
BROWSER=${BROWSER:-firefox}
PAGER=${PAGER:-less -R}
DICT=${DICT:-dict}

# load xdg basedir utility
source __PREFIX__/share/bashrun2/xdgbase

# setup paths
bashrun_site=__PREFIX__/share/bashrun2
bashrun_config_dirs="$(§xdg config-dirs bashrun2)"
bashrun_config_home="$(§xdg config-home bashrun2)"
bashrun_data_home="$(§xdg data-home bashrun2)"
bashrun_cache_home="$(§xdg cache-home bashrun2)"

# setup rcfile
bashrun_rcfile="$(§xdg -e config bashrun2/bashrun2.rc)"

if [[ -z "$bashrun_rcfile" ]]; then
    source "$bashrun_site/message"

    files="$(§xdg config bashrun2/bashrun2.rc)"
    files="${files//$'\n'/\\n}"

    §message "Error" \
	"Could not find a configuration file at the following locations:

        $files

        Please make sure that either

        - Your XDG_CONFIG_DIRS environment variable contains the
          appropriate path to the xdg directory below which the
          default configuration files have been installed, or that

        - Bashrun has been installed using the default sysconfdir
          prefix as defined by the XDG Base Directory Specification by
          using the configure option '--sysconfdir=/etc'.

        If you have installed bashrun2 by using the package manager of
        your distribution, please consider reporting this as a bug
        to the maintainer of the distribution package.

        See the README file included in the source tarball for details."

    exit 1
fi

# define version info
bashrun_major_version=0
bashrun_minor_version=2
bashrun_bugfix_version=2
bashrun_release_version=""

# create version string
bashrun_version="${bashrun_major_version}.${bashrun_minor_version}.${bashrun_bugfix_version}"
[[ -n "$bashrun_release_version" ]] && bashrun_version="$bashrun_version${bashrun_release_version}"

