Last active
December 9, 2016 19:10
-
-
Save colstrom/2cbacb9d7c1a4927457bfc03668ac2f3 to your computer and use it in GitHub Desktop.
without-trailing.fish: removes a pattern from the end of strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = without-trailing | |
| author = Chris Olstrom | |
| license = MIT | |
| provides = fish/functions/without-trailing | |
| requires | |
| command/sed | |
| fish/builtin/end | |
| fish/builtin/function | |
| fish/builtin/if | |
| fish/builtin/return | |
| fish/builtin/string | |
| fish/functions/empty | |
| fish/functions/errno | |
| fish/functions/usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function without-trailing --argument string | |
| if empty "$string" | |
| usage without-trailing '<string>' | |
| return (errno EINVAL) | |
| end | |
| sed -E "s/$string\$//" | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In
fish >= 2.3.0this can be done withstring trim --right --chars "$string"orstring replace --regex "$string\$" ''