Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: flag for 1-indexing #23

Closed
AndydeCleyre opened this issue Jun 14, 2020 · 2 comments
Closed

Request: flag for 1-indexing #23

AndydeCleyre opened this issue Jun 14, 2020 · 2 comments

Comments

@AndydeCleyre
Copy link

AndydeCleyre commented Jun 14, 2020

choose helpfully offers compatibility with Python's style of 0-indexing, inclusive start, and exclusive end, with -x (which the docs make sound like it uses an exclusive range, while it uses an inclusive start):

$ s=(1 2 3 4 5 6)
$ print $s | choose 2:4
3 4 5
$ print $s | choose -x 2:4
3 4

But when I'm in a shell, using ZSH tools, cut, etc., I expect 1-indexing, inclusive start, inclusive end:

$ s=(1 2 3 4 5 6)
$ print $s[2,4]
2 3 4
$ print $s | cut -d' ' -f2-4
2 3 4

Since the context I'd use choose in is the same I'd use ZSH and cut in, it would lessen the mental load and chance of user error if I could get it to match the indexing and slicing of ZSH (default config) and cut.

Here's the same data as a table, where s is an array of the numbers 1 through 6:

Context Command Result Index Start End
python s[2:4] (3, 4) 0 Inclusive Exclusive
zsh print $s[2,4] 2 3 4 1 Inclusive Inclusive
cut print $s | cut -d' ' -f2-4 2 3 4 1 Inclusive Inclusive
choose print $s | choose 2:4 3 4 5 0 Inclusive Inclusive
choose print $s | choose -x 2:4 3 4 0 Inclusive Exclusive
@theryangeary
Copy link
Owner

This is reasonable. I will add it.

theryangeary added a commit that referenced this issue Jun 16, 2020
theryangeary added a commit that referenced this issue Jun 16, 2020
@theryangeary
Copy link
Owner

Added in develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants