fish-shell/fish-shell — pull request #212 by maxfl (2012-07-08 03:24:56+00:00)
Title: Index range expansion

I've added possibility to expand index ranges for variable expansion, command substitution, and set builtin.
This pull request is not intended to be merged in a short term (at least until I update the documentation).
I just want to show it and to get some feedback.

Here is what works (see tests/test8.in for examples):
Range is defined as following: i1..i2, where i1, and i2 are two non-zero integers. They may be negative.
This functruction is expanded to the sequence of integers between i1 and i2. It respects the direction:
1..5 -> 1 2 3 4 5
5..1 -> 5 4 3 2 1
It knows about the array/output size and respects negative numbers. Consider the variable with 5 elements:
3..-1 -> 3 4 5
-1..-3 -> 5 4 3
-1..1 -> 5 4 3 2 1 # this is useful for inverting variables and output.

Of course this can be used only in [] brackets. Several ranges can be specified:
echo $PATH[1..2 3..-1]

Overlapping ranges can be specified:
echo (seq 10)[1..5 1..10]

Set command also respects ranges:
set var[6..10] (seq 5)

Limits can be variables or command substitution:
echo $PATH[1..(seq 3)]
set -n 3
echo $PATH[1..$3]

Any feedback is appreciated.
I had also idea of making possible to apply indexes to the process substitution, so I can write:
kill %gvim[-1]
But I'm not sure if it worth doing for now. Any thoughts on this?