diff options
Diffstat (limited to '.bash_utils/text.sh')
-rw-r--r-- | .bash_utils/text.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/.bash_utils/text.sh b/.bash_utils/text.sh new file mode 100644 index 0000000..5a678ee --- /dev/null +++ b/.bash_utils/text.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com> +# This file is part of the "Cygwin configuration files" project. +# For details, see https://github.com/egor-tensin/cygwin-home. +# Distributed under the MIT License. + +alias dos2eol='sed --binary --in-place '"'"'s/\(\r\?\)$//'"'" +alias eol2dos='sed --binary --in-place '"'"'s/\r\?$/\r/'"'" + +alias trim='sed --binary --in-place '"'"'s/[[:blank:]]*\(\r\?\)$/\1/'"'" + +alias trimeol='sed --binary --in-place -e :a -e '"'"'/^\n*$/{$d;N;ba}'"'" +alias trimdoseol='sed --binary --in-place -e :a -e '"'"'/^\(\r\n\)*\r$/{$d;N;ba}'"'" + +alias eol='sed --binary --in-place '"'"'$a\'"'" +alias doseol='sed --binary --in-place '"'"'$s/\r\?$/\r/;a\'"'" + +alias trimbom='sed --binary --in-place '"'"'1 s/^\xef\xbb\xbf//'"'" + +lint() { + trim "$@" && trimeol "$@" && eol "$@" +} + +doslint() { + trim "$@" && trimdoseol "$@" && doseol "$@" +} |