a command-line script and Python module for working with text file end-of-line (EOL) characters
Project description
`eol` is both a command-line script `eol` and a Python module `eol` for working
with end-of-line chars in text files.
This project lives here: <http://github.com/trentm/eol>
## Command-line examples
**List the EOL-style** of given paths:
eol -r ~/src/redis
/Users/trentm/src/redis/.gitignore: Unix (LF)
/Users/trentm/src/redis/BETATESTING.txt: Unix (LF)
/Users/trentm/src/redis/BUGS: Unix (LF)
/Users/trentm/src/redis/COPYING: Unix (LF)
...
/Users/trentm/src/redis/zmalloc.h: Unix (LF)
/Users/trentm/src/redis/.git/HEAD: Unix (LF)
/Users/trentm/src/redis/.git/config: Unix (LF)
...
/Users/trentm/src/redis/client-libraries/README: Unix (LF)
/Users/trentm/src/redis/design-documents/REDIS-CLUSTER: Unix (LF)
/Users/trentm/src/redis/doc/AppendOnlyFileHowto.html: Unix (LF)
/Users/trentm/src/redis/doc/AuthCommand.html: Unix (LF)
...
**Find files** with the given EOL-style:
eol ~/src/python/Tools/msi/merge.py
/Users/trentm/src/python/Tools/msi/merge.py: Windows (CRLF)
eol -c native ~/src/python/Tools/msi/merge.py
converted `/Users/trentm/src/python/Tools/msi/merge.py' to LF EOLs
$ eol ~/src/python/Tools/msi/merge.py
/Users/trentm/src/python/Tools/msi/merge.py: Unix (LF)
## Module examples
**List the EOL-style** of given paths:
>>> import eol, glob
>>> for path in glob.glob("*.txt")
>>> for path in glob.glob("*.txt"):
... print path, eol.eol_info_from_path(path)
...
foo_cr.txt ('\r', '\r') # (<detected-eols>, <suggested-eols>)
foo_crlf.txt ('\r\n', '\r\n')
foo_empty.txt (None, '\n') # suggests the native EOL for empty content
foo_lf.txt ('\n', '\n')
foo_mixed.txt (<class 'eol.MIXED'>, '\n')
Recursively:
>>> for i in eol.eol_info_from_path_patterns(["/Users/trentm/src/redis"], recursive=True): print i
...
('/Users/trentm/src/redis/.gitignore', '\n', '\n')
('/Users/trentm/src/redis/BETATESTING.txt', '\n', '\n')
('/Users/trentm/src/redis/BUGS', '\n', '\n')
('/Users/trentm/src/redis/COPYING', '\n', '\n')
...
**Convert files** to a given EOL-style:
>>> path = "/Users/trentm/src/python/Tools/msi/merge.py"
>>> eol.eol_info_from_path(path)
('\r\n', '\r\n')
>>> eol.convert_path_eol(path, "\n")
>>> eol.eol_info_from_path(path)
('\n', '\n')
with end-of-line chars in text files.
This project lives here: <http://github.com/trentm/eol>
## Command-line examples
**List the EOL-style** of given paths:
/Users/trentm/src/redis/.gitignore: Unix (LF)
/Users/trentm/src/redis/BETATESTING.txt: Unix (LF)
/Users/trentm/src/redis/BUGS: Unix (LF)
/Users/trentm/src/redis/COPYING: Unix (LF)
...
/Users/trentm/src/redis/zmalloc.h: Unix (LF)
/Users/trentm/src/redis/.git/HEAD: Unix (LF)
/Users/trentm/src/redis/.git/config: Unix (LF)
...
/Users/trentm/src/redis/client-libraries/README: Unix (LF)
/Users/trentm/src/redis/design-documents/REDIS-CLUSTER: Unix (LF)
/Users/trentm/src/redis/doc/AppendOnlyFileHowto.html: Unix (LF)
/Users/trentm/src/redis/doc/AuthCommand.html: Unix (LF)
...
**Find files** with the given EOL-style:
/Users/trentm/src/python/Tools/msi/merge.py: Windows (CRLF)
converted `/Users/trentm/src/python/Tools/msi/merge.py' to LF EOLs
$ eol ~/src/python/Tools/msi/merge.py
/Users/trentm/src/python/Tools/msi/merge.py: Unix (LF)
## Module examples
**List the EOL-style** of given paths:
>>> import eol, glob
>>> for path in glob.glob("*.txt")
>>> for path in glob.glob("*.txt"):
... print path, eol.eol_info_from_path(path)
...
foo_cr.txt ('\r', '\r') # (<detected-eols>, <suggested-eols>)
foo_crlf.txt ('\r\n', '\r\n')
foo_empty.txt (None, '\n') # suggests the native EOL for empty content
foo_lf.txt ('\n', '\n')
foo_mixed.txt (<class 'eol.MIXED'>, '\n')
Recursively:
>>> for i in eol.eol_info_from_path_patterns(["/Users/trentm/src/redis"], recursive=True): print i
...
('/Users/trentm/src/redis/.gitignore', '\n', '\n')
('/Users/trentm/src/redis/BETATESTING.txt', '\n', '\n')
('/Users/trentm/src/redis/BUGS', '\n', '\n')
('/Users/trentm/src/redis/COPYING', '\n', '\n')
...
**Convert files** to a given EOL-style:
>>> path = "/Users/trentm/src/python/Tools/msi/merge.py"
>>> eol.eol_info_from_path(path)
('\r\n', '\r\n')
>>> eol.convert_path_eol(path, "\n")
>>> eol.eol_info_from_path(path)
('\n', '\n')