Skip to content

Instantly share code, notes, and snippets.

@colstrom
Last active December 9, 2016 19:10
Show Gist options
  • Select an option

  • Save colstrom/2cbacb9d7c1a4927457bfc03668ac2f3 to your computer and use it in GitHub Desktop.

Select an option

Save colstrom/2cbacb9d7c1a4927457bfc03668ac2f3 to your computer and use it in GitHub Desktop.
without-trailing.fish: removes a pattern from the end of strings
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
function without-trailing --argument string
if empty "$string"
usage without-trailing '<string>'
return (errno EINVAL)
end
sed -E "s/$string\$//"
end
@colstrom
Copy link
Author

colstrom commented May 4, 2016

In fish >= 2.3.0 this can be done with string trim --right --chars "$string" or string replace --regex "$string\$" ''

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment