prepend_path allowing multiple paths to be specified at once
parent
25dbd9ad48
commit
521b7bb7da
@ -1,14 +1,52 @@
|
||||
# Prepends the path to the specified path list. If no list specified, defaults to $PATH
|
||||
# NAME
|
||||
# _prepend_path - adds a path to a list
|
||||
#
|
||||
# SYNOPSIS
|
||||
# _prepend_path [-d --destination <destination path>] <path>
|
||||
#
|
||||
# DESCRIPTION
|
||||
# Adds a path to a list.
|
||||
# If no list specified, defaults to $PATH
|
||||
#
|
||||
# OPTIONS
|
||||
# <path>
|
||||
# Required. Specify the path to add to the list.
|
||||
#
|
||||
# [<glob> [<operator> <glob>..]]
|
||||
# Glob pattern to match when traversing the path path.
|
||||
#
|
||||
# OPERATORS
|
||||
# -d <DESTINATION PATH>
|
||||
# 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
|
||||
#/
|
||||
|
||||
function _prepend_path
|
||||
set -l path PATH
|
||||
set -l destination_path PATH #$PATH is the default destination path
|
||||
set -l len (count $argv)
|
||||
set -l path $argv
|
||||
|
||||
if test (echo $argv | wc -w) -eq 2
|
||||
set path $argv[2]
|
||||
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
|
||||
|
Loading…
Reference in New Issue