/vicious/widgets/fs_all.lua

https://github.com/starenka/awesomerc · Lua · 55 lines · 22 code · 6 blank · 27 comment · 4 complexity · 50655a884b5364ed487ccffb99ecd4b1 MD5 · raw file

  1. -- filesystem widget type
  2. -- Copyright (C) 2009 Lucas de Vries <lucas@glacicle.com>
  3. -- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
  4. -- Copyright (C) 2017 Joerg Thalheim <joerg@thalheim.io>
  5. -- Copyright (C) 2017 mutlusun <mutlusun@github.com>
  6. -- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
  7. --
  8. -- This file is part of Vicious.
  9. --
  10. -- Vicious is free software: you can redistribute it and/or modify
  11. -- it under the terms of the GNU General Public License as
  12. -- published by the Free Software Foundation, either version 2 of the
  13. -- License, or (at your option) any later version.
  14. --
  15. -- Vicious is distributed in the hope that it will be useful,
  16. -- but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. -- GNU General Public License for more details.
  19. --
  20. -- You should have received a copy of the GNU General Public License
  21. -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
  22. -- {{{ Grab environment
  23. local tonumber = tonumber
  24. local helpers = require"vicious.helpers"
  25. local spawn = require"vicious.spawn"
  26. -- }}}
  27. -- Mebibyte and gibibyte respectively, because backward compatibility
  28. local UNIT = { mb = 1024, gb = 1024^2 }
  29. -- FS: provides file system disk space usage
  30. -- vicious.widgets.fs
  31. return helpers.setasyncall{
  32. async = function(format, warg, callback)
  33. local fs_info = {} -- Get data from df
  34. spawn.with_line_callback_with_shell(
  35. warg and "LC_ALL=C df -kP" or "LC_ALL=C df -klP",
  36. { stdout = function (line)
  37. -- (1024-blocks) (Used) (Available) (Capacity)% (Mounted on)
  38. local s, u, a, p, m = line:match(
  39. "^.-%s+(%d+)%s+(%d+)%s+(%d+)%s+(%d+)%%%s+([%p%w]+)")
  40. if u and m then -- Handle 1st line and broken regexp
  41. helpers.uformat(fs_info, m .. " size", s, UNIT)
  42. helpers.uformat(fs_info, m .. " used", u, UNIT)
  43. helpers.uformat(fs_info, m .. " avail", a, UNIT)
  44. fs_info["{" .. m .. " used_p}"] = tonumber(p)
  45. fs_info["{" .. m .. " avail_p}"] = 100 - tonumber(p)
  46. end
  47. end,
  48. output_done = function () callback(fs_info) end })
  49. end }