2016-06-01 12:09:38 +08:00
|
|
|
function require
|
|
|
|
set packages $argv
|
2015-11-02 08:03:56 +08:00
|
|
|
|
2016-06-01 12:09:38 +08:00
|
|
|
if test -z "$packages"
|
|
|
|
echo 'usage: require <name>...'
|
|
|
|
echo ' require --path <path>...'
|
|
|
|
echo ' require --no-bundle --path <path>...'
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# If bundle should be
|
|
|
|
if set index (contains -i -- --no-bundle $packages)
|
|
|
|
set -e packages[$index]
|
|
|
|
set ignore_bundle
|
2015-09-27 07:15:18 +08:00
|
|
|
end
|
2015-10-15 08:49:12 +08:00
|
|
|
|
2016-06-01 12:09:38 +08:00
|
|
|
# Requiring absolute paths
|
|
|
|
if set index (contains -i -- --path $packages)
|
|
|
|
set -e packages[$index]
|
|
|
|
set package_path $packages
|
|
|
|
|
|
|
|
# Requiring specific packages from default paths
|
|
|
|
else
|
|
|
|
set package_path {$OMF_PATH,$OMF_CONFIG}/pkg*/$packages
|
|
|
|
|
|
|
|
# Exit with error if no package paths were generated
|
|
|
|
test -z "$package_path"
|
|
|
|
and return 1
|
|
|
|
end
|
|
|
|
|
|
|
|
set function_path $package_path/functions*
|
2016-06-08 08:27:14 +08:00
|
|
|
set complete_path $package_path/completions*
|
2016-06-01 12:09:38 +08:00
|
|
|
set init_path $package_path/init.fish*
|
2018-11-19 11:41:36 +08:00
|
|
|
set conf_path $package_path/conf.d/*.fish
|
2016-06-01 12:09:38 +08:00
|
|
|
|
|
|
|
# Autoload functions
|
|
|
|
test -n "$function_path"
|
|
|
|
and set fish_function_path $fish_function_path[1] \
|
|
|
|
$function_path \
|
|
|
|
$fish_function_path[2..-1]
|
|
|
|
|
|
|
|
# Autoload completions
|
|
|
|
test -n "$complete_path"
|
|
|
|
and set fish_complete_path $fish_complete_path[1] \
|
|
|
|
$complete_path \
|
|
|
|
$fish_complete_path[2..-1]
|
|
|
|
|
|
|
|
for init in $init_path
|
|
|
|
emit perf:timer:start $init
|
|
|
|
set -l IFS '/'
|
|
|
|
echo $init | read -la components
|
|
|
|
|
|
|
|
set path (printf '/%s' $components[1..-2])
|
|
|
|
|
|
|
|
contains $path $omf_init_path
|
|
|
|
and continue
|
|
|
|
|
|
|
|
set package $components[-2]
|
|
|
|
|
|
|
|
if not set -q ignore_bundle
|
|
|
|
set bundle $path/bundle
|
|
|
|
set dependencies
|
|
|
|
|
|
|
|
if test -f $bundle
|
|
|
|
set -l IFS ' '
|
|
|
|
while read -l type dependency
|
|
|
|
test "$type" != package
|
|
|
|
and continue
|
|
|
|
require "$dependency"
|
|
|
|
set dependencies $dependencies $dependency
|
|
|
|
end < $bundle
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
source $init $path
|
2018-11-19 11:41:36 +08:00
|
|
|
|
2016-06-01 12:09:38 +08:00
|
|
|
emit init_$package $path
|
|
|
|
|
|
|
|
set -g omf_init_path $omf_init_path $path
|
|
|
|
emit perf:timer:finish $init
|
|
|
|
end
|
2015-10-15 08:49:12 +08:00
|
|
|
|
2019-01-11 05:57:14 +08:00
|
|
|
for conf in $conf_path
|
|
|
|
source $conf
|
|
|
|
end
|
|
|
|
|
2015-10-15 08:49:12 +08:00
|
|
|
return 0
|
2015-09-27 07:15:18 +08:00
|
|
|
end
|