Merge pull request #99 from derekstavis/remove-from-autoload
Implement `autoload -e` option to remove from autoload pathspull/105/head
commit
beca6512e1
@ -1,28 +1,64 @@
|
|||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
# autoload <path>...
|
# autoload <path>...
|
||||||
|
# autoload -e <path>...
|
||||||
#
|
#
|
||||||
# OVERVIEW
|
# OVERVIEW
|
||||||
# Autoload a function or completion path. Add the specified list of
|
# Manipulate autoloading path components.
|
||||||
# directories to $fish_function_path. Any `completions` directories
|
|
||||||
# are correctly added to the $fish_complete_path.
|
|
||||||
#
|
#
|
||||||
# Returns 0 if one of the paths exist.
|
# If called without options, the paths passed as arguments are added to
|
||||||
# Returns != 0 if all paths are missing.
|
# $fish_function_path. All paths ending with `completions` are correctly
|
||||||
|
# added to $fish_complete_path. Returns 0 if one or more paths exist. If all
|
||||||
|
# paths are missing, returns != 0.
|
||||||
|
#
|
||||||
|
# When called with -e, the paths passed as arguments are removed from
|
||||||
|
# $fish_function_path. All arguments ending with `completions` are correctly
|
||||||
|
# removed from $fish_complete_path. Returns 0 if one or more paths erased. If
|
||||||
|
# no paths were erased, returns != 0.
|
||||||
|
|
||||||
|
function autoload -d "Manipulate autoloading path components"
|
||||||
|
set -l paths $argv
|
||||||
|
|
||||||
|
switch "$argv[1]"
|
||||||
|
case '-e' '--erase'
|
||||||
|
set erase
|
||||||
|
|
||||||
|
if test (count $argv) -ge 2
|
||||||
|
set paths $argv[2..-1]
|
||||||
|
else
|
||||||
|
echo "usage: autoload $argv[1] <path>..." 1>&2
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
case "-*" "--*"
|
||||||
|
echo "autoload: invalid option $argv[1]"
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for path in $paths
|
||||||
|
not test -d "$path"; and continue
|
||||||
|
|
||||||
function autoload -d "autoload a function or completion path"
|
|
||||||
for path in $argv
|
|
||||||
set -l dest fish_function_path
|
set -l dest fish_function_path
|
||||||
|
|
||||||
if test -d "$path"
|
if test (basename "$path") = completions
|
||||||
set path_exist
|
set dest fish_complete_path
|
||||||
|
end
|
||||||
|
|
||||||
|
if set -q erase
|
||||||
|
not contains -- "$path" $$dest; and continue
|
||||||
|
# Make a copy of function path selected above
|
||||||
|
set -l function_path $$dest
|
||||||
|
|
||||||
if test (basename "$path") = completions
|
set -l index (contains -i -- $path $function_path)
|
||||||
set dest fish_complete_path
|
set -e function_path[$index]
|
||||||
end
|
|
||||||
|
|
||||||
contains "$path" $$dest; or set $dest "$path" $$dest
|
# Set function path to modified copy
|
||||||
|
set $dest $function_path
|
||||||
|
set return_success
|
||||||
|
else
|
||||||
|
set return_success
|
||||||
|
contains -- "$path" $$dest; and continue
|
||||||
|
set $dest "$path" $$dest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
set -q path_exist
|
set -q return_success
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue