How to fix inconsistent line endings for whole VS solution?

后端 未结 4 1752
天涯浪人
天涯浪人 2021-01-31 14:45

Visual Studio will detect inconsistent line endings when opening a file and there is an option to fix it for that specific file. However, if I want to fix line endings for all f

4条回答
  •  醉话见心
    2021-01-31 15:18

    If you have Cygwin with the cygutils package installed, you can use this chain of commands from the Cygwin shell:

    unix2dos -idu *.cpp | sed -e 's/ 0 [1-9][0-9]//' -e 's/ [1-9][0-9]* 0 //' | sed '/ [1-9][0-9] / !d' | sed -e 's/ [1-9][0-9 ] //' | xargs unix2dos

    (Replace the *.cpp with whatever wildcard you need)

    To understand how this works, the unix2dos command is used to convert the files, but only files that have inconsistent line endings (i.e., a mixture of UNIX and DOS) need to be converted. The -idu option displays the number of dos and unix line endings in the file. For example:

       0     491  Acad2S5kDim.cpp
     689       0  Acad2S5kPolyline.cpp
       0     120  Acad2S5kRaster.cpp
     433      12  Acad2S5kXhat.cpp
       0     115  AppAuditInfo.cpp
    

    Here, only the Acad2S5kXhat.cpp file needs to be converted. The sed commands filter the output to produce a list of just the files that need to be converted, and these are then processed via xargs.

提交回复
热议问题