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.
pull/2/head
Jorge Bucaran 10 years ago
parent dbab48f307
commit 5eb156f995

@ -2,17 +2,17 @@
# _prepend_tree - add a dependency tree to fish_function_path
#
# SYNOPSIS
# _prepend_tree [-p --preview] <path> [<glob>..]
# _prepend_tree [-v --verbose] <path> [<glob>..]
#
# DESCRIPTION
# Search a path tree and prepend directories with fish files
# printing any matches by default. Use a glob list to include
# or exclude other file extensions. Use -p --preview to just
# print matches withouth modifying the path.
# Search a path tree and prepend directories with fish files. Use a glob
# list to include or exclude other file extensions. Use -v --verbose to
# output directories to be added to the path.
#
# OPTIONS
# [-p --preview]
# Do not modify the path. Print directories that match the glob.
# [-v --verbose]
# Optional. Print directories that match the glob. Must be the
# first argument if used.
#
# <path>
# Required. Specify the path to search for glob patterns.
@ -46,15 +46,21 @@
# SEE ALSO
# .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."
# Match directories with .fish files always.
set -l glob -name \*.fish
set -l verbose ""
# Retrieve first argument, either the path or the -v option.
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]
end
# Parse glob options to create the main glob pattern.
if [ (count $argv) -gt 2 ]
set -l operator -o
@ -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
# which is safe to use in the loop.
set -l subs $path/**/
# Traverse $path and $subs prepending only directories with matches.
for dir in $path $subs
# Use head to retrieve at least the first match.
if [ -z (find $dir $glob -maxdepth 1 | head -1) ]
# Use head to retrieve at least one match. Ignore errors for non
# existing directories
if [ -z (find "$dir" $glob -maxdepth 1 ^/dev/null | head -1) ]
continue
end
printf "%s" $dir
if not contains -- $argv[1] -p --preview
_prepend_path $dir -d fish_function_path
# Print matched directories if the -v option is set.
if not [ -z $verbose ]
printf "%s\n" $dir
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

@ -25,19 +25,23 @@
# functions/_prepend_path.fish
# functions/_prepend_tree.fish
#
# v.0.2.1
# v.0.1.0
#/
function import -d "Load libraries, plugins, themes, etc."
for library in $argv
# Prepend plugins, themes and completions, traversing library
# 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
# Set path to load files.
set -l path $library/(basename $library).load
# Source each plugin, theme, etc., configuration load file.
for path in $fish_path/$library/(basename $library).load
if [ -e $path ]
. $path
for load in $fish_path/$path $fish_custom/$path
if [ -e $load ]
. $load
end
end
end

@ -10,24 +10,21 @@ end
set user_function_path $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
set fish_function_path $fish_path/functions/ $fish_function_path
end
# Add required plugins, completions and themes. Imported commands can be
# customized via the $fish_path/custom directory. To customize a theme,
# create a directory under $fish_path/custom/themes with the same name
# as the theme. Use the same approach for plugins, etc.
import plugins/$fish_plugins themes/$fish_theme
# Add imported plugins, completions and themes. Customize imported
# commands via the $fish_path/custom directory, for example create
# a directory under $fish_path/custom/themes with the same name as
# the theme and override any functions/variables there. Rinse and
# repeat for plugins.
import $fish_plugins themes/$fish_theme
# Prepend all user custom paths to the fish path and source load files.
for custom_file in $fish_custom/**
_prepend_path $custom_file -d fish_function_path
switch $custom_file
case \*.load
. $custom_file
end
# Source all files inside custom directory.
for load in $fish_custom/*.load
. $load
end
# Prepend extracted user functions so they have the highest priority.

Loading…
Cancel
Save