From 29d117e7ce5a36f350d8f3e41c3843c74801c690 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Sun, 11 Jan 2015 01:20:25 +0900 Subject: [PATCH] + Rename `array.delete` to `list.erase` to better suit Fish terminology. + Extend to support any number of items and/or lists. + Add --from option. --- plugins/fish-spec/array.delete.fish | 39 ++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/plugins/fish-spec/array.delete.fish b/plugins/fish-spec/array.delete.fish index ae8610d..d574151 100644 --- a/plugins/fish-spec/array.delete.fish +++ b/plugins/fish-spec/array.delete.fish @@ -1,8 +1,35 @@ -# Remove item from list. List must be the name of a global variable. -# @params -function array.delete - set -l item $argv[1] - if set -l index (contains -i -- $item $$argv[2]) - set -e $argv[2][$index] +# NAME +# list.erase - erase items from lists +# +# SYNOPSIS +# [...] [--from] +# [...] --from [...] +# +# 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. +# +#/ +function -S list.erase + # List to erase from is last item by default. + set -l items $argv[1..-2] + set -l lists $argv[-1] + if set -l index (contains -i -- --from $argv) + # Everything before --from are items to erase and everything + # after, lists to erase any found items from. + 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] + end + end end end