Commit 5eb156f9 authored by Jorge Bucaran's avatar Jorge Bucaran

Fix bugs in new import command as discussed in oh-my-fish/pull/291

+ All `.load` files inside custom are sourced as usual.

+ Only set plugins set in `$fish_plugins` as imported. Works whether they are in `$fish_path` or `$fish_custom` as expected. The same for plugins.

+ `$fish_function_path` is not polluted.
parent dbab48f3
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
# _prepend_tree - add a dependency tree to fish_function_path # _prepend_tree - add a dependency tree to fish_function_path
# #
# SYNOPSIS # SYNOPSIS
# _prepend_tree [-p --preview] <path> [<glob>..] # _prepend_tree [-v --verbose] <path> [<glob>..]
# #
# DESCRIPTION # DESCRIPTION
# Search a path tree and prepend directories with fish files # Search a path tree and prepend directories with fish files. Use a glob
# printing any matches by default. Use a glob list to include # list to include or exclude other file extensions. Use -v --verbose to
# or exclude other file extensions. Use -p --preview to just # output directories to be added to the path.
# print matches withouth modifying the path.
# #
# OPTIONS # OPTIONS
# [-p --preview] # [-v --verbose]
# Do not modify the path. Print directories that match the glob. # Optional. Print directories that match the glob. Must be the
# first argument if used.
# #
# <path> # <path>
# Required. Specify the path to search for glob patterns. # Required. Specify the path to search for glob patterns.
...@@ -46,15 +46,21 @@ ...@@ -46,15 +46,21 @@
# SEE ALSO # SEE ALSO
# .oh-my-fish/functions/_prepend_path.fish # .oh-my-fish/functions/_prepend_path.fish
# #
# v.0.2.1 # v.0.2.0
#/ #/
function _prepend_tree -d "Add a dependency tree to the Fish path." function _prepend_tree -d "Add a dependency tree to the Fish path."
# Match directories with .fish files always. # Match directories with .fish files always.
set -l glob -name \*.fish set -l glob -name \*.fish
set -l verbose ""
# Retrieve first argument, either the path or the -v option.
set -l path $argv[1] set -l path $argv[1]
if contains -- $path -p --preview if contains -- $path -v --verbose
set verbose -v
# Option first, path should be next.
set path $argv[2] set path $argv[2]
end end
# Parse glob options to create the main glob pattern. # Parse glob options to create the main glob pattern.
if [ (count $argv) -gt 2 ] if [ (count $argv) -gt 2 ]
set -l operator -o set -l operator -o
...@@ -82,16 +88,22 @@ function _prepend_tree -d "Add a dependency tree to the Fish path." ...@@ -82,16 +88,22 @@ function _prepend_tree -d "Add a dependency tree to the Fish path."
# $subs will become an empty list for directories without sub directories # $subs will become an empty list for directories without sub directories
# which is safe to use in the loop. # which is safe to use in the loop.
set -l subs $path/**/ set -l subs $path/**/
# Traverse $path and $subs prepending only directories with matches. # Traverse $path and $subs prepending only directories with matches.
for dir in $path $subs for dir in $path $subs
# Use head to retrieve at least the first match. # Use head to retrieve at least one match. Ignore errors for non
if [ -z (find $dir $glob -maxdepth 1 | head -1) ] # existing directories
if [ -z (find "$dir" $glob -maxdepth 1 ^/dev/null | head -1) ]
continue continue
end end
printf "%s" $dir
if not contains -- $argv[1] -p --preview # Print matched directories if the -v option is set.
_prepend_path $dir -d fish_function_path if not [ -z $verbose ]
printf "%s\n" $dir
end end
# Prepend matched directory to the the global fish function path.
# Note path duplicates are already handled by _prepend_path.
_prepend_path $dir -d fish_function_path
end end
end end
...@@ -25,19 +25,23 @@ ...@@ -25,19 +25,23 @@
# functions/_prepend_path.fish # functions/_prepend_path.fish
# functions/_prepend_tree.fish # functions/_prepend_tree.fish
# #
# v.0.2.1 # v.0.1.0
#/ #/
function import -d "Load libraries, plugins, themes, etc." function import -d "Load libraries, plugins, themes, etc."
for library in $argv for library in $argv
# Prepend plugins, themes and completions, traversing library # Prepend plugins, themes and completions, traversing library
# trees and prepending directories with fish code. # trees and prepending directories with fish code.
_prepend_tree $fish_path/$library >/dev/null _prepend_tree $fish_path/$library
_prepend_tree $fish_custom/$library
_prepend_path $fish_path/$library/completions -d fish_complete_path _prepend_path $fish_path/$library/completions -d fish_complete_path
# Set path to load files.
set -l path $library/(basename $library).load
# Source each plugin, theme, etc., configuration load file. # Source each plugin, theme, etc., configuration load file.
for path in $fish_path/$library/(basename $library).load for load in $fish_path/$path $fish_custom/$path
if [ -e $path ] if [ -e $load ]
. $path . $load
end end
end end
end end
......
...@@ -10,24 +10,21 @@ end ...@@ -10,24 +10,21 @@ end
set user_function_path $fish_function_path[1] set user_function_path $fish_function_path[1]
set -e fish_function_path[1] set -e fish_function_path[1]
# Add functions defined in oh-my-fish/functions to path. # Add functions defined in oh-my-fish/functions to the path.
if not contains $fish_path/functions/ $fish_function_path if not contains $fish_path/functions/ $fish_function_path
set fish_function_path $fish_path/functions/ $fish_function_path set fish_function_path $fish_path/functions/ $fish_function_path
end end
# Add required plugins, completions and themes. Imported commands can be # Add imported plugins, completions and themes. Customize imported
# customized via the $fish_path/custom directory. To customize a theme, # commands via the $fish_path/custom directory, for example create
# create a directory under $fish_path/custom/themes with the same name # a directory under $fish_path/custom/themes with the same name as
# as the theme. Use the same approach for plugins, etc. # the theme and override any functions/variables there. Rinse and
import plugins/$fish_plugins themes/$fish_theme # repeat for plugins.
import $fish_plugins themes/$fish_theme
# Prepend all user custom paths to the fish path and source load files. # Source all files inside custom directory.
for custom_file in $fish_custom/** for load in $fish_custom/*.load
_prepend_path $custom_file -d fish_function_path . $load
switch $custom_file
case \*.load
. $custom_file
end
end end
# Prepend extracted user functions so they have the highest priority. # Prepend extracted user functions so they have the highest priority.
......
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