From 521b7bb7da849b8c780d2c24e2965c15f7984843 Mon Sep 17 00:00:00 2001 From: Bruno Pinto Date: Tue, 6 Jan 2015 17:48:14 -0200 Subject: [PATCH] prepend_path allowing multiple paths to be specified at once --- functions/_prepend_path.fish | 54 ++++++++++++++++++++++++++++++------ oh-my-fish.fish | 12 ++++---- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/functions/_prepend_path.fish b/functions/_prepend_path.fish index 4797108..dded431 100644 --- a/functions/_prepend_path.fish +++ b/functions/_prepend_path.fish @@ -1,14 +1,52 @@ -# Prepends the path to the specified path list. If no list specified, defaults to $PATH -function _prepend_path - set -l path PATH +# NAME +# _prepend_path - adds a path to a list +# +# SYNOPSIS +# _prepend_path [-d --destination ] +# +# DESCRIPTION +# Adds a path to a list. +# If no list specified, defaults to $PATH +# +# OPTIONS +# +# Required. Specify the path to add to the list. +# +# [ [ ..]] +# Glob pattern to match when traversing the path path. +# +# OPERATORS +# -d +# Should appear at the end if used. Specifies the name of the +# list to prepend the paths to. +# If not used, $PATH is assumed by default. +# +# EXAMPLES +# _prepend_path $path +# Add $path to $PATH +# +# _prepend_path $path -d $fish_function_path +# Add $path to $fish_function_path +#/ - if test (echo $argv | wc -w) -eq 2 - set path $argv[2] +function _prepend_path + set -l destination_path PATH #$PATH is the default destination path + set -l len (count $argv) + set -l path $argv + + if test $len -gt 2 + switch $argv[-2] + case -d --destination + set destination_path $argv[-1] + set path $argv[1..-3] + end end - if test -d $argv[1] - if not contains $argv[1] $$path - set $path $argv[1] $$path + for path in $path + if test -d $path + if not contains $path $$destination_path + set $destination_path $path $$destination_path + end end end end diff --git a/oh-my-fish.fish b/oh-my-fish.fish index a15912e..d7b8060 100644 --- a/oh-my-fish.fish +++ b/oh-my-fish.fish @@ -6,16 +6,16 @@ function _fish_add_plugin set -l plugin $argv[1] set -l plugin_path "plugins/$plugin" - _prepend_path $fish_path/$plugin_path fish_function_path - _prepend_path $fish_custom/$plugin_path fish_function_path + _prepend_path $fish_path/$plugin_path -d fish_function_path + _prepend_path $fish_custom/$plugin_path -d fish_function_path end function _fish_add_completion set -l plugin $argv[1] set -l completion_path "plugins/$plugin/completions" - _prepend_path $fish_path/$completion_path fish_complete_path - _prepend_path $fish_custom/$completion_path fish_complete_path + _prepend_path $fish_path/$completion_path -d fish_complete_path + _prepend_path $fish_custom/$completion_path -d fish_complete_path end function _fish_source_plugin_load_file @@ -32,8 +32,8 @@ function _fish_source_plugin_load_file end function _fish_load_theme - _prepend_path $fish_path/themes/$fish_theme fish_function_path - _prepend_path $fish_custom/themes/$fish_theme fish_function_path + _prepend_path $fish_path/themes/$fish_theme -d fish_function_path + _prepend_path $fish_custom/themes/$fish_theme -d fish_function_path end ###