2014-12-16 22:12:17 +00:00
|
|
|
# NAME
|
2015-01-07 05:00:00 +00:00
|
|
|
# _prepend_tree - add a dependency tree to fish_function_path
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
|
|
|
# SYNOPSIS
|
2015-01-07 17:21:51 +00:00
|
|
|
# _prepend_tree [-v --verbose] <path> [<glob>..]
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
|
|
|
# DESCRIPTION
|
2015-01-07 17:21:51 +00:00
|
|
|
# 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.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
|
|
|
# OPTIONS
|
2015-01-07 17:21:51 +00:00
|
|
|
# [-v --verbose]
|
|
|
|
# Optional. Print directories that match the glob. Must be the
|
|
|
|
# first argument if used.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# <path>
|
|
|
|
# Required. Specify the path to search for glob patterns.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# [<glob> [<operator> <glob>..]]
|
|
|
|
# Glob pattern to match when traversing the path path.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# OPERATORS
|
|
|
|
# [! -not glob]
|
|
|
|
# Negates the following glob.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# [<glob> -o -or <glob>..]
|
|
|
|
# Default. Must meet at least one listed criteria.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# [<glob> [-a -and <glob>..]]
|
|
|
|
# Must meet *all* listed criteria.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
|
|
|
# EXAMPLES
|
2015-01-07 05:00:00 +00:00
|
|
|
# _prepend_tree $path
|
|
|
|
# Match directories in $path containing `.fish` files.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# _prepend_tree $path \*.fish \*.sh
|
|
|
|
# Match directories in $path with either `.fish` OR `.sh` files.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
2015-01-07 05:00:00 +00:00
|
|
|
# _prepend_tree $path \*.fish -a ! _\*.\*
|
|
|
|
# Match directories with `.fish` files that do not start with `_`.
|
2014-12-16 22:12:17 +00:00
|
|
|
#
|
|
|
|
# AUTHORS
|
|
|
|
# Jorge Bucaran <jbucaran@me.com>
|
|
|
|
#
|
|
|
|
# SEE ALSO
|
|
|
|
# .oh-my-fish/functions/_prepend_path.fish
|
|
|
|
#
|
2015-01-07 17:21:51 +00:00
|
|
|
# v.0.2.0
|
2014-12-16 22:12:17 +00:00
|
|
|
#/
|
2015-01-07 05:00:00 +00:00
|
|
|
function _prepend_tree -d "Add a dependency tree to the Fish path."
|
|
|
|
# Match directories with .fish files always.
|
|
|
|
set -l glob -name \*.fish
|
2015-01-07 17:21:51 +00:00
|
|
|
set -l verbose ""
|
|
|
|
|
|
|
|
# Retrieve first argument, either the path or the -v option.
|
2015-01-07 05:00:00 +00:00
|
|
|
set -l path $argv[1]
|
2015-01-07 17:21:51 +00:00
|
|
|
if contains -- $path -v --verbose
|
|
|
|
set verbose -v
|
|
|
|
# Option first, path should be next.
|
2015-01-07 05:00:00 +00:00
|
|
|
set path $argv[2]
|
2014-12-16 22:12:17 +00:00
|
|
|
end
|
2015-01-07 17:21:51 +00:00
|
|
|
|
2015-01-07 05:00:00 +00:00
|
|
|
# Parse glob options to create the main glob pattern.
|
|
|
|
if [ (count $argv) -gt 2 ]
|
|
|
|
set -l operator -o
|
|
|
|
for option in $argv[3..-1]
|
|
|
|
switch $option
|
2014-12-16 22:12:17 +00:00
|
|
|
case ! -not
|
|
|
|
set operator $operator !
|
|
|
|
case -o -or
|
|
|
|
set operator -o
|
|
|
|
case -a -and
|
|
|
|
set operator -a
|
|
|
|
case "*"
|
2015-01-07 05:00:00 +00:00
|
|
|
if [ operator = ! ]
|
|
|
|
set glob $operator $glob
|
|
|
|
else
|
|
|
|
set glob $glob $operator
|
|
|
|
end
|
|
|
|
set glob $glob -name $option
|
|
|
|
set operator -o # Default
|
2014-12-16 22:12:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-19 04:22:57 +00:00
|
|
|
# Traverse $path prepending only directories with matches. Excludes completions folder.
|
|
|
|
test -d $path
|
|
|
|
and for dir in (find $path \! -name "completions" -type d)
|
2015-01-07 18:04:54 +00:00
|
|
|
# Use head to retrieve at least one match. Skip not found errors
|
|
|
|
# for directories that do not exist.
|
2015-01-07 17:21:51 +00:00
|
|
|
if [ -z (find "$dir" $glob -maxdepth 1 ^/dev/null | head -1) ]
|
2015-01-07 05:00:00 +00:00
|
|
|
continue
|
|
|
|
end
|
2015-01-07 17:21:51 +00:00
|
|
|
|
|
|
|
# Print matched directories if the -v option is set.
|
|
|
|
if not [ -z $verbose ]
|
|
|
|
printf "%s\n" $dir
|
2014-12-16 23:21:13 +00:00
|
|
|
end
|
2015-01-07 17:21:51 +00:00
|
|
|
|
|
|
|
# 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
|
2014-12-16 22:12:17 +00:00
|
|
|
end
|
|
|
|
end
|