Jump to content

[11066] make whitespace history


Recommended Posts

Posted

about your script:

- why declare TYPE and then not use it?

- afaik bash is fine with for i in *.$TYPE, no need to ls directly

additional ideas:

- add a -r switch for recursive

- perhaps define a few default types that are cleaned (.cpp .h .txt)

- why not add an additional substitution to sed to move all tabs to 4 blanks?

Posted

Also, GNU sed can process in place (with optional backup), no need to move around files ;)

But for some reason, trailing white spaces keep coming back anyway, i start to believe that getting rid of them is a futile untertaking xD

Posted

@Schmoozerd: I was using it in console with "./cleanIT h" or "./cleanIT cpp" this way only cpp or header files are used ofc default types are an improvement. ls isn't needed :-) Didn't thought about tabs to 4 blanks.

@Lynx3d: don't know that much about sed. I tried using the same file name and it didn't work, that's why I used it my way.

I'll see if I can improve it a bit.

Regards

Skirnir

[EDIT]

I came up with this one:

#!/bin/bash

cd mangos
for i in `find $PWD -name "*.h" -or -name "*.cpp" | grep -Ev 'dep/'`
do
sed -i 's/\\t/    /g;s/[ \\t]*$//' $i
cd ..
done

patch is here: [1] but hmm before applying someone has to manually recheck and clean many lines (or someone finds a clean way to do it via awk for instance), thus comments positioned with tabs are moving and afterwards it might look terrible.

[1] http://paste2.org/p/1200977

Posted

Another thanks to Schmoozerd, the tabs to spaces will be nice for my script as well

currently I use

find . \\( -name "*.c" -o -name "*.cpp*" -o -name "*.h" \\) -exec sed -i '' 's/[[:space:]]\\{1,\\}$//' {} \\;

in an auto updater script i wrote

my find/sed code catches more trailing white spaces with every commit so i've just never bothered to post patches, but thought i would throw my code out there if anyone wanted to mess with it

Note: I used csh, but it should still work with bash

Edit: Might not be obvious, but that code is meant to be executed from within your mangos working directory

Posted

for i in `ls *.$1`
do
cat ${i} | sed 's/[ \\t]*$//' > $i-clean
mv $i-clean $i
done

-->

for i in *.$1; do
sed -i 's/[ \\t]*$//' $i
done

slightly faster

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use