1

How can I make magit display the file sizes (at least of the unstaged files) in the status buffer? This would help me in avoiding to add large files directly to git.

Here is an example of what the status buffer might look like right now:

 Local:    master ~/some/repo/
 Remote:   master @ server (git@server.com:path/to/repo.git)
 Head:     ea55b10 last commit message

 Untracked files:
    new_file_1.ext
    new_file_2.ext

 Unstaged changes:
    Modified   old_file_1.ext
    Modified   old_file_2.ext

 Unpushed commits:
 ea55b10 last commit message

And here is what I'd like to see:

 Local:    master ~/some/repo/
 Remote:   master @ server (git@server.com:path/to/repo.git)
 Head:     ea55b10 last commit message

 Untracked files:
    new_file_1.ext                                  10K
    new_file_2.ext                                   5M

 Unstaged changes:
    Modified   old_file_1.ext                      100K
    Modified   old_file_2.ext                       530

 Unpushed commits:
 ea55b10 last commit message
Andreas
  • 1,106
  • 9
  • 26

1 Answers1

2

There's no easy way to configure this; you'll have to patch magit.

I started by looking for the definition of the magit-status function. C-h f magit-status RET got me the help for it, including a handy link to the source code. This function calls magit-status-internal, which opens a buffer and calls magit-status-refresh-buffer to show the status information. magit-status-refresh-buffer calls all of the hook functions in the variable magit-status-sections-hook; one of these functions is called magit-insert-untracked-files; this looks promising. I haven't read all of the supporting code (such as magit-insert-section), but this appears to call magit-insert-un/tracked-files-1 on each file in the list. That function actually does insert things into the buffer:

(insert (propertize file 'face 'magit-filename) ?\n)

It's just inserting the filename (with a custom face) followed by a newline; it's here that you would have to look up the file size and insert it as well.

You can use the elisp function file-attributes to get information about the file, including the file size.

If you do this, then I suggest submitting the change back to magit as a pull request.

You might also think about changing the code to adopt a pattern which will be familiar to most emacs users, which is to create a customizable variable which holds a format directive into which you can substitute the available values. Users can then edit this string to customize how the files are displayed, without having to edit the source code as you are doing. Of course, that's a rather larger change than to add just one thing. For inspiration you might look at gnus-summary-line-format (docs); it's got a very comprehensive set of information you might wish to show for each email in a folder, and the code that uses it is bound to be instructive.

db48x
  • 3,108
  • 24
  • 16