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

Add string sub --end #5974

Closed
zx8 opened this issue Jul 3, 2019 · 3 comments · Fixed by #6765
Closed

Add string sub --end #5974

zx8 opened this issue Jul 3, 2019 · 3 comments · Fixed by #6765

Comments

@zx8
Copy link

zx8 commented Jul 3, 2019

Would be neat if string sub --length accepted negatives indexes, just like string sub --start, e.g.

$ string sub --length -2 -- foobar
foob

AFAIK, the only way to achieve this at the moment is:

$ set s foobar
$ string sub --length (math (string length -- $s) - 2) -- $s
foob

(Also, feel like this option should be (re?)named --end to match --start)

@faho
Copy link
Member

faho commented Jul 3, 2019

That's an entirely different thing?

Like... with a length of 3, you'd go from a start of e.g. 2 to an end of 5.

Which is an okay thing to add, I just don't see why we should remove --length for it.

@faho faho changed the title Accept negative indexes for string sub --length Add string sub --end Jul 3, 2019
@faho
Copy link
Member

faho commented Jul 3, 2019

E.g. string sub --start 2 --length 3 foobar prints "oob" (a 3-long string starting with the second character).

string sub --start 2 --end 3 foobar should print either oo or just o. (Arguably it'd be better to include the end, like we include the start, so oo)

@zx8
Copy link
Author

zx8 commented Jul 3, 2019

Aha, misunderstood --length, got it!

@zanchey zanchey added this to the fish-future milestone Jul 25, 2019
@zanchey zanchey modified the milestones: fish-future, fish 3.2.0 Mar 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants