3

I am often inspecting heterogeneous code bases, and would like to, at a quick glance, know the percentage of files per language, just like Github shows for a repository:

Github's code distribution per programming language

However, in Github's case, once we enter a subdirectory of the repository, this data is no longer available.

I'd like to have the same, but for a local directory, either graphically or via the command-line, ideally Linux-compatible.

Related tools

cloc shows a numerical table, but it does not group by subdirectory, so if I want to get more details, I have to:

  • run cloc . for the main directory;
  • find out where are the files (which subdirectories, if any);
  • enter each subdirectory and re-run cloc . to get the values for that directory.

The absence of bars, colors, etc, makes it very hard to quickly evaluate where are most of the files for a given language.


WinDirStat does offer graphical facilities for navigating and grouping directories and, I believe, is able to colorize files by extension. But the Linux equivalent, k4dirstat, does not offer this colorization (its colors are only related to the depth of the elements).

Other similar tools, such as Baobab, seem not to offer grouping-per-file-type capabilities.


Is there a Linux-compatible tool that fits my usage scenario?

2
  • Can't think of a graphical tool, but mlocate combined with some quick shell scripts can probably do the extension based analysis quickly
    – Lockszmith
    Commented Dec 3, 2021 at 21:25
  • Sounds like a fun open source project for you to code and share :-)
    – Mawg
    Commented Dec 4, 2021 at 10:27

2 Answers 2

1

It's not ideal, but I found out that QDirStat works closely to what I want: like WinDirStat, it allows coloring per file type, and it displays a tree view so that larger directories take more place, and makes it easier to find out where is the bulk of the files for a given programming language.

However, it does not allow filtering files, only directories. So while it is possible to exclude directories such as .git, it is not possible to exclude specific files from a directory, for instance to filter out .jpg files lying in a directory containing sources. In some cases, most of the space is taken by those files, and the best you can do is let them remain black and white, so you can visually ignore them more easily.

0
cloc --vcs=git --by-file --csv | tail -n +5 | head -n -1 | awk -F , '{printf("%s,",$1); system("dirname " $2 " | tr -d \\\\n"); printf(",%s,%s,%s\n",$3,$4,$5)}' | q -H -c 5 -d , 'select ".", sum(code) from - group by "."'

Should be a good start

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.