2015-01-11 00:20:25 +08:00
|
|
|
# NAME
|
2015-01-13 19:30:24 +08:00
|
|
|
# list.erase - erase any items from one or more lists
|
2015-01-11 00:20:25 +08:00
|
|
|
#
|
|
|
|
# SYNOPSIS
|
|
|
|
# <item> [<item>...] [--from] <list>
|
|
|
|
# <item> [<item>...] --from <list1> [<list2>...]
|
|
|
|
#
|
|
|
|
# DESCRIPTION
|
|
|
|
# Erase any number of items from any number of lists. If more than one
|
|
|
|
# list is specified it must be separated from the items with --from.
|
|
|
|
#
|
|
|
|
# NOTES
|
|
|
|
# While items are basically any valid sequence of symbols, lists refer
|
|
|
|
# to any global variable or local variable in the scope of the calling
|
|
|
|
# function by name.
|
2015-01-17 12:46:44 +08:00
|
|
|
#
|
|
|
|
# AUTHORS
|
|
|
|
# Jorge Bucaran <@bucaran>
|
2015-01-11 00:20:25 +08:00
|
|
|
#/
|
|
|
|
function -S list.erase
|
2015-01-17 12:46:44 +08:00
|
|
|
# Assume no items were erased.
|
|
|
|
set -l result 1
|
|
|
|
# At least one list should be at the last index.
|
2015-01-11 00:20:25 +08:00
|
|
|
set -l items $argv[1..-2]
|
|
|
|
set -l lists $argv[-1]
|
|
|
|
if set -l index (contains -i -- --from $argv)
|
2015-01-17 12:46:44 +08:00
|
|
|
# <items to erase> --from <lists>
|
2015-01-11 00:20:25 +08:00
|
|
|
set items $argv[1..(math $index-1)]
|
|
|
|
set lists $argv[(math $index+1)..-1]
|
|
|
|
end
|
|
|
|
for item in $items
|
|
|
|
for list in $lists
|
|
|
|
if set -l index (contains -i -- $item $$list)
|
|
|
|
set -e $list[1][$index]
|
2015-01-17 12:46:44 +08:00
|
|
|
# Function succeeds if at least an item is erased.
|
|
|
|
set result 0
|
2015-01-11 00:20:25 +08:00
|
|
|
end
|
|
|
|
end
|
2015-01-10 22:18:04 +08:00
|
|
|
end
|
2015-01-17 12:46:44 +08:00
|
|
|
return $result
|
2015-01-10 22:18:04 +08:00
|
|
|
end
|