Monday

Nautilus script line count in Ubuntu Gibbon 7.10

[Story]
I was in an interview two weeks ago and the interviewer popped up an unexpected question.
Interviewer- How many code lines does your Master Thesis Project have?.
Ray-"To be honest I have NO IDEA". (My NoC Simulator is a modular system with around 125 source files)
Interviewer-But can you give me an approximation?
Ray-"I have not a clue" [(You should view his face). I tried to solve the situation by giving him the CD with the project, but he didn't take it so I guess I lost one job opportunity.(The interesting thing is that I believe this department needs me more than I need them. There are not many engineers with the background, passion and enthusiasm this research topic needs, and I have all of them ;-). Life is just like that, my experience tells me that some times when you follow a different path that the one you were planning the result is much better than the initial plan.)]

[Problem]
What do we do to count the number of code lines along many files and folders?.
[Solution]
A Nautilus script.
I searched internet and I found an script package from "Nicolas Cuntz (ni_ka_ro), 16.4.2005" with a line count script implemented, but since it is an old implementation it does not work with the last version of nautilus and bash(or at least it does not work for me).

I have updated some lines to solve the main problems, and right now I have a working solution. It is important to point out that there is an error in the execution, but does not affect the counting. In the future I will solve it and I will make a clean script but in the mean time you can download this functional version here.

-How to install&use it
Extract it and move the files to the folder /home/user/.gnome2/nautilus-scripts/
Don't forget to move the hidden folder '.scripts' to the same destination.
Give execution permission to all the files inside .scripts an also to 'line_count' script in /home/user/.gnome2/nautilus-scripts/
That's all. Select the folder with the project. Right click->Scripts->line_count.

Yes I know, the recursion along folders is just great.
I hope you find it useful and don't forget to reply me if you have a better solution.

1 comment:

Anonymous said...

Most linux distros have the program 'wc' which can count words, lines and bytes.

It doesn't recurse by default, but using regexps with a 'for' with this program does the job pretty well.