about summary refs log tree commit diff
path: root/fnl/nvrc/ui/modules/misc.fnl
blob: 24d84f9570f2190e7b347d90a138f6e30d02df97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
(fn file-size []
  "feline.nvim's file size calculation module."
  (let [suffix [:b :k :M :G :T :P :E]]
    (var index 1)
    (var fsize (vim.fn.getfsize (vim.api.nvim_buf_get_name 0)))
    (when (< fsize 0)
      (set fsize 0))
    (while (and (> fsize 1024) (< index 7))
      (set fsize (/ fsize 1024))
      (set index (+ index 1)))
    (string.format (or (and (= index 1) "%g%s | ") "%.2f%s | ") fsize
                   (. suffix index))))

{: file-size}