1. Choice
EditorConfig — is my choice.
2. Relevance
This answer is relevant for March 2018. In the future, the data from this answer may be obsolete.
Author of this answer personally used EditorConfig at March 2018.
3. Limitations
You need to use one of supported IDE/editors.
4. Argumentation
- Simply usage. I need set my
.editorconfig
file 1 time, where I create my project, → I can forget some platform-, style- and IDE-specific problems.
- Cross-platform, cross-languages, cross-IDE, cross-editors.
5. Example
5.1. Simple
I install EditorConfig plugin for Sublime Text → my text editor. I edit files in Sublime Text.
For example, I have sashacrlf.sh
file:
echo "Sasha" &
echo "Goddess!" &
I run this file in Cygwin:
$ bash sashacrlf.sh
Sasha
sashacrlf.sh: line 1: $'\r': command not found
Goddess!
I create a file .editorconfig
in same project as sashacrlf.sh
.
[*.sh]
end_of_line = lf
It means, that if you save any file with .sh
extension in your project in your editor, EditorConfig set UNIX line endings for this file.
I save sashacrlf.sh
in my text editor again. I run sashacrlf.sh
again:
$ bash sashacrlf.sh
Sasha
Goddess!
I can't get unexpected output in console.
5.2. Multiple file extensions
For example, I want to have UNIX line endings in all files with extensions .sh
, .bashrc
and .bash_profile
.
I add these lines to my .editorconfig
file:
[*.{sh,bashrc,bash_profile}]
end_of_line = lf
Now, if I save any file with .sh
, .bashrc
or .bash_profile
extension, EditorConfig automatically set UNIX line ending for this file.
6. Additional links
- EditorConfig official site.