Commit 30ab0544 authored by Bruno Pinto's avatar Bruno Pinto

Add `require` function to support plugin dep

In order to support dependency between plugins a function called
`require` has been added.
parent ceb31c14
...@@ -41,20 +41,20 @@ source $OMF_CONFIG/before.init.fish ^/dev/null ...@@ -41,20 +41,20 @@ source $OMF_CONFIG/before.init.fish ^/dev/null
set -l user_function_path $fish_function_path[1] set -l user_function_path $fish_function_path[1]
set fish_function_path[1] $OMF_PATH/lib set fish_function_path[1] $OMF_PATH/lib
set -l theme {$OMF_PATH,$OMF_CONFIG}/themes/(cat $OMF_CONFIG/theme) # Autoload util functions
autoload $OMF_PATH/lib $OMF_PATH/lib/git
for path in $OMF_PATH/lib $OMF_PATH/lib/git {$OMF_PATH,$OMF_CONFIG}/pkg/* $theme for path in {$OMF_PATH,$OMF_CONFIG}/pkg/*
contains -- (basename $path) $OMF_IGNORE; and continue set -l name (basename $path)
autoload $path $path/completions contains -- $name $OMF_IGNORE; and continue
require $name
if source $path/init.fish ^/dev/null
else
source $path/(basename $path).fish ^/dev/null;
#and echo "Plugin '"(basename $path)"' has a deprecated structure. Run `omf update`."
end; and emit init_(basename $path) $path
end end
# Autoload theme
autoload {$OMF_PATH,$OMF_CONFIG}/themes/(cat $OMF_CONFIG/theme)
# Autoload custom functions
autoload $OMF_CONFIG/functions autoload $OMF_CONFIG/functions
autoload $user_function_path autoload $user_function_path
......
# SYNOPSIS # SYNOPSIS
# autoload <path [path...]> # autoload <path>...
# #
# OVERVIEW # OVERVIEW
# Autoload a function or completion path. Add the specified list of # Autoload a function or completion path. Add the specified list of
# directories to $fish_function_path. Any `completions` directories # directories to $fish_function_path. Any `completions` directories
# are correctly added to the $fish_complete_path. # are correctly added to the $fish_complete_path.
#
# Returns 0 if one of the paths exist.
# Returns != 0 if all paths are missing.
function autoload -d "autoload a function or completion path" function autoload -d "autoload a function or completion path"
for path in $argv for path in $argv
set -l dest fish_function_path
if test -d "$path" if test -d "$path"
set -l dest fish_function_path set path_exist
if test (basename "$path") = completions if test (basename "$path") = completions
set dest fish_complete_path set dest fish_complete_path
...@@ -18,4 +23,6 @@ function autoload -d "autoload a function or completion path" ...@@ -18,4 +23,6 @@ function autoload -d "autoload a function or completion path"
contains "$path" $$dest; or set $dest "$path" $$dest contains "$path" $$dest; or set $dest "$path" $$dest
end end
end end
set -q path_exist
end end
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
# available [name] # available [name]
# #
# OVERVIEW # OVERVIEW
# Check if a program is available. # Check if a function or program is available.
function available -a program -d "check if a program is available." function available -a name -d "Check if a function or program is available."
type "$program" ^/dev/null >&2 type "$name" ^/dev/null >&2
end end
# SYNOPSIS
# require [name]
#
# OVERVIEW
# Require a plugin:
# - Autoload its functions and completions.
# - Source its initialization file.
# - Emit its initialization event.
#
# If the required plugin has already been loaded, does nothing.
function require -a name
# Skip if plugin has already been loaded.
contains -- $OMF_PATH/pkg/$name $fish_function_path;
or contains -- $OMF_CONFIG/pkg/$name $fish_function_path;
and return 0
for path in {$OMF_PATH,$OMF_CONFIG}/pkg/$name
if autoload $path $path/completions
source $path/init.fish ^/dev/null;
or source $path/$name.fish ^/dev/null;
and emit init_$name $path
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment