2016-06-01 12:14:30 +08:00
|
|
|
function autoload
|
2015-10-04 22:50:40 +08:00
|
|
|
switch "$argv[1]"
|
|
|
|
case '-e' '--erase'
|
2016-06-01 12:14:30 +08:00
|
|
|
test (count $argv) -ge 2
|
|
|
|
and __autoload_erase $argv[2..-1]
|
|
|
|
or echo "usage: autoload $argv[1] <path>..." 1>&2
|
2015-10-04 22:50:40 +08:00
|
|
|
case "-*" "--*"
|
|
|
|
echo "autoload: invalid option $argv[1]"
|
|
|
|
return 1
|
2016-06-01 12:14:30 +08:00
|
|
|
case '*'
|
|
|
|
test (count $argv) -ge 1
|
|
|
|
and __autoload_insert $argv
|
|
|
|
or echo "usage: autoload <path>..." 1>&2
|
2015-10-04 22:50:40 +08:00
|
|
|
end
|
2016-06-01 12:14:30 +08:00
|
|
|
end
|
|
|
|
function __autoload_insert
|
|
|
|
set -l function_path
|
|
|
|
set -l complete_path
|
|
|
|
for path in $argv
|
2015-10-04 22:50:40 +08:00
|
|
|
not test -d "$path"; and continue
|
2016-06-01 12:14:30 +08:00
|
|
|
set -l IFS '/'
|
|
|
|
echo $path | read -la components
|
|
|
|
if test "x$components[-1]" = xcompletions
|
|
|
|
contains -- $path $fish_complete_path
|
|
|
|
or set complete_path $complete_path $path
|
2015-10-04 22:50:40 +08:00
|
|
|
else
|
2016-06-01 12:14:30 +08:00
|
|
|
contains -- $path $fish_function_path
|
|
|
|
or set function_path $function_path $path
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
test -n "$function_path"
|
|
|
|
and set fish_function_path $fish_function_path[1] $function_path $fish_function_path[2..-1]
|
|
|
|
test -n "$complete_path"
|
|
|
|
and set fish_complete_path $fish_complete_path[1] $complete_path $fish_complete_path[2..-1]
|
|
|
|
return 0
|
|
|
|
end;
|
|
|
|
function __autoload_erase
|
|
|
|
set -l function_indexes
|
|
|
|
set -l complete_indexes
|
|
|
|
for path in $argv
|
|
|
|
set -l IFS '/'
|
|
|
|
echo $path | read -la components
|
|
|
|
test "x$components[-1]" = xcompletions
|
|
|
|
and set complete_indexes $complete_indexes (contains -i $path $fish_complete_path)
|
|
|
|
or set function_indexes $function_indexes (contains -i $path $fish_function_path)
|
|
|
|
end;
|
|
|
|
test -n "$function_indexes"
|
|
|
|
and set -e fish_function_path[$function_indexes]
|
|
|
|
test -n "$complete_indexes"
|
|
|
|
and set -e fish_complete_path[$complete_indexes]
|
|
|
|
return 0
|
|
|
|
end;
|