Merge pull request #83 from oh-my-fish/faster-loading

Faster loading
This commit is contained in:
Bruno 2015-10-02 21:37:54 +01:00
commit a1243f659f
6 changed files with 51 additions and 15 deletions

View File

@ -41,16 +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
source $path/(basename $path).fish ^/dev/null require $name
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

View File

@ -1,16 +1,21 @@
# 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
if test -d "$path"
set -l dest fish_function_path set -l dest fish_function_path
if test -d "$path"
set path_exist
if test (basename "$path") = completions if test (basename "$path") = completions
set dest fish_complete_path set dest fish_complete_path
end end
@ -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

View File

@ -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

26
lib/require.fish Normal file
View 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

3
pkg/omf/init.fish Normal file
View File

@ -0,0 +1,3 @@
function init -a path --on-event init_omf
autoload $path/cli $path/util
end

View File

@ -29,10 +29,6 @@ function omf::off
set_color normal set_color normal
end end
function init -a path --on-event init_omf
autoload $path/cli $path/util
end
function omf -d "Oh My Fish" function omf -d "Oh My Fish"
if test (count $argv) -eq 0 if test (count $argv) -eq 0
omf.help "main"; and return 0 omf.help "main"; and return 0