Unix is so Rad!

After running SwiftFormat on a directory, SwiftFormat told me that it had formatted 279 out of 280 files. “What was that one file?”, I asked. So Nathan and I figured out how to do this using Unix commands.

We used find . -name "*.swift" > ~/Desktop/all.txt to find all swift files in current directory and output those lines to a file.

We then used git status | grep -E 'swift$' > ~/Desktop/gst.txt to output the result of git status to a file. Running git status after running swift format . shows all swift files changed.

We then used the TextEdit GUI to remove the ./ from the find output and modified: from the git status output.

We then used sort all.txt > allsorted.txt and sort gst.txt > gstsorted.txt to sort the files in alphabetical order.

Finally, we used diff -y allsorted.txt gstsorted.txt to give us a side by side comparison of the two files.

The result? We figured out exactly which file was not changed by SwiftFormat. After touching the file, we were able to format it by running swiftformat [file name].

Unix is so cool!

UPDATE: Cristian gave us a head start on how to do it with one line and Nathan figured it out:

diff <(find iFarmers -name “*.swift” | sort) <(git status -s | tr -d \” | cut -c 4- | sort)