mirror of
https://github.com/oh-my-fish/oh-my-fish.git
synced 2025-03-31 05:25:12 +08:00
Add require
function to support plugin dep
In order to support dependency between plugins a function called `require` has been added.
This commit is contained in:
parent
ceb31c143a
commit
30ab05445d
20
init.fish
20
init.fish
@ -41,20 +41,20 @@ source $OMF_CONFIG/before.init.fish ^/dev/null
|
||||
set -l user_function_path $fish_function_path[1]
|
||||
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
|
||||
contains -- (basename $path) $OMF_IGNORE; and continue
|
||||
for path in {$OMF_PATH,$OMF_CONFIG}/pkg/*
|
||||
set -l name (basename $path)
|
||||
|
||||
autoload $path $path/completions
|
||||
|
||||
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
|
||||
contains -- $name $OMF_IGNORE; and continue
|
||||
require $name
|
||||
end
|
||||
|
||||
# Autoload theme
|
||||
autoload {$OMF_PATH,$OMF_CONFIG}/themes/(cat $OMF_CONFIG/theme)
|
||||
|
||||
# Autoload custom functions
|
||||
autoload $OMF_CONFIG/functions
|
||||
autoload $user_function_path
|
||||
|
||||
|
@ -1,15 +1,20 @@
|
||||
# SYNOPSIS
|
||||
# autoload <path [path...]>
|
||||
# autoload <path>...
|
||||
#
|
||||
# OVERVIEW
|
||||
# Autoload a function or completion path. Add the specified list of
|
||||
# directories to $fish_function_path. Any `completions` directories
|
||||
# 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"
|
||||
for path in $argv
|
||||
set -l dest fish_function_path
|
||||
|
||||
if test -d "$path"
|
||||
set -l dest fish_function_path
|
||||
set path_exist
|
||||
|
||||
if test (basename "$path") = completions
|
||||
set dest fish_complete_path
|
||||
@ -18,4 +23,6 @@ function autoload -d "autoload a function or completion path"
|
||||
contains "$path" $$dest; or set $dest "$path" $$dest
|
||||
end
|
||||
end
|
||||
|
||||
set -q path_exist
|
||||
end
|
||||
|
@ -2,8 +2,8 @@
|
||||
# available [name]
|
||||
#
|
||||
# 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."
|
||||
type "$program" ^/dev/null >&2
|
||||
function available -a name -d "Check if a function or program is available."
|
||||
type "$name" ^/dev/null >&2
|
||||
end
|
||||
|
26
lib/require.fish
Normal file
26
lib/require.fish
Normal file
@ -0,0 +1,26 @@
|
||||
# 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
|
Loading…
x
Reference in New Issue
Block a user