# -*- shell-script -*-

################################################################################
#
# Load and initialize the bashrun engine.
#
################################################################################

# source global variables
source __PREFIX__/share/bashrun2/globals

# when launched by the frontend, source the user's ~/.bashrc
if (( bashrun_frontend )) && [[ -f "$HOME/.bashrc" ]]; then
    source "$HOME/.bashrc"
fi

# initialize object system
source $bashrun_site/objects
§objects.site $bashrun_site
§objects.cache_home $bashrun_cache_home
§objects.data_home $bashrun_cache_home
§objects.namespace "bashrun2"

# source utilities 
source $bashrun_site/utils
source $bashrun_site/window
source $bashrun_site/registry
source $bashrun_site/message
source $bashrun_site/bootstrap

# register this instance if we're launched by the
# frontend... (needs to happen early on)
(( bashrun_frontend )) && §registry.add

# install cygwin workarounds
if §cygwin?; then
    §winch
    trap §winch WINCH
fi
    
# setup progress bar
source $bashrun_site/progress
§progress.new "Loading... [objects]"

# continue sourcing utilities
source $bashrun_site/config
source $bashrun_site/plugin
source $bashrun_site/remote
source $bashrun_site/command
source $bashrun_site/readline
source $bashrun_site/completion

# source objects
source $bashrun_site/modes
source $bashrun_site/templates
source $bashrun_site/terminals
source $bashrun_site/actions
source $bashrun_site/bindings
source $bashrun_site/handlers
source $bashrun_site/rules
source $bashrun_site/bookmarks

# source and initialize the engine
source $bashrun_site/engine
§engine.init
